Python 尝试运行LogisticRegression的fit函数时未获得任何输出

Python 尝试运行LogisticRegression的fit函数时未获得任何输出,python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,下面是我的简单代码 import matplotlib.pyplot as plt import numpy as np from sklearn.linear_model import LogisticRegression from sklearn.metrics import classification_report, confusion_matrix x = np.arange(10).reshape(-1, 1) y = np.array([0, 0, 0, 0, 1, 1, 1,

下面是我的简单代码

import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix

x = np.arange(10).reshape(-1, 1)
y = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1])

model = LogisticRegression(solver='liblinear', random_state=0)

print(model.fit(x, y))

我得到的结果是:

LogisticRegression(random_state=0, solver='liblinear')
我用其他数据和PyCharm做了同样的尝试


我做错了什么?

Scikit learn的模型都以类似的方式工作。
fit
方法不返回任何内容,它只更新模型的参数,即进行训练

如果希望返回预测作为示例,则需要使用
predict
方法。请注意,在拟合模型后,当然应该使用
predict
方法(这对于需要拟合模型才能理解的任何其他方法都是有效的)。请注意,这些模型通常还实现了一种同时执行这两种操作的
fit\u predict
方法

您的代码可能如下所示:

model=logistic回归(solver='liblinear',random_state=0)
model.fit(x,y)#进行学习
预测=模型。预测(x)#获取训练数据集上的预测值

这是否回答了您的问题?这是一个非常低级的问题,OP可以轻松查看Sklearn文档。你为什么留下答案?!添加
model.fit(x,y)
model.predict(x[:2,:])
model.score(x,y)
他需要先用谷歌搜索一下!我投票结束这个问题,因为所描述的行为是预期的和名义上的,没有任何问题或错误需要纠正或调试。你所说的
model.predict(x)
是什么意思?它返回
数组([0,0,0,1,1,1,1,1,1])
它是
x
model.predict(x)返回预测,我们将其称为
y\u pred
。在您的情况下,
ypred=y
,这意味着模型在训练集上具有100%的准确性。