周志洋

个人站

持续学习 才能不被淘汰


Python机器学习-模型评估

交叉验证

from sklearn.model_selection import cross_val_score, StratifiedKFold

# K折交叉验证
cv_scores = cross_val_score(model, X, y, cv=5)
print(f"平均准确率: {cv_scores.mean():.3f}")

# 分层K折
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)

评估指标

from sklearn.metrics import classification_report, confusion_matrix

# 分类报告
print(classification_report(y_test, y_pred))

# 混淆矩阵
cm = confusion_matrix(y_test, y_pred)


转载请注明:周志洋的博客 » Python机器学习-模型评估

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦