-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decision Tree.py
91 lines (37 loc) · 971 Bytes
/
Decision Tree.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# coding: utf-8
# In[22]:
import pandas as pd
df = pd.read_csv("salaries.csv")
df.head()
# In[23]:
inputs = df.drop("salary_more_then_100k", axis = "columns")
targets = df["salary_more_then_100k"]
# In[36]:
inputs
# In[26]:
from sklearn.preprocessing import LabelEncoder
# In[27]:
le_company = LabelEncoder()
le_job = LabelEncoder()
le_degree = LabelEncoder()
# In[29]:
inputs["company_n"] = le_company.fit_transform(inputs["company"])
inputs["job_n"] = le_job.fit_transform(inputs["job"])
inputs["degree_n"] = le_degree.fit_transform(inputs["degree"])
inputs.head()
# In[30]:
inputs_n = inputs.drop(["job","degree", "company"], axis = "columns")
inputs_n
# In[31]:
from sklearn import tree
# In[32]:
model = tree.DecisionTreeClassifier()
# In[34]:
model.fit(inputs_n,targets)
# models.score(inputs_n, targets)
# In[35]:
model.score(inputs_n,targets)
# In[40]:
model.predict([[1,2,1]])
# In[ ]: