使用Logistic回归(python)时,最大迭代次数必须为正误差

2024-09-30 12:23:48 发布

您现在位置: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:最大迭代次数必须为正;got(max_iter='800')

由于max_iter默认为100,是否有其他方法更改迭代的大小?在


Tags: testfalsesizemodelreturntrainsklearnmax
2条回答

实际上max_iter应该是int,而不是str

你能试试下列方法吗:

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

为什么要将max_iter对象值放在“”中。你正在创建一个Str。你需要输入一个int。把它等于800。在

相关问题 更多 >

    热门问题