Tree DecisionTreeClassifi er random_state max_features max_depth min_s

 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
Tree = DecisionTreeClassifier(random_state = 6, max_features=5, max_depth=8, min_samples_leaf=1)
Tree.fit(X_train_scaled, y_train)
train = Tree.score(X_train_scaled, y_train)*100
test = Tree.score(X_test_scaled, y_test)*100
print("DecisionTreeClassifier best")
print(train)
print(test)
plt.figure(figsize=(10,7))
plt.barh(range(34), Tree.feature_importances_, align='center')
plt.yticks(np.arange(34), np.arange(34))
plt.xlabel("Feature importance")
plt.ylabel("Featurе")
# GradientBoostingClassifier best
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split
import mglearn
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
boosting = GradientBoostingClassifier(random_state = 6, learning_rate=41/100, n_estimators=11, subsample=5/10)
boosting.fit(X_train_scaled, y_train)
train = boosting.score(X_train_scaled, y_train)*100
test = boosting.score(X_test_scaled, y_test)*100
print("GradientBoostingClassifier best")
print(train)
print(test)
# np_resuts = np.array(np.around(boosting.predict_proba(X_test_scaled), decimals=1))
# data_pd = pd.DataFrame(np_resuts)
# data_pd.columns = ['g','b']
# display(data_pd)
plt.figure(figsize=(10,7))
plt.barh(range(34), boosting.feature_importances_, align='center')
plt.yticks(np.arange(34), np.arange(34))
plt.xlabel("Feature importance")
plt.ylabel("Featurе")
forest = RandomForestClassifier(n_estimators=14, max_features=14, max_depth=8, min_samples_leaf=1, random_state=6)
forest.fit(X_train_scaled, y_train)
train = forest.score(X_train_scaled, y_train)*100
test = forest.score(X_test_scaled, y_test)*100
print("RandomForestClassifier best")
print(train)
print(test)
plt.figure(figsize=(10,7))
plt.barh(range(34), forest.feature_importances_, align='center')
plt.yticks(np.arange(34), np.arange(34))
plt.xlabel("Feature importance")
plt.ylabel("Featurе")