import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import SGDClassifier
from sklearn.datasets import load_iris, make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, classification_report

x, y = make_classification(n_samples=5000, n_features=10, n_classes=2, n_clusters_per_class=1)

xtrain, xtest, ytrain, ytest=train_test_split(x, y, test_size=0.15)

sgdc = SGDClassifier(max_iter=1000, loss = 'log', eta0 = 1, learning_rate = 'constant', alpha = 0.1, tol=0.001)

sgdc.fit(xtrain, ytrain)

score = sgdc.score(xtrain, ytrain)
print("Training score: ", score)

ypred = sgdc.predict(xtest)
cm = confusion_matrix(ytest, ypred).ravel()
print(cm)

cr = classification_report(ytest, ypred)
print(cr)

## Iris dataset example
iris = load_iris()
x, y = iris.data, iris.target

xtrain, xtest, ytrain, ytest=train_test_split(x, y, test_size=0.15)

sgdc = SGDClassifier(max_iter=1000, loss = 'log', eta0 = 1, learning_rate = 'constant', alpha = 0.1, tol=0.001)
print(sgdc)

sgdc.fit(xtrain, ytrain)
score = sgdc.score(xtrain, ytrain)
print("Score: ", score)

ypred = sgdc.predict(xtest)

cm = confusion_matrix(ytest, ypred)
print(cm)

cr = classification_report(ytest, ypred)
print(cr)