Beispiel #1
0
    def _initialize_model(self):
        """
        Initialize a classifier model for the Picker object base on configuration values.
        """

        logger.info(f'Classifier model desired = {config.apple.model}')
        if config.apple.model == 'gaussian_mixture':
            from sklearn.mixture import GaussianMixture
            self.model = GaussianMixture(n_components=2)
        elif config.apple.model == 'gaussian_naive_bayes':
            from sklearn.naive_bayes import GaussianNB
            self.model = GaussianNB()
        elif config.apple.model == 'xgboost':
            import xgboost as xgb
            self.model = xgb.XGBClassifier(objective='binary:hinge',
                                           learning_rate=0.1,
                                           max_depth=6,
                                           n_estimators=10,
                                           method='gpu_hist')
        elif config.apple.model == 'thunder_svm':
            import thundersvm
            self.model = thundersvm.SVC(kernel=config.apple.svm.kernel,
                                        gamma=config.apple.svm.gamma)
        else:
            logger.info('Using SVM Classifier')
            self.model = svm.SVC(C=1,
                                 kernel=config.apple.svm_kernel,
                                 gamma=config.apple.svm_gamma,
                                 class_weight='balanced')
Beispiel #2
0
 def test_poly(self):
     self.check_jthunder(
         thundersvm.SVC(C=3, kernel="polynomial", coef0=np.pi,
                        degree=2).fit(
                            X=self.ds_train.xs,
                            y=self.ds_train.ys,
                        ))
Beispiel #3
0
    'max_iter': -1, # int, optional (default=-1) hard limit on the number of iterations within the solver, or -1 for no limit.
    'n_jobs': -1, # int, optional (default=-1) set the number of cpu cores to use, or -1 for maximum.
    'max_mem_size': -1, # int, optional (default=-1) set the maximum memory size (MB) that thundersvm uses, or -1 for no limit.
    'class_weight': dataset.weight_per_class,  #{dict}, optional(default=None) set the parameter C of class i to weight*C, for C-SVC
    'kernel': 'linear', # string, optional(default='rbf') set type of kernel function 'linear': u'*v 'polynomial': (gamma*u'*v + coef0)^degree 'rbf': exp(-gamma*|u-v|^2) 'sigmoid': tanh(gamma*u'*v + coef0) 'precomputed' -- precomputed kernel (kernel values in training_set_file)
    'degree': 3, # int, optional(default=3) set degree in kernel function
    'gamma': 'auto', # float, optional(default='auto') set gamma in kernel function (auto:1/num_features)
    'coef0': 0.0, # float, optional(default=0.0) set coef0 in kernel function
    'C': 100.0, # optional(default=1.0) set the parameter C of C-SVC, epsilon-SVR, and nu-SVR
    'tol': 0.1, # float, optional(default=0.001) set tolerance of termination criterion (default 0.001)
    'probability': False, # boolean, optional(default=False) whether to train a SVC or SVR model for probability estimates, True or False
    'shrinking': False, # boolean, optional (default=False, not supported yet for True) whether to use the shrinking heuristic.
    'decision_function_shape': 'ovr' # ‘ovo’, default=’ovo’, not supported yet for 'ovr' only for classifier. Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2).
    }

model = thundersvm.SVC(**model_parameters)
#model = BaggingClassifier(verbose = 1,base_estimator=modeld, n_estimators=8, max_samples = 1 / 8, bootstrap=False, n_jobs=-1, random_state=42)
# Training
print('Training...')
start_time = time.time()
model.fit(
    X=dataset.X_train.values,
    y=dataset.y_train.values)

elapsed_time_training = time.time() - start_time

# Predicting
print('Predicting...')
start_time = time.time()
y_pred = model.predict(dataset.X_test.values)
elapsed_time_testing = time.time() - start_time
Beispiel #4
0
 def test_rbf(self):
     self.check_jthunder(
         thundersvm.SVC(C=3, kernel="rbf").fit(
             X=self.ds_train.xs,
             y=self.ds_train.ys,
         ))
Beispiel #5
0
 def test_linear(self):
     self.check_jthunder(
         thundersvm.SVC(C=3, kernel="linear").fit(
             X=self.ds_train.xs,
             y=self.ds_train.ys,
         ))