ML之xgboost:利用xgboost算法(自带特征重要性可视化+且作为阈值训练模型)训练mushroom蘑菇数据集(22+1,6513+1611)来预测蘑菇是否毒性(二分类预测)


小海豚俊秀
小海豚俊秀 2022-09-19 14:42:00 49725
分类专栏: 资讯

ML之xgboost:利用xgboost算法(自带特征重要性可视化+且作为阈值训练模型)训练mushroom蘑菇数据集(22+1,6513+1611)来预测蘑菇是否毒性(二分类预测)

目录

输出结果

设计思路

核心代码


输出结果

可知,8个或者5个特征就足够好了 ,odor、spore-print-color、population、gill-spacing、gill-size 

设计思路

后期更新……

核心代码

后期更新……

  1. print('XGB_model.feature_importances_:','\n', XGB_model.feature_importances_)
  2. from matplotlib import pyplot
  3. pyplot.bar(range(len(XGB_model.feature_importances_)), XGB_model.feature_importances_)
  4. from xgboost import plot_importance
  5. plot_importance(XGB_model)
  6. thresholds = sort(XGB_model.feature_importances_)
  7. for thresh in thresholds:
  8. selection = SelectFromModel(XGB_model, threshold=thresh, prefit=True)
  9. select_X_train = selection.transform(X_train)
  10. selection_model = XGBClassifier()
  11. selection_model.fit(select_X_train, y_train)
  12. select_X_test = selection.transform(X_test)
  13. y_pred = selection_model.predict(select_X_test)
  14. predictions = [round(value) for value in y_pred]
  15. accuracy = accuracy_score(y_test, predictions)
  16. print("Thresh=%.3f, n=%d, Accuracy: %.2f%%" % (thresh, select_X_train.shape[1], accuracy*100.0))

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=3053
赞同 0
评论 0 条

加入交流群

请使用微信扫一扫!