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

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

# + colab={"base_uri": "https://localhost:8080/", "height": 195} id="cIb8Ygkwn7Mn" outputId="a1b69274-1988-466f-aedb-ad47be0f28c2"
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
% matplotlib inline
import math

dataset = pd.read_csv("car_evaluation.csv")
dataset.head(5)



# + colab={"base_uri": "https://localhost:8080/"} id="2CerWtGvoEEB" outputId="171bb4ce-fd0c-473e-807c-8fb2eb2d8ad2"
dataset.shape



# + colab={"base_uri": "https://localhost:8080/", "height": 195} id="xmTtXYqNoEGs" outputId="6cb9f2a8-5a42-4ca5-fee6-0222f54a6c25"
col_names = ['buying', 'maintainance', 'doors', 'persons', 'lug_boot', 'safety', 'class']

dataset.columns = col_names
dataset.head(5)



# + colab={"base_uri": "https://localhost:8080/"} id="PY7FxPswoEJK" outputId="60023f80-f382-4d3f-d543-5498e56c806a"
dataset.isnull().sum()



# + colab={"base_uri": "https://localhost:8080/", "height": 195} id="V2P8_YEroEMF" outputId="0723187d-1340-49c3-8c26-3d3aedadc6cf"
dataset.columns

dataset['buying'],_ = pd.factorize(dataset['buying'])
dataset['maintainance'],_ = pd.factorize(dataset['maintainance'])
dataset['doors'],_ = pd.factorize(dataset['doors'])
dataset['persons'],_ = pd.factorize(dataset['persons'])
dataset['lug_boot'],_ = pd.factorize(dataset['lug_boot'])
dataset['safety'],_ = pd.factorize(dataset['safety'])
dataset.head()




# + colab={"base_uri": "https://localhost:8080/"} id="wTVyxPxzoEOs" outputId="3b62c776-e317-4a24-a695-ae225d6835e9"
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
print(X)
print(y)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,random_state=42)

X_train.shape, X_test.shape



# + id="RxnpOBSeoERT"
from sklearn.tree import DecisionTreeClassifier
clf_en = DecisionTreeClassifier(criterion='entropy', max_depth=3, random_state=0)


# fit the model
clf_en.fit(X_train, y_train)
y_pred = clf_en.predict(X_test)



# + colab={"base_uri": "https://localhost:8080/"} id="-MFs3Ra_oET6" outputId="4b3ceb9b-92e0-4ea0-ba64-474d95007441"

from sklearn.metrics import accuracy_score
accuracy_score(y_test,y_pred)

StarcoderdataJupyterScriptsDedupFiltered