如何在MLPClassifier中打印mse vs epoch



嗨,大家好,我有问题打印我的结果使用MLPClassifier sklearn,我想我的结果是图mse vs epoch训练vs测试,这是我的代码:

#Spliting data into Feature and
x=Dt[['new_tests','people_vaccinated','people_fully_vaccinated','total_boosters','new_vaccinations']]
y=Dt[['new_cases','new_deaths']]
#Import train_test_split function**
from sklearn.model_selection import train_test_split
#Split dataset into training set and test set to be 70% and 30%
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=42)

# Import MLPClassifer and mse
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import mean_squared_error
# Create model object
flc = MLPClassifier(hidden_layer_sizes=(15,10),
random_state=5,
verbose=True,
max_iter=50,
learning_rate_init=0.1)
mse = mean_squared_error(y_test, ypred, squared=False)
# Fit data onto the model
flc.fit(x_train, y_train)
# Make prediction on test dataset
ypred = flc.predict(x_test)
# Import accuracy score 
from sklearn.metrics import accuracy_score
# Calcuate accuracy
accuracy_score(y_test,ypred)

我期待图形显示mse vs epoch用于训练和测试请,有人能运行它吗?有什么想法或建议吗?是什么导致了这个问题?谢谢你。

均方误差是一个回归度量。为了可视化每次迭代的损失,您可以绘制clf.loss_curve_:

import matplotlib.pyplot as plt
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import make_classification
X, y = make_classification()
clf = MLPClassifier(max_iter=50).fit(X, y)
plt.plot(clf.loss_curve_)
plt.show()

如果你想绘制更复杂的东西(例如训练和测试的错误与epoch),你将编写这样的训练循环:

最新更新