我有两个数据集(训练和测试),它们都具有完全相同的特征和标签列,只有不同的内部(数字和值)。这是我的代码:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
datatraining = pd.read_csv("datatrain.csv")
datatesting = pd.read_csv("datatest.csv")
columns = ["Full","Id","Id & PPDB","Id & Words Sequence","Id & Synonyms","Id & Hypernyms","Id & Hyponyms"]
labeltrain = datatraining["Gold Standard"].values
featurestrain = datatraining[list(columns)].values
labeltest = datatesting["Gold Standard"].values
featurestest = datatesting[list(columns)].values
X_train = featurestrain
y_train = labeltrain
X_test = featurestest
y_test = labeltest
mlp = MLPRegressor(solver='lbfgs', hidden_layer_sizes=50, max_iter=1000, learning_rate='constant')
mlp.fit(X_train, y_train)
print('Accuracy training : {:.3f}'.format(mlp.score(X_train, y_train)))
print
mlp.fit(X_test, y_test)
print('Accuracy testing : {:.3f}'.format(mlp.score(X_test, y_test)))
print
我仍然怀疑我的代码是否正确找到列车和测试分数,因为我认为没有差异化来确定哪一个正在训练哪个以及另一个正在测试。我看到两者都在训练,或两者都在测试。 任何人都可以解释如何确定它?或者我的代码是否正确?感谢
答案 0 :(得分:4)
一旦您的模型适合您的训练,您就不应该再次参加测试了。相反,您应该使用测试集评估模型的性能。因此,您需要删除行
mlp.fit(X_test, y_test)
来自您的代码。然后使用行
print('Accuracy testing : {:.3f}'.format(mlp.score(X_test, y_test)))
您将能够在看不见的数据上评估模型的性能。