I'm trying to plot the learning curve of a cnn keras sequential model but it is not working. I tried this code:

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)

It is giving the following error:

ValueError: Found input variables with inconsistent numbers of samples: [91, 130]

Any ideas how to plot this curve?

0 Answers