def create_learner(self): alpha = self.alphas[self.alpha_index] preprocessors = self.preprocessors args = {"preprocessors": preprocessors} if self.reg_type == OWLinearRegression.OLS: learner = LinearRegressionLearner(**args) elif self.reg_type == OWLinearRegression.Ridge: learner = RidgeRegressionLearner(alpha=alpha, **args) elif self.reg_type == OWLinearRegression.Lasso: learner = LassoRegressionLearner(alpha=alpha, **args) elif self.reg_type == OWLinearRegression.Elastic: learner = ElasticNetLearner(alpha=alpha, l1_ratio=1 - self.l2_ratio, **args) return learner
def commit(self): alpha = self.alphas[self.alpha_index] preprocessors = self.preprocessors args = {"preprocessors": preprocessors} if self.reg_type == OWLinearRegression.OLS: learner = LinearRegressionLearner(**args) elif self.reg_type == OWLinearRegression.Ridge: learner = RidgeRegressionLearner(alpha=alpha, **args) elif self.reg_type == OWLinearRegression.Lasso: learner = LassoRegressionLearner(alpha=alpha, **args) elif self.reg_type == OWLinearRegression.Elastic: learner = ElasticNetLearner(alpha=alpha, l1_ratio=self.l1_ratio, **args) learner.name = self.learner_name predictor = None coef_table = None self.error(0) if self.data is not None: if not learner.check_learner_adequacy(self.data.domain): self.error(0, learner.learner_adequacy_err_msg) else: predictor = learner(self.data) predictor.name = self.learner_name domain = Domain( [ContinuousVariable("coef", number_of_decimals=7)], metas=[StringVariable("name")]) coefs = [predictor.intercept] + list(predictor.coefficients) names = ["intercept"] + \ [attr.name for attr in predictor.domain.attributes] coef_table = Table(domain, list(zip(coefs, names))) coef_table.name = "coefficients" self.send("Linear Regression", learner) self.send("Model", predictor) self.send("Coefficients", coef_table)