forked from k-l-a/DatasetSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataset2Config.py
100 lines (80 loc) · 2.45 KB
/
Dataset2Config.py
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
import autosklearn.classification
from hyperopt import hp, tpe
from hpsklearn import HyperoptEstimator, gradient_boosting, any_classifier
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings("ignore", "Mean of empty slice")
path = ""
defaultPath = "./HyperparameterConfig/"
savePath = "./HyperparameterConfig/"
exitCommand = "exit"
loadCommand = "load"
saveCommand = "save"
indexFilename = "./saved_index2"
fileListName = "./saved_filelist2"
indexType = "L2"
fileList = []
searchTerm = ""
weights = []
def getHyperparameter(X, y):
test_size = int(0.2 * len(y))
indices = np.random.permutation(X.shape[0])
X_train = X
X_test = X
y_train = y
y_test = y
training_idx, test_idx = indices[:80], indices[80:]
# X_train = X[training_idx,:]
# y_train = y[indices[:-test_size]]
# X_test = X[indices[-test_size:]]
# y_test = y[indices[-test_size:]]
# estim = HyperoptEstimator(classifier= gradient_boosting('my_gbdt'), max_evals=100, trial_timeout=120)
automl = autosklearn.classification.AutoSklearnClassifier(
include_estimators=["gradient_boosting", ], exclude_estimators=None, ensemble_size=1)
automl.fit(X_train.values, y_train.values)
automl.cv_results_
automl.sprint_statistics()
automl.show_models()
automl.get_params()
print(automl.get_params())
#estim.fit(X_train.values, y_train.values)
#print(estim.best_model())
def separate(df):
n = len(df.columns)
df.columns = list(range(n))
x = df[list(range(2, n))]
y = df[1].astype('category')
return x, y
def catToNum(df):
df.columns = list(range(len(df.columns)))
is_number = np.vectorize(lambda x: np.issubdtype(x, np.number))
arr = is_number(df.dtypes)
for i in range(len(arr)):
isNum = arr[i]
if not isNum:
df[i] = df[i].astype('category').cat.codes
return df
def getDatasetFromFile(filepath):
x, y = separate(catToNum(pd.read_csv((filepath))).fillna(0))
return x, y
def readData():
folderpath = input("Path to dataset base folder :")
global path
if folderpath == loadCommand:
path = loadCommand
else:
path = folderpath
def readDatabaseInput():
isRead = True
while isRead:
try:
readData()
X, y = getDatasetFromFile(path)
getHyperparameter(X, y)
isRead = False
except Exception as e:
print(e)
def main():
readDatabaseInput()
main()