-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom Forest.py
84 lines (34 loc) · 809 Bytes
/
Random Forest.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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
from sklearn.datasets import load_digits
digits = load_digits()
# In[2]:
dir(digits)
# In[4]:
import matplotlib.pyplot as plt
plt.gray()
for i in range(4):
plt.matshow(digits.images[i])
# In[6]:
df = pd.DataFrame(digits.data)
df.head()
# In[8]:
df["targets"] = digits.target
df.head()
# In[9]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(df.drop(['targets'], axis = "columns"), digits.target,test_size = 0.2)
# In[10]:
len(X_test)
# In[11]:
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train, y_train)
# In[12]:
model.score(X_test, y_test)
# In[20]:
X_test
# In[ ]:
# In[ ]: