-
Notifications
You must be signed in to change notification settings - Fork 6
/
dt.py
51 lines (31 loc) · 1.06 KB
/
dt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""DT.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Fm7pU3JyQHDDg9rLO1roAFOh8ot06EMW
"""
import pandas as pd
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
import matplotlib as plt
df = pd.read_csv("/content/pima-indians-diabetes.csv")
df
X = df.iloc[:,:-1]
Y= df['label']
df
from sklearn.model_selection import train_test_split
X_train , X_test , Y_train , Y_test = train_test_split(X,Y ,test_size= 0.3 , random_state= 0)
model = DecisionTreeClassifier()
model.fit(X_train,Y_train)
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(100,100))
_ = tree.plot_tree(model , feature_names= Y)
predict = model.predict(X_test)
import matplotlib.pyplot as plt
import numpy
from sklearn import metrics
confusion_matrix = metrics.confusion_matrix(Y_test, predict)
cm_display = metrics.ConfusionMatrixDisplay(confusion_matrix = confusion_matrix, display_labels = [False, True])
cm_display.plot()
plt.show()
accuracy_score(Y_test, predict)