forked from shubhampachori12110095/DFLsklearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_funct_interfaces.py
More file actions
110 lines (88 loc) · 3.83 KB
/
custom_funct_interfaces.py
File metadata and controls
110 lines (88 loc) · 3.83 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 11:26:32 2017
@authors: V. Latorre, F. Benvenuto
"""
import sklearn
from DFLsklearn import KFold_error
def interface_funct(model_f,z):
global X_values,Y_values,n_splits, base_exp,algo, hp_list,has_no_space,var_is_int,space_points,hp_space
'''
Some custom model functs, as examples to implement in the case the user
wants to implement some custom interfaces between sklearn and DFL
'''
if(type(model_f) is sklearn.linear_model.ElasticNet):
model_f.alpha=base_exp**z[0]+base_exp**z[1]
model_f.l1_ratio=(base_exp**z[0])/(base_exp**z[0]+base_exp**z[1])
return KFold_error()
if(type(model_f) is sklearn.linear_model.MultiTaskElasticNet):
model_f.alpha=base_exp**z[0]+base_exp**z[1]
model_f.l1_ratio=(base_exp**z[0])/(base_exp**z[0]+base_exp**z[1])
return KFold_error()
if(type(model_f) is sklearn.linear_model.BayesianRidge):
model_f.alpha_1=base_exp**z[0]
model_f.alpha_2=base_exp**z[1]
model_f.lambda_1=base_exp**z[2]
model_f.lambda_2=base_exp**z[3]
return KFold_error()
if(type(model_f) is sklearn.linear_model.ARDRegression):
model_f.alpha_1=base_exp**z[0]
model_f.alpha_2=base_exp**z[1]
model_f.lambda_1=base_exp**z[2]
model_f.lambda_2=base_exp**z[3]
return KFold_error()
if(type(model_f) is sklearn.neural_network.MLPRegressor):
model_f.hidden_layer_sizes=tuple(z[0:len(z)-1].astype(int))
model_f.alpha=base_exp**z[len(z)-1]
return KFold_error()
if(type(model_f) is sklearn.svm.SVC):
model_f.C=base_exp**z[0]
model_f.gamma=base_exp**z[1]
return KFold_error(errortype="classification")
if(type(model_f) is sklearn.svm.SVR):
model_f.C=base_exp**z[0]
model_f.gamma=base_exp**z[1]
model_f.epsilon=base_exp**z[2]
return KFold_error()
if(type(model_f) is sklearn.svm.LinearSVC):
model_f.c=base_exp**z[0]
return KFold_error(errortype="classification")
if(type(model_f) is sklearn.svm.NuSVC):
model_f.nu=z[0]
model_f.gamma=base_exp**z[1]
return KFold_error(errortype="classification")
if(type(model_f) is sklearn.svm.LinearSVR):
model_f.C=base_exp**z[0]
return KFold_error()
if(type(model_f) is sklearn.svm.NuSVR):
model_f.nu=z[0]
model_f.gamma=base_exp**z[1]
model_f.epsilon=base_exp**z[2]
return KFold_error()
if(type(model_f) is sklearn.neural_network.MLPClassifier):
model_f.hidden_layer_sizes=tuple(z[0:len(z)-1].astype(int))
model_f.alpha=base_exp**z[len(z)-1]
return KFold_error(errortype="classification")
if(type(model_f) is sklearn.ensemble.RandomForestClassifier):
model_f.max_features=int(z[0])
model_f.min_samples_split=int(base_exp**z[1])
model_f.min_samples_leaf=int(base_exp**z[2])
model_f.max_depth=int(base_exp**z[3])
model_f.n_estimators=int(base_exp**z[4])
return KFold_error(errortype="classification")
if(type(model_f) is sklearn.ensemble.RandomForestRegressor):
model_f.max_features=int(z[0])
model_f.min_samples_split=int(base_exp**z[1])
model_f.min_samples_leaf=int(base_exp**z[2])
model_f.max_depth=int(base_exp**z[3])
model_f.n_estimators=int(base_exp**z[4])
return set_error()
if(type(model_f) is sklearn.linear_model.Lasso):
model_f.alpha=base_exp**z[0]
return KFold_error()
if(type(model_f) is R_flarecast_learning_algorithms.R_nn):
algo.parameters['R_nn']['size']=z[0]
algo.estimator=R_flarecast_learning_algorithms.R_nn(**algo.parameters)
model_f=algo.estimator
return KFold_error()