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

K-fold cross-validation

This method was invented and gained popularity in those days when the big date was not yet a problem, everyone had little data, but still needed to build reliable models. First thing we do is shuffle our dataset well, and then divide it randomly into several equal parts, say 10 (this is the k in k-fold). We hold out the first part as a test set, and on the remaining nine parts we train the model. The trained model is then assessed on the test set that did not participate in the training as usual. Next, we hold out the second of 10 parts, and train the model on the remaining nine (including those previously served as a test set). We validate the new model again on the part that did not participate in the training. We continue this process until each of the 10 parts is in the role of the test set. The final quality metrics are determined by the averaging metrics from each of the 10 tests:

In []: 
from sklearn.model_selection import cross_val_score 
scores = cross_val_score(tree_model, features, df.label, cv=10) 
np.mean(scores) 
Out[]: 
0.88300000000000001 
In []: 
plot = plt.bar(range(1,11), scores) 
Out[]: 
Figure 2.10: Cross-validation results

From the preceding graph, you can see that the model's accuracy depends on how you split the data, but not much. By taking the average and variance of the cross-validation results, you can make a sense of how well your model can generalize on different data, and how stable it is.

主站蜘蛛池模板: 东辽县| 邹城市| 惠州市| 九寨沟县| 梅州市| 凤城市| 乌苏市| 东兴市| 民丰县| 白朗县| 密云县| 昌宁县| 牙克石市| 建德市| 华阴市| 盐池县| 三明市| 铜鼓县| 习水县| 子长县| 四川省| 青河县| 隆昌县| 三台县| 滕州市| 寻乌县| 女性| 南投市| 凤阳县| 东港市| 都安| 台北市| 日土县| 乐平市| 昔阳县| 静宁县| 宜章县| 朝阳市| 奉新县| 府谷县| 安达市|