0

I was using scikit-learn.linear_model.LogisticRegression, but it didn't work so well.

I started with an x and y list. X was integers between -10 and 10 inclusive. Y was the x value plugged into the logistic function 100/ (1 + e^-x). This means it should have been a perfect Logistic Regression.

It worked well, but when I changed the Y slightly (+1, -1, or 0 for every y value), it didn't work. When plotted with matplotlib.pyplot it was clearly a logistic curve.

I tried

reg = linear_model.LogisticRegression(C=10e4) reg.fit(x, y) reg.predict(x)

The predicted Y had half the points at the minimum y (y=0), and the other half at the maximum (y=100). I tried with C as the default value, but the same thing happened.

Why is this, and how do I get a correct regression model?

Also: Orange is the model, blue is the actual. This one is a little bit better, but when C is default, all oranges are above 100 or less than 0

Orange is the model, blue is the actual. This one is a little bit better, but when C is default, all oranges are above 100 or less than 0

B. Johnson
  • 45
  • 6
  • 2
    Since LogisticRegression is used for categorization, your code predicts your categories in y which are derived from your floats resulting from 100/ (1 + e^-x) , right?. If you rather want to do regression, you can find good code examples in the link below. In order to understand the impact of the regularization parameter C (if you really want this), you need to share how your categories look like that are created from the float. https://stackoverflow.com/questions/41925157/logisticregression-unknown-label-type-continuous-using-sklearn-in-python – Andi Schroff Feb 12 '20 at 10:31
  • @andi I thought that since it was LogisticRegression, it would do Regression. For the C value, I used the default on a perfect Logistic curve. When it didn't work, I googled and it said to use a large C value, so I used C=10e4. – B. Johnson Feb 12 '20 at 23:03
  • @AndiSchroff Also, I used integers, not floats, so the link isn't really what I'm looking for. I tries `linear_model.BayesianRidge`, but that didn't work well with Logistic curves. Is there something in linear_model for logistic **regression** and not classification? – B. Johnson Feb 12 '20 at 23:15

0 Answers0