【发布时间】:2021-01-31 18:43:43
【问题描述】:
在功能选择(嵌入式方法)中,我得到了错误的功能。
特征选择代码:
# create the random forest model
model = RandomForestRegressor(n_estimators=120)
# fit the model to start training.
model.fit(X_train[_columns], X_train['delay_in_days'])
# get the importance of the resulting features.
importances = model.feature_importances_
# create a data frame for visualization.
final_df = pd.DataFrame({"Features": X_train[_columns].columns, "Importances":importances})
final_df.set_index('Importances')
# sort in descending order
final_df = final_df.sort_values('Importances',ascending=False)
#visualising feature importance
pd.Series(model.feature_importances_, index=X_train[_columns].columns).nlargest(10).plot(kind='barh')
_columns #my some selected features
这里是功能列表,您可以看到 total_open_amount 是非常重要的功能 但是当我在我的模型中加入前 3 个功能时,我得到了 -ve R2_Score。但如果我删除 total_open_amount 从我的模型中我得到了不错的 R2_Score。
我的问题是什么原因造成的?(所有数据训练、测试都是从 size=100000 的数据集中随机选择的)
clf = RandomForestRegressor()
clf.fit(x_train, y_train)
# Predicting the Test Set Results
predicted = clf.predict(x_test)
【问题讨论】:
标签: python machine-learning random-forest