官术网_书友最值得收藏!

Random forest accuracy evaluation

Loss on training data:

In []: 
rf_model.score(X_train, y_train) 
Out[]: 
0.98999999999999999 

Loss on test data:

In []: 
rf_model.score(X_test, y_test) 
Out[]: 
0.90333333333333332 

Cross-validation:

In []:
scores = cross_val_score(rf_model, features, df.label, cv=10) np.mean(scores) Out[]: 0.89700000000000002 In []: print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2)) Accuracy: 0.90 (+/- 0.06)

Precision and recall:

In []: 
predictions = rf_model.predict(X_test) 
predictions = np.array(map(lambda x: x == 'rabbosaurus', predictions), dtype='int') 
true_labels = np.array(map(lambda x: x == 'rabbosaurus', y_test), dtype='int') 
precision_score(true_labels, predictions) 
Out[]: 
0.9072847682119205 
In []: 
recall_score(true_labels, predictions) 
Out[]: 
0.90131578947368418 

F1-score:

In []: 
f1_score(true_labels, predictions) 
Out[]: 
0.90429042904290435 

Confusion matrix:

In []: 
confusion_matrix(y_test, rf_model.predict(X_test)) 
Out[]: 
array([[134,  14], 
       [ 15, 137]]) 

You export a random forest for the iOS in the same way you do for a decision tree.

主站蜘蛛池模板: 磐安县| 林州市| 汶上县| 桂东县| 承德县| 泰和县| 庆云县| 河源市| 鲁山县| 襄城县| 松阳县| 修文县| 铁岭市| 阳曲县| 岳池县| 马山县| 西乌珠穆沁旗| 资中县| 灌阳县| 斗六市| 祁阳县| 饶阳县| 色达县| 文水县| 伊宁市| 吉木萨尔县| 小金县| 绍兴县| 汉沽区| 江永县| 华坪县| 南川市| 任丘市| 怀安县| 桑植县| 原平市| 清水县| 宜昌市| 中西区| 丰镇市| 任丘市|