-2

Logistic Regressionを使用してモデルを訓練し、名前フィールドと説明フィールドが男性、女性、またはブランドのプロファイルに属するかどうかを予測しました。私の列車精度は約99%であり、試験精度は約83%です。私はCパラメータをチューニングして正規化を実装しようとしましたが、改良はほとんど気づかれませんでした。トレーニングセットには約5,000の例があります。これは、私がSci-Kitでもっと多くのデータを必要としているか、それとも他に何かできるのか、私のテストの精度を上げることを学ぶのですか?Sci-Kitを使用したロジスティック回帰のオーバーフィットを回避するLearn

+0

がはるかに正確な(電車/テスト分割することが何を得る参照; C-チューニングが行わ; *かろうじて注目* ?;;;;;;;;;;;;;;;;;;;;;前処理、オプト・アルゴリズム、正則化の種類、マルチ・クラス戦略)、いくつかの書式を追加することができます。それでも、それはまだ非常に広い質問であるようです。 – sascha

答えて

1

オーバーフィットは多面的な問題です。それはあなたの列車/テスト/検証スプリット(50/40/10から90/9/1のものは何かを変えるかもしれません)かもしれません。入力をシャッフルする必要があるかもしれません。アンサンブル方式を試してみるか、機能の数を減らしてください。あなたは外れ値を持っている可能性があります。

これらのどれも、またはこれらのすべて、またはこれらの組み合わせであってもかまいません。

初心者のための

、テストの分割サイズの関数としてのテストのスコアをプロットしてみて、あなたが

+0

ガイダンスをありがとう。私が使用している機能はTfidfVectorizerからのものなので、どのように機能の数を減らすか分かりません。自分のような初心者のためのアイデアはここにありますか?ありがとう! – user3647894

+0

ロット;プロットスコア対テストサイズ。あなたのデータがゼロ平均と単位標準にスケールされていることを確かめてみてください –

-1
#The 'C' value in Logistic Regresion works very similar as the Support 
#Vector Machine (SVM) algorithm, when I use SVM I like to use #Gridsearch 
#to find the best posible fit values for 'C' and 'gamma', 
#maybe this can give you some light: 

# For SVC You can remove the gamma and kernel keys 
# param_grid = {'C': [0.1,1, 10, 100, 1000], 
#    'gamma': [1,0.1,0.01,0.001,0.0001], 
#    'kernel': ['rbf']} 

param_grid = {'C': [0.1,1, 10, 100, 1000]} 

from sklearn.svm import SVC 
from sklearn.model_selection import train_test_split 
from sklearn.model_selection import GridSearchCV 
from sklearn.metrics import classification_report,confusion_matrix 

# Train and fit your model to see initial values 
X_train, X_test, y_train, y_test = train_test_split(df_feat, np.ravel(df_target), test_size=0.30, random_state=101) 
model = SVC() 
model.fit(X_train,y_train) 
predictions = model.predict(X_test) 
print(confusion_matrix(y_test,predictions)) 
print(classification_report(y_test,predictions)) 

# Find the best 'C' value 
grid = GridSearchCV(SVC(),param_grid,refit=True,verbose=3) 
grid.best_params_ 
c_val = grid.best_estimator_.C 

#Then you can re-run predictions on this grid object just like you would with a normal model. 
grid_predictions = grid.predict(X_test) 

# use the best 'C' value found by GridSearch and reload your LogisticRegression module 
logmodel = LogisticRegression(C=c_val) 
logmodel.fit(X_train,y_train) 

print(confusion_matrix(y_test,grid_predictions)) 
print(classification_report(y_test,grid_predictions)) 
+0

これはscikit learn tutorialのcopy + pasteです。 –

+1

コピー+ペーストなし私はこのSVMモジュールで数日前に働いていました。これはSVCのために最高のCとガンマを見つける方法でしたが、他の人には難しいかもしれないアルゴを学習するマシンですが、質問をしたユーザーがそれを取得します。 –

関連する問題