LoginSignup
5
5

More than 3 years have passed since last update.

"STOP: TOTAL NO. of ITERATIONS REACHED LIMIT."の解決法

Posted at

はじめに

Pythonでロジスティック回帰(LogisticRegression)を用いた時,一応実行はできるが以下のような警告文が発生することがあった.

Python
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=0)
logreg = LogisticRegression()
logreg.fit(X_train,y_train)
print("Test score: {:.2f}".format(logreg.score(X_test,y_test)))

警告内容

STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.

解決法

原因は,LogisticRegressionの最大反復回数に達しなかったことにあるようです.つまり,途中で処理が打ち切られているという事です.この最大反復回数はmax_iterで設定できます.この値を設定しない場合は,デフォルト値である1000が適用されるようです.そのため,max_iterの値を1000より大きくすることで,警告文が消えると考えられます.

max_iter適用例

Python
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=0)
logreg = LogisticRegression(max_iter=1500)
logreg.fit(X_train,y_train)
print("Test score: {:.2f}".format(logreg.score(X_test,y_test)))

今回の場合,最大反復回数を1500に設定したところ,警告文が消えましたが,処理内容によってこの値が異なると考えられます.

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5