How can I describe these points with a regression? In the example the LinearRegression doesn't fit the logistic distribution of the points. The LogisticRegression() from sklearn just accept binary data. My y-values are continuous from 0 to 1. Do I have to transform the data or how do I get a appropriate model?

```import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression

a = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14])
b = [0,0,0.01,0.08,0.16,00.28,0.5,0.66,0.8,0.9,0.95,0.99,1,1]
data = pd.DataFrame({'x': a, 'y':b})

LM = LinearRegression()
LM.fit(data[["x"]],data[["y"]])

plt.scatter(a,b)
plt.plot([1,14], LM.predict([,]), color = "red")
plt.show()

LogM = LogisticRegression()
LogM.fit(data[["x"]],data[["y"]])  # doesn't work
```

scatter plot with linear model Mar 22, 2022 1,303 views

## 1 answer to this question.

Despite the fact that it produces a real between 0 and 1, a logistic regression is commonly used to classify labels. This is why sklearn requires binary data in y: so that the model can be trained
You have a sigmoid function s(x)=1/(1+exp(alpha*x + beta)) and you want to find alpha and beta in your scenario. The simplest method to achieve this, in my opinion, is to first change your data:

```ne_a = a[2:-2]
ne_b = np.array(b[2:-2]) # Getting rid of 0 and 1 values
ne_b = np.log((1 / ne_b) - 1)```

Because ne_b is now an array with values in the form alpha*ne_a + beta, you can use it to train a LinearRegression model to find alpha:

```model = LinearRegression()
model.fit(ne_a.reshape(-1, 1), ne_b.reshape(-1, 1))
alpha = model.coef_[0, 0]
beta = l.predict([])[0, 0]```

Finally, you may see if this matches to your expectations:

```predicted = 1 / (1 + np.exp(alpha * a + beta))
plt.figure()
plt.plot(a, b)
plt.plot(a, predicted)
plt.show()
``` • 6,000 points

## Linear regression with gradient descent to predict house prices using area (one var) in python

Apart from instructional purposes, I'm not sure ...READ MORE

## Example of Logistic regression with python code

Have a look at this: import csv import ...READ MORE

## Efficient online linear regression algorithm in python

To calculate 10k rows, and also to speed ...READ MORE

+1 vote

## View onto a numpy array?

just index it as you normally would. ...READ MORE

## Dimension in python numpy

Use the .shape to print the dimensions ...READ MORE