0

Trying to plot the training and testing sets vs loss to come up with a plot similar to the one attached (epoch vs. loss). How can I do this using mlxtend (https://rasbt.github.io/mlxtend/user_guide/plotting/plot_learning_curves/)?

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X_normalized, y_for_normalized, test_size=0.20,random_state=0)
from sklearn.linear_model import LinearRegression

lin_regressor = LinearRegression()

# pass the order of your polynomial here  
poly = PolynomialFeatures(1)

# convert to be used further to linear regression
X_transform = poly.fit_transform(x_train)

# fit this to Linear Regressor
linear_regg=lin_regressor.fit(X_transform,y_train) 


from mlxtend.plotting import plot_learning_curves

plot_learning_curves(x_train, y_train, x_test, y_test, lin_regressor, scoring=mean_squared_error)

plt.show()

#Error

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

enter image description here

Z47
  • 67
  • 6
  • 1) `lin_regressor = LinearRegression()` What library does this come from? Can you include any required imports in the question? 2) How did you define your loss function? – Nick ODell May 26 '23 at 00:08
  • 1
    They're using sklearn in order to pre-process the data, but they're not using it for a linear regression. They're using keras for that. I don't think sklearn creates this history. – Nick ODell May 26 '23 at 00:26
  • Thx! If you have any suggestion on how to do the plot for my code, please share it so everyone can benefit from your experience. Cheers! – Z47 May 26 '23 at 01:34
  • I feel like I'd just be copy/pasting code from the tutorial you linked. Have you tried the code in the section "Mean Squared Error Loss?" – Nick ODell May 26 '23 at 02:02

0 Answers0