绘制keras顺序模型的学习曲线

时间:2019-04-11 11:36:47

标签: python keras scikit-learn

我正在尝试绘制cnn keras顺序模型的学习曲线,但是它不起作用。我尝试了这段代码:

train_sizes=[1,50,80,100,116]

from sklearn.linear_model import LinearRegression

from sklearn.model_selection import learning_curve

train_sizes, train_scores, validation_scores = learning_curve(
                                 estimator = LinearRegression(),
                                      X = train_X,
     y = class_labels, train_sizes = train_sizes, cv = 5,
                scoring = 'neg_mean_squared_error')
print('Training scores:\n\n', train_scores)

print('\n', '-' * 70) # separator to make the output easy to read

print('\nValidation scores:\n\n', validation_scores)

train_scores_mean = -train_scores.mean(axis = 1)

validation_scores_mean = -validation_scores.mean(axis = 1 )

print('Mean training scores\n\n', pd.Series(train_scores_mean, index = train_sizes))

print('\n', '-' * 20) # separator

print('\nMean validation scores\n\n',pd.Series(validation_scores_mean, index = train_sizes))

import matplotlib.pyplot as plt


plt.style.use('seaborn')

plt.plot(train_sizes, train_scores_mean, label = 'Training error')

plt.plot(train_sizes, validation_scores_mean, label = 'Validation error')

plt.ylabel('MSE', fontsize = 14)

plt.xlabel('Training set size', fontsize = 14)

plt.title('Learning curves for a linear regression model', fontsize = 18, y = 1.03)

plt.legend()

plt.ylim(0,40)

出现以下错误:

  

ValueError:找到样本数量不一致的输入变量:[91,130]

任何想法如何绘制此曲线?

0 个答案:

没有答案