使用逻辑回归 (python) 时,最大迭代次数必须为正 ERROR

Maximum number of iterations must be positive ERROR when using Logistic Regression (python)

    x_train, x_test, y_train, y_test = 
    sklearn.model_selection.train_test_split(X, y, test_size=0.2, 
    shuffle=False)
    return(x_train, x_test, y_train, y_test)

    logisticR = LogisticRegression(random_state=0, max_iter = '800', 
    solver='saga', multi_class='multinomial')
    logisticR.fit(x_train, encoded_ytrain)

    acc = logisticR.score(x_test, encoded_ytest)
    print(acc)

当运行时出现以下错误:ValueError: Maximum number of iteration must be positive;得到了 (max_iter='800')

由于max_iter默认为100,有没有其他方法可以改变迭代的大小?

其实max_iter应该是int,不应该是str

你可以尝试以下方法吗:

logisticR = LogisticRegression(random_state=0, max_iter=800, 
    solver='saga', multi_class='multinomial')

为什么要将 max_iter 对象值放在 '' 中。您正在创建一个 Str。你需要喂一个整数。就等于800吧。