class CrossSectionalModelLasso(CrossSectionalModelBase): def fit(self, X, y, **kwargs): if self.fit_intercept: X = sm.add_constant(X) try: self.alpha = kwargs['alpha'] except: raise Exception( 'cannot find alpha! please set the penalty of Lasso') else: self.model = OLS(y, X) self.res = self.model.fit_regularized(alpha=self.alpha, L1_wt=1, **kwargs)
class CrossSectionalModelRidge(CrossSectionalModelLinear): def __init__(self, jsonPath=None, paraDict={}): self.parameter = paraDict if jsonPath is not None: with open(jsonPath, 'r') as f: self.parameter = json.loads(f) self.fit_intercept = self.parameter.get('fit_intercept', True) self.model = None def fit(self, X, y, **kwargs): if self.fit_intercept: X = sm.add_constant(X) try: self.alpha = self.parameter['alpha'] except: raise Exception( 'cannot find alpha! please set the penalty of Ridge') else: self.model = OLS(y, X) self.res = self.model.fit_regularized(alpha=self.alpha, L1_wt=0, **kwargs)