|
a |
|
b/classifier.py |
|
|
1 |
from read_data import * |
|
|
2 |
from sklearn.ensemble import RandomForestClassifier |
|
|
3 |
from sklearn.datasets import make_classification |
|
|
4 |
from sklearn.model_selection import train_test_split |
|
|
5 |
from sklearn.mixture import GaussianMixture |
|
|
6 |
|
|
|
7 |
if __name__ == '__main__': |
|
|
8 |
data = execute() |
|
|
9 |
print(data.shape) |
|
|
10 |
X = data[:, :16] # 16 features |
|
|
11 |
y = data[:, 16] |
|
|
12 |
print(X.shape) |
|
|
13 |
print(y.shape) |
|
|
14 |
print(y) |
|
|
15 |
train_features, test_features, train_labels, test_labels = train_test_split(X, y, |
|
|
16 |
test_size=0.25) |
|
|
17 |
print('Training Features Shape:', train_features.shape) |
|
|
18 |
print('Training Labels Shape:', train_labels.shape) |
|
|
19 |
print('Testing Features Shape:', test_features.shape) |
|
|
20 |
print('Testing Labels Shape:', test_labels.shape) |
|
|
21 |
|
|
|
22 |
clf = RandomForestClassifier(n_estimators=100, max_depth=5, oob_score=True) |
|
|
23 |
clf.fit(X, y) |
|
|
24 |
print(clf.feature_importances_) |
|
|
25 |
# print(clf.oob_decision_function_) |
|
|
26 |
print(clf.oob_score_) |
|
|
27 |
predictions = clf.predict(test_features) |
|
|
28 |
errors = abs(predictions - test_labels) |
|
|
29 |
print("M A E: ", np.mean(errors)) |
|
|
30 |
print(np.count_nonzero(errors), len(test_labels)) |
|
|
31 |
print("Accuracy:", np.count_nonzero(errors)/len(test_labels)) |