sklearn Logistic Regression的准确性太低,即使我尝试用训练数据进行预测 &



我目前正在尝试在一些向量上使用逻辑回归,我使用sklearn库。

这是我的代码。首先是包含数据的文件,然后将值赋给数组。
# load files
xvectors_train = kaldiio.load_scp('train/xvector.scp')
# create empty arrays where to store the data
x_train = np.empty(shape=(len(xvectors_train.keys()), len(xvectors_train[list(xvectors_train.keys())[0]])))
y_train = np.empty(len(xvectors_train.keys()), dtype=object)
# assign values to the empty arrays
for file_id in xvectors_train:
x_train[i] = xvectors_train[file_id]
label = file_id.split('_')
y_train[i] = label[0]
i+=1
# create a model and train it
model = LogisticRegression( max_iter = 200, solver = 'liblinear')
model.fit(x_train, y_train) 
# predict 
model.predict(x_train)
#score
score = model.score(x_train, y_train)

由于某些原因,即使我使用x_train数据进行预测,得分也大约是0.32。它不应该是1.0吗,因为模型已经知道这些问题的答案了?如果我使用我的测试数据,分数仍然是0.32。

有谁知道是什么问题吗?

没有任何明显的问题,结果看起来很正常:您的测试分数与您的训练分数非常相似。

大多数模型试图学习泛化到新数据的规则/参数,但不记住你现有的训练数据,这意味着"它不应该是1.0吗,因为模型已经知道这些的答案了?"是不正确的…

如果你真的看到你的测试集分数明显低于你的训练分数(例如,0.32 vs 1.0),那么这意味着你的模型严重过拟合,需要修复。

最新更新