Das Objekt "Numpy.ndarray" hat kein Attribut "GroupBy"Python

Python-Programme
Anonymous
 Das Objekt "Numpy.ndarray" hat kein Attribut "GroupBy"

Post by Anonymous »

Ich versuche, Zielcodierung auf kategorische Merkmale mit den category_encoders.targetEnCoder in Python anzuwenden. Ich erhalte jedoch immer wieder den folgenden Fehler: < /p>

Code: Select all

AttributeError: 'numpy.ndarray' object has no attribute 'groupby'
< /code>
from category_encoders import TargetEncoder
from sklearn.model_selection import train_test_split

# Features for target encoding
encoding_cols = ['grade', 'sub_grade', 'home_ownership', 'verification_status',
'purpose', 'application_type', 'zipcode']

# Train-Test Split
X_train_cv, X_test, y_train_cv, y_test = train_test_split(x, y, test_size=0.25, random_state=1)
X_train, X_test_cv, y_train, y_test_cv = train_test_split(X_train_cv, y_train_cv, test_size=0.25, random_state=1)

# Initialize the Target Encoder
encoder = TargetEncoder()

# Apply Target Encoding
for i in encoding_cols:
X_train[i] = encoder.fit_transform(X_train[i], y_train)  # **Error occurs here**
X_test_cv[i] = encoder.transform(X_test_cv[i])
X_test[i] = encoder.transform(X_test[i])
< /code>
want to [b]successfully apply target encoding[/b] to the categorical columns without encountering the 'numpy.ndarray' object has no attribute 'groupby'
Fehler.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post