'numpy.ndarray' object has no attribute 'columns' how can ı solve it?

Viewed 1205
 rf_tuned = RandomForestClassifier(max_depth = 8, max_features = 8, min_samples_split = 10, n_estimators = 20)
rf_tuned.fit(X_train, y_train)

y_pred = rf_tuned.predict(X_test)
accuracy_score(y_test, y_pred)

importance = pd.DataFrame({'Importance': rf_tuned.feature_importances_*100},
                     index = X_train.columns)
Output >> AttributeError: 'numpy.ndarray' object has no attribute 'columns'

How can I solve this, Do I need to convert the dataframe to numpy ndarray?

1 Answers
X = dataTrain.drop('Risk_Flag', axis=1).values
y = dataTrain['Risk_Flag'].values
X = pd.DataFrame(X)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

I added this code X = pd.DataFrame(X) and then my problem is solved.Thanks for the ansvers guys.

Related