6.2 随机森林模型
- from sklearn.ensemble import RandomForestClassifier
- rfmodel=RandomForestClassifier()
- rfmodel.fit(x_train,y_train)
- #查看模型
- print('rfmodel')
- rfmodel
- rfmodel
- RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
- max_depth=None, max_features='auto', max_leaf_nodes=None,
- min_impurity_decrease=0.0, min_impurity_split=None,
- min_samples_leaf=1, min_samples_split=2,
- min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
- oob_score=False, random_state=None, verbose=0,
- warm_start=False)
- #查看混淆矩阵
- ypred_rf=rfmodel.predict(x_test)
- print('confusion_matrix')
- print(metrics.confusion_matrix(y_test,ypred_rf))
- confusion_matrix
- [[85291 4]
- [ 34 114]]
- #查看分类报告
- print('classification_report')
- print(metrics.classification_report(y_test,ypred_rf))
- classification_report
- precision recall f1-score support
- 0 1.00 1.00 1.00 85295
- 1 0.97 0.77 0.86 148
- avg / total 1.00 1.00 1.00 85443
- #查看预测精度与决策覆盖面
- print('Accuracy:%f'%(metrics.accuracy_score(y_test,ypred_rf)))
- print('Area under the curve:%f'%(metrics.roc_auc_score(y_test,ypred_rf)))
- Accuracy:0.999625
- Area under the curve:0.902009
(编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|