李坦(IT)学习空间 Instructional Technology and Big Data

交叉验证的实现与热力图可视化实现

2020-07-08
GarrettLee


当通过小样本训练机器学习模型时,为了更加准确的评价机器学习模型,可以采用k折交叉验证方法

1.读取训练数据

mldata_x = data[['学科A','学科B','学科C','学科D']]
mldata_y = data[['学业成败']]

2.进入5折交叉验证方法

```python from sklearn.model_selection import cross_val_score nb=GaussianNB() score=cross_val_score(nb,mldata_x,mldata_y,cv=5,scoring=’accuracy’)#5折:交叉验证

print (‘平均准确率’,score.mean()) print (‘每则准确率’,score) ```

3.扫码获取更多学习资料

sklearn 实现机器学习的5折交叉验证


Similar Posts

Comments