[英]sklearn Logistic Regression has too little accuracy even if I try to predict with the train data
我目前正在嘗試對某些向量使用邏輯回歸,並且使用 sklearn 庫。
這是我的代碼。 我首先是包含數據的文件並將值分配給 arrays。
# 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,因為 model 已經知道這些的答案了嗎? 如果我使用我的測試數據,分數仍然是 0.32。
有誰知道是什么問題?
沒有任何明顯的問題,結果看起來很正常:你的測試分數和你的訓練分數非常相似。
大多數模型試圖學習推廣到新數據的規則/參數,但不記住現有的訓練數據,這意味着“不應該是 1.0,因為 model 已經知道這些的答案了嗎?” 不是真的……
如果您實際上看到您的測試集分數明顯低於您的訓練分數(例如,0.32 與 1.0),那么這意味着您的 model 嚴重過度擬合,需要修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.