Beispiel #1
0
    def __init__(self, indim: int, outdim: int, order: int, default=0.,\
        tol: float=1e-3, random_state: Union[int, RandomState] = None, **kwargs):

        self.indim = indim
        self.outdim = outdim
        self.default = default
        self.order = order

        self.transformer = PolynomialFeatures(degree=order, include_bias=False)
        # self.powers = np.arange(1, self.order + 1)[:, None]

        kwargs['random_state'] = random_state  # to be passed to SGDRegressor
        kwargs['fit_intercept'] = True  # learn bias term for polynomial
        n_features = len(self._project(np.zeros((1, indim)))[0])
        self.models = []
        for _ in range(outdim):
            model = SGDRegressor(tol=tol, **kwargs)
            # SGDRegressor does not assign weight arrays until the first call
            # to 'fit()'. Allocating them early so the weights property is
            # accessible from the get-go. One initialized, they won't be reset
            # by the model.
            model._allocate_parameter_mem(n_classes=outdim,
                                          n_features=n_features)
            self.models.append(model)