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
Beispiel #2
0
    def commit(self):
        alpha = self.alphas[self.alpha_index]
        preprocessors = self.preprocessors
        if self.data is not None and np.isnan(self.data.Y).any():
            self.warning(0, "Missing values of target variable(s)")
            if not self.preprocessors:
                if self.reg_type == OWLinearRegression.OLS:
                    preprocessors = LinearRegressionLearner.preprocessors
                elif self.reg_type == OWLinearRegression.Ridge:
                    preprocessors = RidgeRegressionLearner.preprocessors
                else:
                    preprocessors = LassoRegressionLearner.preprocessors
            else:
                preprocessors = list(self.preprocessors)
            preprocessors.append(RemoveNaNClasses())
        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)

        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)
Beispiel #3
0
    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)
Beispiel #4
0
    def commit(self):
        alpha = self.alphas[self.alpha_index]
        args = {"preprocessors": self.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)

        learner.name = self.learner_name
        predictor = 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

        self.send("Learner", learner)
        self.send("Predictor", predictor)
Beispiel #5
0
            if hasattr(model, "model"):
                model = model.model
            elif hasattr(model, "skl_model"):
                model = model.skl_model
        if model is not None and hasattr(model, "coef_"):
            domain = Domain([ContinuousVariable("coef", number_of_decimals=7)],
                            metas=[StringVariable("name")])
            coefs = [model.intercept_ + model.coef_[0]] + list(model.coef_[1:])
            names = ["1", x_label] + \
                    ["{}^{}".format(x_label, i) for i in range(2, degree + 1)]
            coef_table = Table(domain, list(zip(coefs, names)))
            self.send("Coefficients", coef_table)
        else:
            self.send("Coefficients", None)


if __name__ == "__main__":
    import sys
    from AnyQt.QtWidgets import QApplication

    a = QApplication(sys.argv)
    ow = OWUnivariateRegression()
    learner = RidgeRegressionLearner(alpha=1.0)
    polylearner = PolynomialLearner(learner, degree=2)
    d = Table('iris')
    ow.set_data(d)
    ow.set_learner(learner)
    ow.show()
    a.exec_()
    ow.saveSettings()