Professional Documents
Culture Documents
Random Forest
Random Forest
Random Forest
Omkar Singh
102
A1
Random Forest
Out[14]: stalk- st
cap- cap- cap- gill- gill- gill- gill- surface- co
class bruises odor ...
shape surface color attachment spacing size color below- abo
ring
0 p x s n t p f c n k ... s
1 e x s y t a f c b k ... s
2 e b s w t l f c b n ... s
3 p x y w t p f c n n ... s
4 e x s g f n f w b k ... s
5 rows × 23 columns
In [15]: df.drop(['cap-shape','cap-color','cap-surface','gill-attachment','gill-spacing','gi
In [16]: df.head()
0 p t p s u
1 e t a n g
2 e t l n m
3 p t p s u
4 e f n a g
In [17]: print(df)
In [18]: df.describe()
unique 2 2 4 5 5
top e t a s g
d = {'t': 1, 'f': 0}
df['bruises'] = df['bruises'].map(d)
# bruises=t,no=f
print(df)
In [57]: len(X_train)
452
Out[57]:
In [58]: X_train.head()
473 0 3 4 0
598 1 0 0 1
72 1 2 3 4
467 1 2 1 1
378 1 2 1 1
In [59]: len(X_test)
151
Out[59]:
In [60]: X_test.head()
543 1 1 0 1
456 1 1 1 1
454 1 2 1 2
338 0 3 3 0
444 1 2 1 2
RandomForestClassifier(random_state=0)
Out[63]:
RandomForestClassifier(n_estimators=20)
Out[65]:
1.0
Out[66]:
array([[23, 0, 0, 0, 0],
Out[68]:
[ 0, 66, 0, 0, 0],
[ 0, 0, 34, 0, 0],
[ 0, 0, 0, 9, 0],
[ 0, 0, 0, 0, 19]], dtype=int64)
In [ ]:
In [ ]: