File size: 565 Bytes
a647f03
 
e369ba4
a647f03
e369ba4
 
 
 
a647f03
e369ba4
a647f03
e369ba4
a647f03
e369ba4
 
a647f03
e369ba4
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt

# Generate some sample binary data
np.random.seed(0)
X = np.random.randn(100, 1)
y = np.where(np.dot(X, np.array([0.5, 0.5])) > 0, 1, 0)

# Create logistic regression object and fit the model to the data
model = LogisticRegression()
model.fit(X, y)

# Predict probabilities
predictions = model.predict_proba(X)[:,1]

# Plot the results
plt.scatter(X, y)
plt.plot(X, predictions, color='red', alpha=0.5)
plt.xlabel('Feature')
plt.ylabel('Probability')
plt.show()