nbsvm/nbsvm.py
def fit(self, X, y):
        "Fit the NBSVM model according to the given training data."
        X_binarized = X.copy()
        X_binarized = self._binarize(X_binarized)
        self._log_probs(X_binarized, y)
        del X_binarized
        X_nb = X*self.r
        svm = SVC(C=self.C, kernel='linear', class_weight=self.class_weight)
        svm.fit(X_nb, y)
        self.coef_ = svm.coef_
        self.intercept_ = svm.intercept_
        self.interpolated_coef_ = self._interpolate(svm.coef_)
        self.interpolated_intercept_ = self._interpolate(svm.intercept_)
        self.model = svm
        if self.probability:
            n_tot = len(y[y==0])
            p_tot = len(y[y==1])
            n_tar = 1/(n_tot + 2)
            p_tar = (p_tot + 1)/(p_tot + 2)
            self.platt_model_['n_tar'] = n_tar
            self.platt_model_['p_tar'] = p_tar
            model = LogisticRegressionUsingGD()
            dec_fn = self.decision_function(X)
            self.platt_model_['costs'] = model.fit(dec_fn, self._y_to_t(y))
            self.platt_model_['model'] = model
        return self
Fit the NBSVM model according to the given training data.
Fit the NBSVM model according to the given training data.
Fit the NBSVM model according to the given training data .
def fit(self, X, y):
        X_binarized = X.copy()
        X_binarized = self._binarize(X_binarized)
        self._log_probs(X_binarized, y)
        del X_binarized
        X_nb = X*self.r
        svm = SVC(C=self.C, kernel='linear', class_weight=self.class_weight)
        svm.fit(X_nb, y)
        self.coef_ = svm.coef_
        self.intercept_ = svm.intercept_
        self.interpolated_coef_ = self._interpolate(svm.coef_)
        self.interpolated_intercept_ = self._interpolate(svm.intercept_)
        self.model = svm
        if self.probability:
            n_tot = len(y[y==0])
            p_tot = len(y[y==1])
            n_tar = 1/(n_tot + 2)
            p_tar = (p_tot + 1)/(p_tot + 2)
            self.platt_model_['n_tar'] = n_tar
            self.platt_model_['p_tar'] = p_tar
            model = LogisticRegressionUsingGD()
            dec_fn = self.decision_function(X)
            self.platt_model_['costs'] = model.fit(dec_fn, self._y_to_t(y))
            self.platt_model_['model'] = model
        return self
def fit ( self , X , y ) : X_binarized = X . copy ( ) X_binarized = self . _binarize ( X_binarized ) self . _log_probs ( X_binarized , y ) del X_binarized X_nb = X * self . r svm = SVC ( C = self . C , kernel = 'linear' , class_weight = self . class_weight ) svm . fit ( X_nb , y ) self . coef_ = svm . coef_ self . intercept_ = svm . intercept_ self . interpolated_coef_ = self . _interpolate ( svm . coef_ ) self . interpolated_intercept_ = self . _interpolate ( svm . intercept_ ) self . model = svm if self . probability : n_tot = len ( y [ y == 0 ] ) p_tot = len ( y [ y == 1 ] ) n_tar = 1 / ( n_tot + 2 ) p_tar = ( p_tot + 1 ) / ( p_tot + 2 ) self . platt_model_ [ 'n_tar' ] = n_tar self . platt_model_ [ 'p_tar' ] = p_tar model = LogisticRegressionUsingGD ( ) dec_fn = self . decision_function ( X ) self . platt_model_ [ 'costs' ] = model . fit ( dec_fn , self . _y_to_t ( y ) ) self . platt_model_ [ 'model' ] = model return self
Fit the NBSVM model according to the given training data.
Fit the NBSVM model according to the given training data .
"Fit the NBSVM model according to the given training data."
self
X
y