Reputation: 1947
Let's consider data:
import pandas as pd
x_train = pd.DataFrame([[1, 2, 3], [2, 3, 4], [5, 6, 2]])
y_train = pd.DataFrame([1, 0, 1])
I want to check which variables are important in this primitive example when using neural network. So if we do:
from sklearn.neural_network import MLPClassifier
from sklearn.feature_selection import RFE
# Define neural network classifier
clf = MLPClassifier(max_iter = 1000,
activation = 'logistic',
random_state = 1)
# Select two most important variables
selector = RFE(clf, n_features_to_select=2, step=1).fit(x_train, y_train)
# Extract names of the most important variables
print(selector.get_feature_names_out())
However, I get the error:
ValueError: when importance_getter=='auto', the underlying estimator MLPClassifier should
have coef_ or feature_importances_ attribute. Either pass a fitted estimator to feature
selector or call fit before calling transform.
Could you please help me solving it?
Upvotes: 0
Views: 38