【发布时间】:2019-12-12 21:09:41
【问题描述】:
我正在尝试以下代码用于随机森林分类器。即使我已经定义但得到 NameError。 请帮忙
def RFC_model(randomState, X_train, X_test, y_train, y_test):
rand_forest = RandomForestClassifier()
rand_forest.fit(X_train, y_train)
forest_test_predictions = rand_forest.predict(X_test)
print(accuracy_score(y_test, forest_test_predictions))
X_train, X_test, y_train, y_test = train_test_split(df_encoded.drop(['success'],axis='columns').values,
df_encoded.success,
test_size=0.2)
RFC_model(42, X_train, X_test, y_train, y_test)
0.994045375744328
rand_forest.feature_importances_.round(3)
NameError Traceback (most recent call last)
<ipython-input-40-974786899b7f> in <module>
1 #importance of features rounded to nearest 3 decimals
----> 2 rand_forest.feature_importances_.round(3)
NameError: name 'rand_forest' is not defined
【问题讨论】:
标签: python random-forest nameerror