-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsklearn_classification.py
More file actions
38 lines (28 loc) · 1.08 KB
/
sklearn_classification.py
File metadata and controls
38 lines (28 loc) · 1.08 KB
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
import numpy as np
import time
from sklearn.model_selection import cross_val_predict
from sklearn.linear_model import LogisticRegression, PassiveAggressiveClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import Perceptron
from sklearn.metrics import recall_score, precision_score, f1_score
data = np.genfromtxt('data.txt', delimiter = ',')
X = data[:, 0:13]
y = data[:, 13]
regressors = {
"log": LogisticRegression(solver = 'liblinear'),
"tree": DecisionTreeClassifier(),
"mlpc": MLPClassifier(),
"forest": RandomForestClassifier(n_estimators = 10),
"knc": KNeighborsClassifier(),
"percep": Perceptron()
}
regressor = regressors["tree"]
start = time.time()
regressor.fit(X,y)
end = time.time()
print('time: ', end - start)
#predict = regressor.predict(X[m:])
#print('F1=', f1_score(y[m:], predict), 'Recall= ', recall_score(y[m:], predict),'Precision= ',precision_score(y[m:], predict))