# ---
# 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
# ---

# + colab={} colab_type="code" id="E0dss3nUnmik"
import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
import seaborn as sns

sns.set()
# -



# + colab={} colab_type="code" id="xR3Btgv5p0aD"
from sklearn.datasets import load_wine

# + colab={} colab_type="code" id="GD5QaZN2p0ch"
data = load_wine()
df = pd.DataFrame(data.data, columns=data.feature_names)
df["target"] = data.target

# + colab={"base_uri": "https://localhost:8080/", "height": 215} colab_type="code" id="p6iQR4olp0fC" outputId="1d9cfcc2-9edb-4bfd-a43f-25733779cd6d"
df.head()

# + colab={} colab_type="code" id="3sH5UbGfp0hL"


# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="VYGpnkXPp0jx" outputId="3b34282f-e8ca-4fa5-af75-b3502e178ee8"
df.isna().sum().sum()

# + colab={"base_uri": "https://localhost:8080/", "height": 468} colab_type="code" id="6EMu-ZsCq0Dw" outputId="4fbd7fdc-cc37-459f-80d8-88cbb788f726"
df.describe().T

# + colab={} colab_type="code" id="1jBEt3G7q0GY"


# + colab={} colab_type="code" id="eVYv0wgtq0Ip"
# EDA

# + colab={"base_uri": "https://localhost:8080/", "height": 435} colab_type="code" id="z3wQyItEq0LH" outputId="247a83bb-9e3e-41ef-e99c-88e4a558806b"
sns.countplot(df["target"])

# + colab={} colab_type="code" id="PQr5olvarQ6I"
from sklearn.model_selection import train_test_split

# + colab={} colab_type="code" id="CPEmV9WirQ8Q"
y = df["target"]
df.drop(columns=["target"], inplace=True)

# + colab={} colab_type="code" id="_AybR29mrQ-f"


# + colab={} colab_type="code" id="Qb00jwbqr1gv"
x_train, x_test, y_train, y_test = train_test_split(df, y, test_size=0.2, stratify=y)

# + colab={"base_uri": "https://localhost:8080/", "height": 435} colab_type="code" id="uUK2_gU-r1i_" outputId="29aa686e-8258-4d83-e726-d0241c376454"
sns.countplot(y_train)

# + colab={"base_uri": "https://localhost:8080/", "height": 435} colab_type="code" id="wRGJTzFBr1lW" outputId="01195554-fcd6-4eae-8bc3-7a1951239d0b"
sns.countplot(y_test)

# + colab={} colab_type="code" id="-tVa_JL-r1n7"


# + colab={} colab_type="code" id="XyvmB31Cr1p3"


# + colab={} colab_type="code" id="q8QtrlkZr1sK"
from sklearn.tree import DecisionTreeClassifier

# + colab={} colab_type="code" id="LmzM9athr1uf"
model = DecisionTreeClassifier()

# + colab={"base_uri": "https://localhost:8080/", "height": 126} colab_type="code" id="jDBa3nAwr1w5" outputId="2f0cc96c-f275-43fd-a96f-6be288f4d52b"
model.fit(x_train, y_train)

# + colab={} colab_type="code" id="JQeBU7XKq0No"
y_preds = model.predict(x_test)

# + colab={} colab_type="code" id="mQqvj3QZtc2_"
from sklearn.metrics import accuracy_score


# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="iYMHK4JMtpsX" outputId="122fa5af-c862-4acf-d889-8da31f2506c2"
accuracy_score(y_test, y_preds)

# + colab={} colab_type="code" id="YqESPUWMttOv"


# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="YrDNqw3WtwOV" outputId="bfa4d1c8-97cf-49eb-a1c6-419bc4f2f2ea"
from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import StandardScaler


ss = StandardScaler()
x_train = ss.fit_transform(x_train)
x_test = ss.transform(x_test)

model_2 = KNeighborsClassifier()
model_2.fit(x_train, y_train)
y_preds = model_2.predict(x_test)

accuracy_score(y_test, y_preds)



# + colab={} colab_type="code" id="An3qWmkctwQ0"
accs = []
for h in range(2, 50):
    model = DecisionTreeClassifier(max_depth=h)
    model.fit(x_train, y_train)
    y_pred = model.predict(x_test)
    acc = accuracy_score(y_test, y_pred)
    accs.append(acc)

# + colab={"base_uri": "https://localhost:8080/", "height": 35} colab_type="code" id="gIIk6uRdu_gd" outputId="ef8819f3-bde5-45c7-ddaa-9ee30fbcc5c5"
len(y_test)

# + colab={} colab_type="code" id="QZlTSsemvK71"


StarcoderdataJupyterScriptsDedupFiltered