[go: up one dir, main page]

0% found this document useful (0 votes)
9 views2 pages

Deci Tree Codes

The document outlines a Python script that utilizes libraries such as NumPy, Matplotlib, and Pandas to implement a Decision Tree Classifier on a dataset. It includes steps for data preprocessing, model training, and evaluation using a confusion matrix, along with visualizing the decision tree. The script is designed to predict outcomes based on features like age and estimated salary from the provided dataset.

Uploaded by

Dr Sumathy V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Deci Tree Codes

The document outlines a Python script that utilizes libraries such as NumPy, Matplotlib, and Pandas to implement a Decision Tree Classifier on a dataset. It includes steps for data preprocessing, model training, and evaluation using a confusion matrix, along with visualizing the decision tree. The script is designed to predict outcomes based on features like age and estimated salary from the provided dataset.

Uploaded by

Dr Sumathy V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import numpy as nm

import matplotlib.pyplot as mtp


import pandas as pd

data_set= pd.read.csv('/content/user_data_deci_tree.csv')

x= data_set.iloc[:, (2,3)].values
y= data_set.iloc[:, 4].values

from sklearn.model_selection import train_test_split


x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.2
5)

from sklearn.preprocessing import StandardScaler


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

from sklearn.tree import DecisionTreeClassifier


classifier= DecisionTreeClassifier(criterion='entropy', random_state=0)

classifier.fit(x_train, y_train)

#DecisionTreeClassifier(class_weight=None, criterion='entropy', max_dep


th=None,
max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, presort=False,
random_state=0, splitter='best')

y_pred= classifier.predict(x_test)

From sklearn.metrics import confusion_matrix


cm= confusion_matrix(y_test, y_pred)
cm
from sklearn import tree
fig, ax = plt.subplots(figsize=(10, 10)) #figsize value changes the siz
e of plot
tree.plot_tree(classifier,ax=ax,feature_names=['Age','EstimatedSalary']
,fontsize=6)
plt.show()

You might also like