91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

Scikit-learn中怎么繪制學習曲線

小億
89
2024-05-10 17:22:56
欄目: 編程語言

要繪制學習曲線,可以使用learning_curve函數來實現。下面是一個示例代碼:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import learning_curve
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression

# 加載數據集
iris = load_iris()
X, y = iris.data, iris.target

# 初始化Logistic回歸模型
model = LogisticRegression()

# 繪制學習曲線
train_sizes, train_scores, test_scores = learning_curve(model, X, y, train_sizes=np.linspace(0.1, 1.0, 10), cv=5)

train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)

plt.figure()
plt.title("Learning Curve")
plt.xlabel("Training examples")
plt.ylabel("Score")
plt.grid()

plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                 train_scores_mean + train_scores_std, alpha=0.1,
                 color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                 test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, 'o-', color="r", label="Training score")
plt.plot(train_sizes, test_scores_mean, 'o-', color="g", label="Cross-validation score")

plt.legend(loc="best")
plt.show()

這段代碼將繪制Logistic回歸模型在不同訓練數據量下的學習曲線,可以直觀地觀察模型的訓練和驗證表現。

0
磴口县| 泽普县| 响水县| 广灵县| 梁山县| 长兴县| 宁乡县| 颍上县| 昂仁县| 巴塘县| 六安市| 壶关县| 宜川县| 龙江县| 金塔县| 汉阴县| 拜城县| 卫辉市| 县级市| 河北省| 手游| 蒙城县| 绥芬河市| 法库县| 安宁市| 聂荣县| 六盘水市| 郑州市| 浦城县| 天水市| 崇文区| 綦江县| 炎陵县| 台安县| 名山县| 江达县| 仪陇县| 深州市| 灵璧县| 怀化市| 手游|