Esempio n. 1
0
    def __init__(self, pmml):
        PMMLBaseClassifier.__init__(self, pmml)
        OneHotEncodingMixin.__init__(self)
        LinearSVC.__init__(self)

        # Import coefficients and intercepts
        model = self.root.find('RegressionModel')

        if model is None:
            raise Exception('PMML model does not contain RegressionModel.')

        tables = [
            table for table in model.findall('RegressionTable')
            if table.find('NumericPredictor') is not None
        ]

        self.coef_ = [
            _linear_get_coefficients(self, table) for table in tables
        ]
        self.intercept_ = [float(table.get('intercept')) for table in tables]

        if len(self.coef_) == 1:
            self.coef_ = [self.coef_[0]]

        if len(self.intercept_) == 1:
            self.intercept_ = [self.intercept_[0]]

        self.coef_ = np.array(self.coef_)
        self.intercept_ = np.array(self.intercept_)
class RandomSVM(ActiveLearning):
    def __init__(self, X_train, y_train, X_test, y_test):
        super().__init__(X_train, y_train, X_test, y_test)
        self.model = LinearSVC()

    def init_model(self):
        y_labeled = self.y_train[self.unlabeled_msk==False]
        self.model.__init__(class_weight='balanced')

    def get_next(self):
        idx = np.random.choice(self.X_train.index[self.unlabeled_msk], 1)[0]
        return idx
Esempio n. 3
0
    def __init__(self,
                 penalty='l2',
                 loss='squared_hinge',
                 dual=True,
                 tol=1e-4,
                 C=1.0,
                 multi_class='ovr',
                 fit_intercept=True,
                 intercept_scaling=1,
                 class_weight=None,
                 verbose=0,
                 random_state=None,
                 max_iter=1000):
        _skLinearSVC.__init__(self, penalty, loss, dual, tol, C, multi_class,
                              fit_intercept, intercept_scaling, class_weight,
                              verbose, random_state, max_iter)

        BaseWrapperClf.__init__(self)
Esempio n. 4
0
 def __init__(self,
              threshold=0.01,
              dual=False,
              tol=1e-4,
              C=0.01,
              fit_intercept=True,
              intercept_scaling=1,
              class_weight=None,
              random_state=0,
              max_iter=100,
              multi_class='ovr',
              verbose=0):
     self.threshold = threshold
     LinearSVC.__init__(self,
                        penalty='l1',
                        dual=dual,
                        tol=tol,
                        C=C,
                        fit_intercept=fit_intercept,
                        intercept_scaling=intercept_scaling,
                        class_weight=class_weight,
                        random_state=random_state,
                        max_iter=max_iter,
                        multi_class=multi_class,
                        verbose=verbose)
     # 使用同样的参数创建L2逻辑回归
     self.l2 = LinearSVC(penalty='l2',
                         dual=dual,
                         tol=tol,
                         C=C,
                         fit_intercept=fit_intercept,
                         intercept_scaling=intercept_scaling,
                         class_weight=class_weight,
                         random_state=random_state,
                         max_iter=max_iter,
                         multi_class=multi_class,
                         verbose=verbose)
Esempio n. 5
0
 def __init__(self, penalty='l2', loss='squared_hinge', dual=True, tol=0.0001, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, class_weight=None, verbose=0, random_state=None, max_iter=1000):
     LinearSVC.__init__(self, penalty, loss, dual, tol, C, multi_class, fit_intercept, intercept_scaling, class_weight, verbose, random_state, max_iter)