-1

Below is my simple code.

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))

The output I am getting is:

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

I have tried this with other data and in PyCharm as well, same thing.

What am I doing wrong?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • 1
    Does this answer your question? [What does "fit" method in scikit-learn do?](https://stackoverflow.com/questions/45704226/what-does-fit-method-in-scikit-learn-do) – Lescurel Oct 09 '20 at 12:20
  • This is very low level question OP can easily check the Sklearn documentation. Why you leave the answers?! adding `model.fit(x, y)` `model.predict(x[:2, :])` `model.score(x, y)` He needs to just google first! – Mario Oct 09 '20 at 12:37
  • I’m voting to close this question because the described behavior is the expected & nominal one, and there is not any issue or error to be rectified or debugged. – desertnaut Oct 09 '20 at 21:25

1 Answers1

0

Scikit learn's models all work in a similar way. The fit method does not return anything, it only updates the model's parameters, i.e. it does the training. You can see it in the documentation.

If you want to return predictions as an example, you need to use the predict method. Note that you should use the predict method after fitting the model of course (this is valid any other method that needs a fitted model in order to make sense). Note that the models usually also implement a fit_predictmethod that does both at the same time.

Your code could look like this:

model = LogisticRegression(solver='liblinear', random_state=0)
model.fit(x, y) #does the learning
predictions = model.predict(x) #getting the predicted values on the training dataset
A Co
  • 908
  • 6
  • 15
  • What do you mean by `model.predict(x)` it returns back `array([0, 0, 0, 1, 1, 1, 1, 1, 1, 1]) `which is `x`. – Mario Oct 09 '20 at 12:48
  • `model.predict(x)` returns predictions, let's call them `y_pred`. In you case, `ypred = y` which means that the models has a 100% accuracy **on the training set**. – A Co Oct 09 '20 at 14:24