Logistic Regression with continuous data using sklearn in python

0 votes

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([[1],[14]]), color = "red")
plt.show() 

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

scatter plot with linear model
enter image description here

Mar 22, 2022 in Machine Learning by Nandini
• 5,480 points
3,801 views