# https://realpython.com/logistic-regression-python/
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix

x = np.arange(10).reshape(-1, 1) # x=[0,1,2,3,4,5,6,7,8,9]
y = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1])

model = LogisticRegression(solver='liblinear', random_state=0)
model.fit(x, y)

# model = LogisticRegression(solver='liblinear', random_state=0).fit(x, y)

print('model.classes',model.classes_)

print('model.intercept', model.intercept_)

print('model.coef', model.coef_)

aa = model.predict_proba(x)
print('aa', aa) # Predicted probabilities of each class for the input data x 

aa2 = model.predict(x)
print('aa2', aa2) # Predicted class labels for the input data x 

print('model score', model.score(x, y)) # Logistic regression accuracy, ranging from 0 to 1

cm = confusion_matrix(y, model.predict(x)) 

fig, ax = plt.subplots(figsize=(8, 8))
ax.imshow(cm)
ax.grid(False)
ax.xaxis.set(ticks=(0, 1), ticklabels=('Predicted 0s', 'Predicted 1s'))
ax.yaxis.set(ticks=(0, 1), ticklabels=('Actual 0s', 'Actual 1s'))
ax.set_ylim(1.5, -0.5)
for i in range(2):
    for j in range(2):
        ax.text(j, i, cm[i, j], ha='center', va='center', color='red')
plt.show()

print(classification_report(y, model.predict(x)))