<jupyter_start><jupyter_text>Logistic functionShown in the plot is how the logistic regression would, in thissynthetic dataset, classify values as either 0 or 1,i.e. class one or two, using the logistic curve.<jupyter_code># General a toy dataset:s it's just a straight line with some Gaussian noise:
a1sd_mean  = 5 # 5.8
a1sd_stdev = 2.5

coverage = 1 # Half width of plotting interval as a number of time standard deviation
xmin = math.ceil(a1sd_mean - 4*coverage * a1sd_stdev)
xmax = math.ceil(a1sd_mean + coverage * a1sd_stdev)
print(xmin,xmax)
#xmin, xmax = -5, 5
n_samples = 100
np.random.seed(0)
X = np.random.normal(size=n_samples)
y = (X > 0).astype(float)
X[X > 0] *= 4
X += .3 * np.random.normal(size=n_samples)
# print(X[:])

X = X[:, np.newaxis] # Add axis to have a columnar array (transpode of X?)
#X.shape
#print(X[:,0])

from scipy import stats
stats.describe(X)
# Fit the classifier
clf = linear_model.LogisticRegression(C=1e5)
clf.fit(X, y)

# and plot the result
plt.figure(figsize = (12,5), dpi=100)
plt.clf()
plt.scatter(X.ravel(), y, color='black', zorder=20)
X_test = np.linspace(xmin, xmax, 300)

loss = expit(X_test * clf.coef_ + clf.intercept_).ravel()
plt.plot(X_test, loss, color='red', linewidth=3)

ols = linear_model.LinearRegression()
ols.fit(X, y)
plt.plot(X_test, ols.coef_ * X_test + ols.intercept_, linewidth=1)
plt.axhline(.5, color='.5')

plt.ylabel('y')
plt.xlabel('X')
plt.xticks(range(xmin, 2*xmax))
plt.yticks([0, 0.5, 1])
plt.ylim(-.25, 1.25)
plt.xlim(xmin, 2*xmax)
plt.legend(('Logistic Regression Model', 'Linear Regression Model'),
           loc="lower right", fontsize='small')
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15361803084223014, 'fraction_numerical': 0.03202846975088968, 'mean_word_length': 5.068345323741007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '531671', 'license': 'MIT', 'n_tokens_mistral': 732, 'n_tokens_neox': 675, 'n_words': 173, 'path': 'data/plot_logistic.ipynb', 'repo_name': 'therobotacademy/kaggle-gearbox-analysis', 'size': '1686'}