我正在做一個簡單的機器學習專案。在最初的模型中,我的模型過度擬合,正如我通過谷歌搜索了解什么是過度擬合以及如何檢測它所了解的那樣。然后我使用 SMOTE 來減少過擬合,并試圖找出它是否仍然過擬合。我得到一個我無法解釋的圖表,并嘗試了幾個鏈接來了解正在發生的事情但失敗了。誰能告訴我這張圖是好的還是其中有問題?(圖片和代碼如下)

def EF_final(x_train, y_train, x_test, y_test):
train_scores, test_scores = [], []
values = [i for i in range(1, 21)]
# evaluate a decision tree for each depth
for i in values:
# configure the model
model_ef = ExtraTreesClassifier(n_estimators = 80, random_state=42, min_samples_split = 2, min_samples_leaf= 1, max_features = 'sqrt', max_depth= 24, bootstrap=False)
# fit model on the training dataset
model_ef.fit(x_train, y_train)
# evaluate on the train dataset
train_yhat = model_ef.predict(x_train)
train_acc = accuracy_score(y_train, train_yhat)
train_scores.append(train_acc)
# evaluate on the test dataset
test_yhat = model_ef.predict(x_test)
test_acc = accuracy_score(y_test, test_yhat)
test_scores.append(test_acc)
# summarize progress
print('>%d, train: %.3f, test: %.3f' % (i, train_acc, test_acc))
# plot of train and test scores vs tree depth
plt.plot(values, train_scores, '-o', label='Train')
plt.plot(values, test_scores, '-o', label='Test')
plt.legend()
plt.show()
uj5u.com熱心網友回復:
不能在不查看資料的情況下評論模型預測的結果,但要回答您的標題問題。
您似乎在每個回圈中配置和創建相同的模型,而不使用變數i來更改模型 depth 。即使模型的 random_state 是恒定的,因此您可以期待相同的結果。考慮將模型配置行切換到
model_ef = ExtraTreesClassifier(n_estimators = 80,min_samples_split = 2, min_samples_leaf= 1, max_features = 'sqrt', max_depth = i, bootstrap=False)
這將改變圖表結果以幫助您選擇更好的模型,但是在不知道傳遞什么樣的資料的情況下無法評論準確性。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/481171.html
