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