-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession26.py
More file actions
56 lines (39 loc) · 1.27 KB
/
session26.py
File metadata and controls
56 lines (39 loc) · 1.27 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
54
55
56
# In classification we need to predict about it belongs to which group
# we need more than one classes
# regression is predicting continuous data
# classification is prediction of class labels or what is the category
# Decision Trees
from sklearn.datasets import load_iris
# load iris is a dataset in scikit
from sklearn import tree
# 1.Create Data
irisData = load_iris()
print("=========Iris dataset=======")
print(irisData)
print(type(irisData))
print()
# Array of Features
print(irisData.data)
print()
# Array of targets
print(irisData.target)
print()
# Array of Target names
print(irisData.target_names)
# 2.Lets create Model
model = tree.DecisionTreeClassifier()
# 3. Train the Model| Supervised Learning
model.fit(irisData.data, irisData.target)
# 4. Lets Test our model !!
inputData = [4.6, 3.4, 1.4, 0.3] # Versicolor type of iris flower
predictedClass = model.predict([inputData])
print("Predicted class is:", predictedClass)
print("Predicted class is:", predictedClass[0])
print("Predicted class is:", irisData.target_names[predictedClass[0]])
# Export our Data as graph visual!
import graphviz
data = tree.export_graphviz(model, out_file=None)
graph = graphviz.Source(data)
graph.render("IRIS DATASET TREE")
graph.view()
# Explore : Gini Index and Chi square w.r.t Tree