def find_best_params(self,validation_data_x,validation_data_y,n_jobs=1,params=[]): if not params: params = self.get_default_param_grid() merged_x = Data.merge_arrays(self.training_data_x, validation_data_x) merged_y = Data.merge_arrays(self.training_data_y, validation_data_y) test_fold = [] for i in range(0,len(self.training_data_y)): test_fold.append(1) for i in range(0,len(validation_data_y)): test_fold.append(0) cv = PredefinedSplit(test_fold) gs = GridSearchCV( estimator=GaussianNB(), scoring='f1_micro', param_grid=params, n_jobs=n_jobs, cv=cv ) gs.fit(merged_x,merged_y) best_params = gs.best_params_ results = gs.cv_results_ return best_params,results
def find_best_params(self,validation_data_x,validation_data_y,alpha_vals,n_jobs=1): merged_x = Data.merge_arrays(self.training_data_x, validation_data_x) merged_y = Data.merge_arrays(self.training_data_y, validation_data_y) test_fold = [] for i in range(0,len(self.training_data_y)): test_fold.append(1) for i in range(0,len(validation_data_y)): test_fold.append(0) cv = PredefinedSplit(test_fold) param = {"alpha": alpha_vals} gs = GridSearchCV( estimator=BernoulliNB(), scoring='f1_micro', param_grid=param, n_jobs=n_jobs, cv=cv ) gs.fit(merged_x,merged_y) best_params = gs.best_params_ results = gs.cv_results_ return best_params,results