11
2+ import random
23import warnings
34warnings .filterwarnings ('ignore' )
45
1516from sklearn .naive_bayes import GaussianNB
1617from sklearn .neural_network import MLPClassifier
1718from sklearn .tree import DecisionTreeClassifier
19+ from sklearn .model_selection import ParameterSampler
1820
1921from sklearn .ensemble import AdaBoostRegressor , ExtraTreesRegressor , RandomForestRegressor
2022from sklearn .tree import DecisionTreeRegressor
@@ -178,6 +180,11 @@ def run_all_classifiers(x, y, small = True, normalize_x = True, n_jobs=cpu_count
178180 all_params = (linear_models_n_params_small if small else linear_models_n_params ) + (nn_models_n_params_small if small else nn_models_n_params ) + ([] if small else gaussianprocess_models_n_params ) + neighbor_models_n_params + (svm_models_n_params_small if small else svm_models_n_params ) + (tree_models_n_params_small if small else tree_models_n_params )
179181 return main_loop (all_params , StandardScaler ().fit_transform (x ) if normalize_x else x , y , isClassification = True , n_jobs = n_jobs , verbose = verbose , brain = brain , test_size = test_size , n_splits = n_splits , upsample = upsample , scoring = scoring , grid_search = grid_search )
180182
183+ def run_one_classifier (x , y , small = True , normalize_x = True , n_jobs = cpu_count ()- 1 , brain = False , test_size = 0.2 , n_splits = 5 , upsample = True , scoring = None , verbose = False , grid_search = True ):
184+ all_params = (linear_models_n_params_small if small else linear_models_n_params ) + (nn_models_n_params_small if small else nn_models_n_params ) + ([] if small else gaussianprocess_models_n_params ) + neighbor_models_n_params + (svm_models_n_params_small if small else svm_models_n_params ) + (tree_models_n_params_small if small else tree_models_n_params )
185+ all_params = random .choice (all_params )
186+ return all_params [0 ](** (list (ParameterSampler (all_params [1 ], n_iter = 1 ))[0 ]))
187+
181188
182189class HungaBungaClassifier (ClassifierMixin ):
183190 def __init__ (self , brain = False , test_size = 0.2 , n_splits = 5 , random_state = None , upsample = True , scoring = None , verbose = False , normalize_x = True , n_jobs = cpu_count () - 1 , grid_search = True ):
@@ -202,6 +209,30 @@ def predict(self, x):
202209 return self .model .predict (x )
203210
204211
212+ class HungaBungaRandomClassifier (ClassifierMixin ):
213+ def __init__ (self , brain = False , test_size = 0.2 , n_splits = 5 , random_state = None , upsample = True , scoring = None , verbose = False , normalize_x = True , n_jobs = cpu_count () - 1 , grid_search = True ):
214+ self .model = None
215+ self .brain = brain
216+ self .test_size = test_size
217+ self .n_splits = n_splits
218+ self .random_state = random_state
219+ self .upsample = upsample
220+ self .scoring = None
221+ self .verbose = verbose
222+ self .n_jobs = n_jobs
223+ self .normalize_x = normalize_x
224+ self .grid_search = grid_search
225+ super (HungaBungaRandomClassifier , self ).__init__ ()
226+
227+ def fit (self , x , y ):
228+ self .model = run_one_classifier (x , y , normalize_x = self .normalize_x , test_size = self .test_size , n_splits = self .n_splits , upsample = self .upsample , scoring = self .scoring , verbose = self .verbose , brain = self .brain , n_jobs = self .n_jobs , grid_search = self .grid_search )
229+ self .model .fit (x , y )
230+ return self
231+
232+ def predict (self , x ):
233+ return self .model .predict (x )
234+
235+
205236if __name__ == '__main__' :
206237 iris = datasets .load_iris ()
207238 X , y = iris .data , iris .target
0 commit comments