我试图将Yellowbrick学习曲线的x值从样本数更改为样本的规范化数(%)。我搜索了很多,但找不到路。
发布于 2022-09-24 21:28:12
您需要更改xticks,以便将它们标准化为训练实例的数量,因此您需要在我的示例中的百分比格式化程序中指定训练实例的数量(55000)。我提供了前后的图像。
from yellowbrick.model_selection import LearningCurve
from sklearn.naive_bayes import MultinomialNB
import numpy as np
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
from yellowbrick.datasets import load_game
import matplotlib.pyplot as plt
# Create subplot
fig,ax = plt.subplots()
# Create the learning curve visualizer
sizes = np.linspace(0.3, 1.0, 10)
# Load a classification dataset
X, y = load_game()
# Encode the categorical data
X = OneHotEncoder().fit_transform(X)
y = LabelEncoder().fit_transform(y)
# Instantiate the classification model and visualizer
model = MultinomialNB()
visualizer = LearningCurve(
model, scoring='f1_weighted', ax=ax, train_sizes=sizes)
xticks = mtick.PercentFormatter(55000)
ax.xaxis.set_major_formatter(xticks)
visualizer.fit(X, y) # Fit the data to the visualizer
visualizer.show()


https://stackoverflow.com/questions/73715983
复制相似问题