def gaussian_naive_bayes(self): """ for gnb, i train on the training data using different : 1) var_smoothing :return: test accuracy of the gnb best model """ # define parameters # var_smoothing = np.logspace(start=-9, stop=-3, base=10, num=7, dtype=np.float32) # best result over all var_smoothing: 0.001 # scale down parameters around its best result (1st round) np.random.seed(0) scale = 0.002 loc = 0.001 var_smoothing = loc + scipy.stats.truncnorm.rvs( -loc / scale, np.infty, size=5, scale=scale) # To skip negative values # get the best validated model gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=5, var_smoothing=var_smoothing, grid_search=True) # print all possible parameter values and the best parameters # gnb.print_parameter_candidates() # gnb.print_best_estimator() # return the accuracy score return (gnb.evaluate(data=self.x_train, targets=self.y_train), gnb.evaluate(data=self.x_test, targets=self.y_test))
def gaussian_naive_bayes(self): """ for gnb, i train on the training data using different : 1) var_smoothing :return: ((accuracy_train, recall_train, precision_train), (accuracy_test, recall_test, precision_test)) """ # define parameters # var_smoothing = np.logspace(start=-9, stop=-3, base=10, num=7, dtype=np.float32) # best result over all var_smoothing: 1e-08 # scale down parameters around its best result np.random.seed(0) var_smoothing = norm.rvs(loc=1e-8, scale=1e-8, size=5).astype(np.float32) # get the best validated model gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=5, var_smoothing=var_smoothing, grid_search=True) # print all possible parameter values and the best parameters # gnb.print_parameter_candidates() # gnb.print_best_estimator() # return the accuracy score return (gnb.evaluate(data=self.x_train, targets=self.y_train), gnb.evaluate(data=self.x_test, targets=self.y_test))
def gaussian_naive_bayes(self): """ for gnb, i train on the training data using different : 1) var_smoothing :return: test accuracy of the gnb best model """ # define arguments given to GridSearchCV var_smoothing = np.logspace(start=-9, stop=-6, base=10, num=4, dtype=np.float32) # get the best validated model gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=3, n_jobs=6, var_smoothing=var_smoothing, grid_search=True) # print all possible parameter values and the best parameters # gnb.print_parameter_candidates() # gnb.print_best_estimator() # return the accuracy score return (gnb.evaluate(data=self.x_train, targets=self.y_train, average='macro'), gnb.evaluate(data=self.x_test, targets=self.y_test, average='macro'))
def gaussian_naive_bayes(self): """ for gnb, i train on the training data using different : 1) var_smoothing :return: test accuracy of the gnb best model """ # define parameters # var_smoothing = np.logspace(start=-3, stop=2, base=10, num=6, dtype=np.float32) # best result over all var_smoothing: 100.0 # scale down parameters around its best result np.random.seed(0) var_smoothing = norm.rvs(loc=100.0, scale=20, size=5).astype(np.float32) # get the best validated model gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=5, var_smoothing=var_smoothing, grid_search=True) # print all possible parameter values and the best parameters gnb.print_parameter_candidates() gnb.print_best_estimator() # return the accuracy score return gnb.accuracy_score(x_test=self.x_test, y_test=self.y_test)
def gaussian_naive_bayes(self): priors = [(1, ), (20, ), (50, ), (100, )] gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=3, n_iter=30, var_smoothing=np.logspace(start=-9, stop=-6, base=10, num=4, dtype=np.float32), grid_search=True) # print all possible parameter values and the best parameters #gnb.print_parameter_candidates() #gnb.print_best_estimator() # return the accuracy score return (gnb.evaluate(data=self.x_train, targets=self.y_train), gnb.evaluate(data=self.x_test, targets=self.y_test))
def gaussian_naive_bayes(self): var_smoothing = np.logspace(start=-9, stop=-6, base=10, num=4, dtype=np.float32) gnb = Gaussian_naive_bayes(x_train=self.x_train, y_train=self.y_train, cv=3, n_jobs=-1, var_smoothing=var_smoothing, grid_search=True) # gnb.print_parameter_candidates() # gnb.print_best_estimator() # return the accuracy score return (gnb.evaluate(data=self.x_train, targets=self.y_train, average='micro'), gnb.evaluate(data=self.x_test, targets=self.y_test, average='micro'))