【发布时间】:2020-11-04 00:44:50
【问题描述】:
我正在尝试检索 RandomForestClassifier 模型中特征的重要性,检索模型中每个特征的系数,
我在这里运行下面的代码,
random_forest = SelectFromModel(RandomForestClassifier(n_estimators = 200, random_state = 123))
random_forest.fit(X_train, y_train)
print(random_forest.estimator.feature_importances_)
但收到以下错误
NotFittedError: This RandomForestClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
我到底做错了什么?您可以看到我在确定特征的重要性之前就已经拟合了模型,但它似乎并没有发挥应有的作用,
同样,我有下面带有 LogisticRegression 模型的代码,它工作正常,
log_reg = SelectFromModel(LogisticRegression(class_weight = "balanced", random_state = 123))
log_reg.fit(X_train, y_train)
print(log_reg.estimator_.coef_)
【问题讨论】:
标签: python scikit-learn sklearn-pandas