-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_data.py
More file actions
70 lines (55 loc) · 1.71 KB
/
Copy pathtest_data.py
File metadata and controls
70 lines (55 loc) · 1.71 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
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
"""
This script is used to test how 'complex' particular
dataset used for demos is, based on python tools.
"""
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.svm import LinearSVC
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.dummy import DummyClassifier
import pandas as pd
import numpy as np
def read_dataset(years):
Xy = pd.read_csv('python_prototypes/data/bankruptcy_after_'+str(years)+'_years.csv')
Xy = Xy.replace('?', np.nan)
Xy = Xy.fillna(0.0)
Xy = Xy.as_matrix()
X, y = Xy[:, :-1], Xy[:, -1]
X = X.astype('float')
y = y.astype('int')
return X, y
X_train, X_test, y_train, y_test = train_test_split(*read_dataset(5), **{'random_state': 1})
#X_train, y_train = read_dataset(1)
#X_test, y_test = read_dataset(5)
gbrt = {
'model': [GradientBoostingClassifier()],
'model__n_estimators': [2 ** i for i in range(1, 10)]
}
lsvm = {
'model': [LinearSVC(dual=False, max_iter=100000)],
'model__C': [10.0 ** i for i in range(-6, 6)],
'model__penalty': ['l1', 'l2']
}
knnc = {
'model': [KNeighborsClassifier()],
'model__n_neighbors': [i for i in range(1, 100, 5)]
}
model = GridSearchCV(
estimator = Pipeline([
('scale', StandardScaler()),
('model', DummyClassifier())
]),
param_grid = [lsvm],
cv=5,
n_jobs= -1,
verbose=1
)
dummy = DummyClassifier(strategy='most_frequent')
model.fit(X_train, y_train)
dummy.fit(X_train, y_train)
print('Dummy accuracy:')
print(dummy.score(X_test, y_test))
print('Model score:')
print(model.score(X_test, y_test))