-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path003_wallis.py
More file actions
134 lines (123 loc) · 5.7 KB
/
Copy path003_wallis.py
File metadata and controls
134 lines (123 loc) · 5.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import argparse
import os
import numpy as np
import autosklearn
import autosklearn.data
import autosklearn.data.competition_data_manager
from autosklearn.pipeline.classification import SimpleClassificationPipeline
parser = argparse.ArgumentParser()
parser.add_argument('input')
parser.add_argument('output')
args = parser.parse_args()
input = args.input
dataset = 'wallis'
output = args.output
path = os.path.join(input, dataset)
D = autosklearn.data.competition_data_manager.CompetitionDataManager(path)
X = D.data['X_train']
y = D.data['Y_train']
X_valid = D.data['X_valid']
X_test = D.data['X_test']
# Replace the following array by a new ensemble
choices = \
[(0.580000, SimpleClassificationPipeline(configuration={
'balancing:strategy': 'weighting',
'classifier:__choice__': 'passive_aggressive',
'classifier:passive_aggressive:C': 0.0006373873391108438,
'classifier:passive_aggressive:fit_intercept': 'True',
'classifier:passive_aggressive:loss': 'squared_hinge',
'classifier:passive_aggressive:n_iter': 18,
'imputation:strategy': 'median',
'one_hot_encoding:use_minimum_fraction': 'False',
'preprocessor:__choice__': 'no_preprocessing',
'rescaling:__choice__': 'normalize'})),
(0.200000, SimpleClassificationPipeline(configuration={
'balancing:strategy': 'weighting',
'classifier:__choice__': 'passive_aggressive',
'classifier:passive_aggressive:C': 0.000465329983806252,
'classifier:passive_aggressive:fit_intercept': 'True',
'classifier:passive_aggressive:loss': 'squared_hinge',
'classifier:passive_aggressive:n_iter': 34,
'imputation:strategy': 'median',
'one_hot_encoding:use_minimum_fraction': 'False',
'preprocessor:__choice__': 'kernel_pca',
'preprocessor:kernel_pca:kernel': 'cosine',
'preprocessor:kernel_pca:n_components': 1351,
'rescaling:__choice__': 'normalize'})),
(0.180000, SimpleClassificationPipeline(configuration={
'balancing:strategy': 'none',
'classifier:__choice__': 'liblinear_svc',
'classifier:liblinear_svc:C': 0.7416809477859192,
'classifier:liblinear_svc:dual': 'False',
'classifier:liblinear_svc:fit_intercept': 'True',
'classifier:liblinear_svc:intercept_scaling': 1,
'classifier:liblinear_svc:loss': 'squared_hinge',
'classifier:liblinear_svc:multi_class': 'ovr',
'classifier:liblinear_svc:penalty': 'l2',
'classifier:liblinear_svc:tol': 0.0048882934000166346,
'imputation:strategy': 'most_frequent',
'one_hot_encoding:use_minimum_fraction': 'False',
'preprocessor:__choice__': 'select_percentile_classification',
'preprocessor:select_percentile_classification:percentile': 19.775149789978155,
'preprocessor:select_percentile_classification:score_func': 'chi2',
'rescaling:__choice__': 'normalize'})),
(0.020000, SimpleClassificationPipeline(configuration={
'balancing:strategy': 'none',
'classifier:__choice__': 'liblinear_svc',
'classifier:liblinear_svc:C': 0.4010081266689033,
'classifier:liblinear_svc:dual': 'False',
'classifier:liblinear_svc:fit_intercept': 'True',
'classifier:liblinear_svc:intercept_scaling': 1,
'classifier:liblinear_svc:loss': 'squared_hinge',
'classifier:liblinear_svc:multi_class': 'ovr',
'classifier:liblinear_svc:penalty': 'l2',
'classifier:liblinear_svc:tol': 0.003197120920655818,
'imputation:strategy': 'mean',
'one_hot_encoding:minimum_fraction': 0.0002497904559463802,
'one_hot_encoding:use_minimum_fraction': 'True',
'preprocessor:__choice__': 'no_preprocessing',
'rescaling:__choice__': 'normalize'})),
(0.020000, SimpleClassificationPipeline(configuration={
'balancing:strategy': 'none',
'classifier:__choice__': 'liblinear_svc',
'classifier:liblinear_svc:C': 0.7444178979935873,
'classifier:liblinear_svc:dual': 'False',
'classifier:liblinear_svc:fit_intercept': 'True',
'classifier:liblinear_svc:intercept_scaling': 1,
'classifier:liblinear_svc:loss': 'squared_hinge',
'classifier:liblinear_svc:multi_class': 'ovr',
'classifier:liblinear_svc:penalty': 'l2',
'classifier:liblinear_svc:tol': 0.00359411438055,
'imputation:strategy': 'mean',
'one_hot_encoding:minimum_fraction': 0.0018636449908690695,
'one_hot_encoding:use_minimum_fraction': 'True',
'preprocessor:__choice__': 'nystroem_sampler',
'preprocessor:nystroem_sampler:kernel': 'cosine',
'preprocessor:nystroem_sampler:n_components': 5183,
'rescaling:__choice__': 'normalize'})),
]
targets = []
predictions = []
predictions_valid = []
predictions_test = []
# Make predictions and weight them
iteration = 0
for weight, classifier in choices:
iteration += 1
print(dataset, "Iteration %d/%d" % (iteration, len(choices)))
try:
classifier.fit(X.copy(), y.copy())
predictions_valid.append(
classifier.predict_proba(X_valid.copy()) * weight)
predictions_test.append(
classifier.predict_proba(X_test.copy()) * weight)
except Exception as e:
print(e)
print(classifier.configuration)
# Output the predictions
for name, predictions in [('valid', predictions_valid),
('test', predictions_test)]:
predictions = np.array(predictions)
predictions = np.sum(predictions, axis=0).astype(np.float32)
filepath = os.path.join(output, '%s_%s_000.predict' % (dataset, name))
np.savetxt(filepath, predictions, delimiter=' ', fmt = '%.4e')