# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/madhavjk/DataScience-ML_and_DL/blob/main/SESSION_20_(Classification_Evaluation_Metrics).ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="_6BmHalM2M40"
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# + id="fW0Bel202M42"
df = pd.read_csv('Social_Network_Ads.csv')
X = df[['Age', 'EstimatedSalary']].values
y = df['Purchased']

# + id="9UC0I7Z22M43"
from sklearn.model_selection import train_test_split
x_train , x_test, y_train, y_test = train_test_split(X,y, test_size = 0.25, random_state = 0)

# + id="Rf4rjVgE2M44"
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.fit_transform(x_test)

# + id="jgZRAsKX2M46" outputId="1256fcf0-02d0-4c9b-b192-9b7100c10103"
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression()
classifier.fit(x_train, y_train)

# + id="NuFPNQ5n2M5D"
y_pred = classifier.predict(x_test)

# + id="KllyPRwr2M5E" outputId="b3d6ed08-bf9c-454c-e981-ff168b4857ef"
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_pred,y_test)
cm

# + id="IT31GzdF2M5H" outputId="77eb4480-62b1-4a2b-8b2b-97a5f78fc27f"
from sklearn.metrics import accuracy_score
accuracy_score(y_pred,y_test)

# + id="C90RfRZD2M5J" outputId="7faac07d-c034-494d-a385-847090c84ff4"
(63+25)/(63+25+7+5)

# + id="tOgDv8pA2M5L" outputId="1268d44a-f558-43fc-d502-e34ac7c48e03"
from sklearn.metrics import precision_score,recall_score,f1_score
f1_score(y_pred,y_test)

# + id="uQzqSw5c2M5a" outputId="75683415-b146-4086-bac7-208167a986c4"
precision_score(y_pred,y_test)

# + id="BqaaCO2d2M5b" outputId="de3afec0-b42c-4d1a-9492-e6e8a3f7b687"
recall_score(y_pred,y_test)

# + id="GUx1b2sO2M5c" outputId="a07b965c-917a-4cf1-df9c-b83d701a110a"
# jaccard_index
from sklearn.metrics import jaccard_score
jaccard_score(y_pred,y_test)


# + id="f_hV7qdZ2M5j" outputId="58f74be9-4b32-42a3-a893-fbb85ce3b849"
# Log Loss
from sklearn.metrics import log_loss
log_loss(y_test,y_pred)

# + id="-Yxtice-2M5k" outputId="e133f39a-06e2-48de-d50a-3216489568db"
# ROC_AUC_Score
from sklearn.metrics import roc_auc_score
roc_auc_score(y_test,y_pred)

# + id="zk3ZOzW-2M5p"


StarcoderdataJupyterScriptsDedupFiltered