def __init__(self, coef=None, intercept=None, order=4, cross=0, colspec={}, random_state=4321): """ The first to arguments are here to make interface consistent with LogisiticScorer: ceof - feature coeficients to initialize the model with intercept - intercept value to initialize the model with order - maximum order of polynomial terms cross - maximum order of cross terms (2 is minimum for any effect) colspec - specification of what cols to use Note that this uses only cross terms from two features at a time. """ LogisticRegression.__init__(self, random_state=random_state) assert order >= 2, "order must be at least 2" self.order = order self.cross = cross self.colspec = vessel_scoring.colspec.Colspec(**colspec) if coef is not None: self.coef_ = np.array(coef) if intercept is not None: self.intercept_ = np.array(intercept)
def __init__(self, penalty='l2', dual=False, tol=1e-4, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='liblinear', max_iter=100, multi_class='ovr', verbose=0, warm_start=False, n_jobs=1): LogisticRegression.__init__(self, penalty=penalty, dual=dual, tol=tol, C=C, fit_intercept=fit_intercept, intercept_scaling=intercept_scaling, class_weight=class_weight, random_state=random_state, solver=solver, max_iter=max_iter, multi_class=multi_class, verbose=verbose, warm_start=warm_start, n_jobs=n_jobs)
def __init__(self, fnames=None, ffilter=None, **kwargs): LogisticRegression.__init__(self, **kwargs) self.fnames = fnames self.ffilter = ffilter self.kept_features = None if self.fnames and self.ffilter: self.kept_features = np.array( [bool(re.match(self.ffilter, c)) for c in self.fnames])
def __init__(self, C=1.0, solver='lbfgs', max_iter=100, X_train=None, y_train=None): LogisticRegression.__init__(self, C=C, solver=solver, max_iter=max_iter) self.X_train = X_train self.y_train = y_train
def __init__(self, penalty='l2', C=1.0, fit_intercept=True, *args, **kwargs) -> pd.Series: LogisticRegression.__init__(self, penalty=penalty, C=C, fit_intercept=fit_intercept, *args, **kwargs)
def __init__(self, C=1.0, solver='liblinear', max_iter=100, acc_out=None, summ=None): LogisticRegression.__init__(self, C=C, solver=solver, max_iter=max_iter) self.acc_out = acc_out self.summ = summ
def __init__(self, pmml): PMMLBaseClassifier.__init__(self, pmml) OneHotEncodingMixin.__init__(self) LogisticRegression.__init__(self) # Import coefficients and intercepts model = self.root.find('RegressionModel') mining_model = self.root.find('MiningModel') tables = [] if mining_model is not None and self.n_classes_ > 2: self.multi_class = 'ovr' segmentation = mining_model.find('Segmentation') if segmentation.get('multipleModelMethod') not in ['modelChain']: raise Exception('PMML model for multi-class logistic regression should use modelChain method.') # Parse segments segments = segmentation.findall('Segment') valid_segments = [segment for segment in segments if segment.find('True') is not None] models = [segment.find('RegressionModel') for segment in valid_segments] tables = [ models[i].find('RegressionTable') for i in range(self.n_classes_) ] elif model is not None: self.multi_class = 'auto' tables = [ table for table in model.findall('RegressionTable') if table.find('NumericPredictor') is not None ] else: raise Exception('PMML model does not contain RegressionModel or Segmentation.') self.coef_ = [ _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_) self.solver = 'lbfgs'
def __init__(self, threshold=0.01, dual=False, tol=1e-4, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='liblinear', max_iter=100, multi_class='ovr', verbose=0, warm_start=False, n_jobs=1): #权值相近的阈值 self.threshold = threshold LogisticRegression.__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, solver=solver, max_iter=max_iter, multi_class=multi_class, verbose=verbose, warm_start=warm_start, n_jobs=n_jobs) #使用同样的参数创建L2逻辑回归 self.l2 = LogisticRegression(penalty='l2', dual=dual, tol=tol, C=C, fit_intercept=fit_intercept, intercept_scaling=intercept_scaling, class_weight = class_weight, random_state=random_state, solver=solver, max_iter=max_iter, multi_class=multi_class, verbose=verbose, warm_start=warm_start, n_jobs=n_jobs)
def __init__(self, c=1.0, solver="newton-cg", multi_class="multimonial", max_iter=100, X_train=none, Y_train=None): LogisticRegression.__init__(self, c=c, solver=solver, multi_class=multi_class, max_iter=max_iter) self.X_train = X_train self.Y_train = Y_train
def __init__(self, imbalance_upsampling=None, class_weight=None, method=None, c=100.0, random_state=1, log=None): """ Initialize the model :param imbalance_upsampling: Using upsampling to compensate imbalanced dataset :param class_weight: It can be None, "balanced", or a dict. Used for imbalance class :param method: Optional ensemble method :param c: Not supported yet. :param random_state: Random state :param log: log """ self.c = c self.random_state = random_state MlModelCommon.__init__(self, imbalance_upsampling=imbalance_upsampling, class_weight=class_weight, method=method, log=log) if method == "Bagging": model = LgRegression(C=c, class_weight=class_weight, random_state=random_state) self.ensemble_method = BaggingClassifier(base_estimator=model, n_estimators=200, random_state=random_state) elif method == "Adaptive Boosting": model = LgRegression(C=c, class_weight=class_weight, random_state=random_state) self.ensemble_method = AdaBoostClassifier( base_estimator=model, n_estimators=200, random_state=random_state) else: self.ensemble_method = None LgRegression.__init__(self, C=c, random_state=random_state, class_weight=class_weight)
def __init__(self): # Using default parameters for now # Class weight LogisticRegression.__init__( self, penalty='l2', dual=False, tol=1e-4, C=0.908918018018018, fit_intercept=False, intercept_scaling=1, class_weight=None, random_state=100, solver='saga', max_iter=2000, multi_class='multinomial', verbose=0, warm_start=False, n_jobs=1, ) self.name = 'LR'
def __init__(self): LogisticRegression.__init__(self)
'''
def __init__(self): """ constructor """ LogisticRegression.__init__(self, solver='liblinear')
col = [] correct_predictions = 0 for i in range(0, len(y_pred)): if y_pred[i] == y[i]: correct_predictions += 1 if y_pred[i] == -1: col.append('#FFFF00') else: col.append('#00FFFF') accuracy = correct_predictions / len(y_pred) print("initial accuracy", accuracy) #partB model = LinearSVC() model.__init__(C=0.001) model.fit(X_transform, y) print("model C=0.001", model.coef_, model.intercept_) model1 = {"intercept": model.intercept_, "coef": model.coef_} model.__init__(C=0.1) model.fit(X_transform, y) print("model C=0.1", model.coef_, model.intercept_) model2 = {"intercept": model.intercept_, "coef": model.coef_} model.__init__(C=10) model.fit(X_transform, y) print("model C=10", model.coef_, model.intercept_) model3 = {"intercept": model.intercept_, "coef": model.coef_} model.__init__(