text_plain_output_1.png image_output_1.png
from pandas.plotting import andrews_curves

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import RocCurveDisplay, classification_report

from sklearn.model_selection import train_test_split

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import StandardScaler, LabelEncoder, LabelBinarizer

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

df_iris = pd.DataFrame(pd.read_csv('/kaggle/input/iris/Iris.csv'))

df_iris.groupby('Species').size()

X = df_iris.iloc[:, 1:5]
y = pd.DataFrame(df_iris.iloc[:, 5])
le = LabelEncoder()
y['Species'] = le.fit_transform(y['Species'])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)

andrews_curves(df_iris.drop('Id', axis=1), 'Species')

df_iris.drop('Id', axis=1).boxplot(by='Species', figsize=(15, 10))

model = Pipeline([('scaler', StandardScaler()), ('classifier', LogisticRegression())])

model.fit(X_train, y_train)

y_pred = model.predict(X_test)

y_score = model.predict_proba(X_test)

def show_roc(class_of_interest):
    label_binarizer = LabelBinarizer().fit(y_train)
    y_onehot_test = label_binarizer.transform(y_test)
    label_binarizer.transform([class_of_interest])
    class_id = np.flatnonzero(label_binarizer.classes_ == class_of_interest)[0]
    RocCurveDisplay.from_predictions(y_onehot_test[:, class_id], y_score[:, class_id], name=f'{class_of_interest} vs the rest')
    plt.axis('square')

show_roc('Iris-setosa')
show_roc('Iris-versicolor')
show_roc('Iris-virginica')