亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
交城县| 罗定市| 亚东县| 伊金霍洛旗| 砚山县| 塔河县| 塔城市| 江山市| 尼木县| 新余市| 晴隆县| 饶阳县| 商河县| 大方县| 泸西县| 澎湖县| 武邑县| 金山区| 沧州市| 蓬莱市| 宁武县| 马公市| 聂拉木县| 曲靖市| 都匀市| 盐亭县| 中江县| 新邵县| 泰顺县| 安西县| 团风县| 道真| 东兴市| 望奎县| 三亚市| 丹棱县| 呼伦贝尔市| 册亨县| 瑞安市| 会理县| 图木舒克市|