-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecisionTree.py
More file actions
53 lines (37 loc) · 1.28 KB
/
Copy pathdecisionTree.py
File metadata and controls
53 lines (37 loc) · 1.28 KB
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
52
53
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 1 13:58:57 2023
Ques: Write a program to demonstrate the working of the decision tree classifier. Use appropriate dataset
for building the decision tree and apply this knowledge to classify a new sample
@author: _aditya
"""
import pandas as pd
data=pd.read_csv(r"C:\Users\LENOVO\Desktop\aiml\iris.csv")
#print(data.head())
data.dropna(inplace=True)
x=data.iloc[:,:-1].values
y=data.iloc[:,-1].values
from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.2,random_state=4)
#DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
model=DecisionTreeClassifier(criterion='entropy')
##RandomForestClassifier
##from sklearn.ensemble import RandomForestClassifier
##model=RandomForestClassifier()
##LogisticRegression
##from sklearn.linear_model import LogisticRegression
##model=LogisticRegression()
##SupportVector
##from sklearn.svm import SVC
##model=SVC()
##naive_bayes
##from sklearn.naive_bayes import GaussianNB
##model=GaussianNB()
model.fit(xtrain,ytrain)
ypred=model.predict(xtest)
from sklearn.metrics import accuracy_score
print(accuracy_score(ytest,ypred)*100)
#3--
(model.predict([[1.2,2.1,4.5,6.1]]))
#print(x)