Пример #1
0
class LassoLarsICImpl():
    def __init__(self,
                 criterion='aic',
                 fit_intercept=True,
                 verbose=False,
                 normalize=True,
                 precompute='auto',
                 max_iter=500,
                 eps=2.220446049250313e-16,
                 copy_X=True,
                 positive=False):
        self._hyperparams = {
            'criterion': criterion,
            'fit_intercept': fit_intercept,
            'verbose': verbose,
            'normalize': normalize,
            'precompute': precompute,
            'max_iter': max_iter,
            'eps': eps,
            'copy_X': copy_X,
            'positive': positive
        }
        self._wrapped_model = Op(**self._hyperparams)

    def fit(self, X, y=None):
        if (y is not None):
            self._wrapped_model.fit(X, y)
        else:
            self._wrapped_model.fit(X)
        return self

    def predict(self, X):
        return self._wrapped_model.predict(X)
Пример #2
0
def test_lasso_lars_fit_copyX_behaviour(copy_X):
    """
    Test that user input to .fit for copy_X overrides default __init__ value

    """
    lasso_lars = LassoLarsIC(precompute=False)
    rng = np.random.RandomState(0)
    X = rng.normal(0, 1, (100, 5))
    X_copy = X.copy()
    y = X[:, 2]
    lasso_lars.fit(X, y, copy_X=copy_X)
    assert copy_X == np.array_equal(X, X_copy)
Пример #3
0
def test_lasso_lars_fit_copyX_behaviour(copy_X):
    """
    Test that user input to .fit for copy_X overrides default __init__ value

    """
    lasso_lars = LassoLarsIC(precompute=False)
    rng = np.random.RandomState(0)
    X = rng.normal(0, 1, (100, 5))
    X_copy = X.copy()
    y = X[:, 2]
    lasso_lars.fit(X, y, copy_X=copy_X)
    assert copy_X == np.array_equal(X, X_copy)
Пример #4
0
def test_lasso_lars_copyX_behaviour(copy_X):
    """
    Test that user input regarding copy_X is not being overridden (it was until
    at least version 0.21)

    """
    lasso_lars = LassoLarsIC(copy_X=copy_X, precompute=False)
    rng = np.random.RandomState(0)
    X = rng.normal(0, 1, (100, 5))
    X_copy = X.copy()
    y = X[:, 2]
    lasso_lars.fit(X, y)
    assert copy_X == np.array_equal(X, X_copy)
 def _make_estimator_and_params(self, X, y):
     assert self.precompute in (True, False, None, 'auto')
     alpha = self.alpha
     if isinstance(alpha, six.string_types) and alpha in ('aic', 'bic'):
         model = LassoLarsIC(precompute=self.precompute,
                             criterion=self.alpha,
                             max_iter=self.max_iter,
                             eps=self.eps)
         model.fit(X, y)
         self.alpha_ = alpha = model.alpha_
     return _randomized_lasso, dict(alpha=alpha, max_iter=self.max_iter,
                                    eps=self.eps,
                                    precompute=self.precompute)
Пример #6
0
def test_lasso_lars_copyX_behaviour(copy_X):
    """
    Test that user input regarding copy_X is not being overridden (it was until
    at least version 0.21)

    """
    lasso_lars = LassoLarsIC(copy_X=copy_X, precompute=False)
    rng = np.random.RandomState(0)
    X = rng.normal(0, 1, (100, 5))
    X_copy = X.copy()
    y = X[:, 2]
    lasso_lars.fit(X, y)
    assert copy_X == np.array_equal(X, X_copy)
Пример #7
0
 def fit(self, X, y=None):
     self._sklearn_model = SKLModel(**self._hyperparams)
     if (y is not None):
         self._sklearn_model.fit(X, y)
     else:
         self._sklearn_model.fit(X)
     return self
Пример #8
0
    def connectWidgets(self):
        # LassoLARS
        ll = LassoLars()
        self.alpha_text.setText(str(ll.alpha))
        self.fit_interceptCheckBox.setChecked(ll.fit_intercept)
        self.verboseCheckBox.setChecked(ll.verbose)
        self.normalizeCheckBox.setChecked(ll.normalize)
        self.setComboBox(self.precomputeComboBox,
                         ['True', 'False', 'auto', 'array-like'])
        self.defaultComboItem(self.precomputeComboBox, ll.precompute)
        self.max_iterSpinBox.setValue(ll.max_iter)
        self.copy_XCheckBox.setChecked(ll.copy_X)
        self.fit_pathCheckBox.setChecked(ll.fit_path)
        self.positiveCheckBox.setChecked(ll.positive)

        # LassoLarsCV
        llcv = LassoLarsCV()
        self.max_n_alphasSpinBox.setValue(llcv.max_n_alphas)
        self.n_jobsSpinBox.setValue(llcv.n_jobs)

        # LassoLarsIC
        llic = LassoLarsIC()
        self.cvSpinBox.setValue(3)
        self.setComboBox(self.criterionComboBox, ['aic', 'bic'])
        self.defaultComboItem(self.criterionComboBox, llic.criterion)
Пример #9
0
    def _make_estimator_and_params(self, X, y):
        alpha = self.alpha
        if isinstance(alpha, six.string_types) and alpha in ('aic', 'bic'):
            model = LassoLarsIC(precompute=self.precompute,
                                criterion=self.alpha,
                                max_iter=self.max_iter,
                                eps=self.eps)
            model.fit(X, y)
            self.alpha_ = alpha = model.alpha_

        precompute = self.precompute
        # A precomputed Gram array is useless, since _randomized_lasso
        # change X a each iteration
        if hasattr(precompute, '__array__'):
            precompute = 'auto'
        assert precompute in (True, False, None, 'auto')
        return _randomized_lasso, dict(alpha=alpha, max_iter=self.max_iter,
                                       eps=self.eps,
                                       precompute=precompute)
Пример #10
0
    def function(self):
        model = self.modelComboBox.currentIndex()
        if model == 0:
            params = {
                'alpha': self.alpha_text.text(),
                'fit_intercept': self.fit_interceptCheckBox.isChecked(),
                'verbose': self.fit_interceptCheckBox.isChecked(),
                'normalize': self.normalizeCheckBox.isChecked(),
                'precompute': self.precomputeComboBox.currentText(),
                'max_iter': self.max_iterSpinBox.value(),
                'copy_X': self.copy_XCheckBox.isChecked(),
                'fit_path': self.fit_pathCheckBox.isChecked(),
                'positive': self.positiveCheckBox.isChecked(),
                'model': model
            }
            params_check = dict(params)
            params_check.pop('model')
            return params, self.getChangedValues(params_check, LassoLars())

        elif model == 1:
            params = {
                'fit_intercept': self.fit_interceptCheckBox.isChecked(),
                'verbose': self.fit_interceptCheckBox.isChecked(),
                'max_iter': self.max_iterSpinBox.value(),
                'normalize': self.normalizeCheckBox.isChecked(),
                'precompute': self.precomputeComboBox.currentText(),
                'cv': self.cvSpinBox.value(),
                'max_n_alphas': self.max_n_alphasSpinBox.value(),
                'n_jobs': self.n_jobsSpinBox.value(),
                'copy_X': self.copy_XCheckBox.isChecked(),
                'positive': self.positiveCheckBox.isChecked(),
                'model': model
            }
            params_check = dict(params)
            params_check.pop('model')
            return params, self.getChangedValues(params_check, LassoLarsCV())

        elif model == 2:
            params = {
                'criterion': self.criterionComboBox.currentText(),
                'fit_intercept': self.fit_interceptCheckBox.isChecked(),
                'verbose': self.fit_interceptCheckBox.isChecked(),
                'normalize': self.normalizeCheckBox.isChecked(),
                'precompute': self.precomputeComboBox.currentText(),
                'max_iter': self.max_iterSpinBox.value(),
                'copy_X': self.copy_XCheckBox.isChecked(),
                'positive': self.positiveCheckBox.isChecked(),
                'model': model
            }
            params_check = dict(params)
            params_check.pop('model')
            return params, self.getChangedValues(params_check, LassoLarsIC())
        else:
            params = {}
            print("Error")
Пример #11
0
 def __init__(self, criterion='aic', fit_intercept=True, verbose=False, normalize=True, precompute='auto', max_iter=500, eps=2.220446049250313e-16, copy_X=True, positive=False):
     self._hyperparams = {
         'criterion': criterion,
         'fit_intercept': fit_intercept,
         'verbose': verbose,
         'normalize': normalize,
         'precompute': precompute,
         'max_iter': max_iter,
         'eps': eps,
         'copy_X': copy_X,
         'positive': positive}
     self._wrapped_model = SKLModel(**self._hyperparams)
Пример #12
0
			'KNeighborsClassifier':KNeighborsClassifier(),
			'KNeighborsRegressor':KNeighborsRegressor(),
			'KernelCenterer':KernelCenterer(),
			'KernelDensity':KernelDensity(),
			'KernelPCA':KernelPCA(),
			'KernelRidge':KernelRidge(),
			'LSHForest':LSHForest(),
			'LabelPropagation':LabelPropagation(),
			'LabelSpreading':LabelSpreading(),
			'Lars':Lars(),
			'LarsCV':LarsCV(),
			'Lasso':Lasso(),
			'LassoCV':LassoCV(),
			'LassoLars':LassoLars(),
			'LassoLarsCV':LassoLarsCV(),
			'LassoLarsIC':LassoLarsIC(),
			'LatentDirichletAllocation':LatentDirichletAllocation(),
			'LedoitWolf':LedoitWolf(),
			'LinearDiscriminantAnalysis':LinearDiscriminantAnalysis(),
			'LinearRegression':LinearRegression(),
			'LinearSVC':LinearSVC(),
			'LinearSVR':LinearSVR(),
			'LocallyLinearEmbedding':LocallyLinearEmbedding(),
			'LogisticRegression':LogisticRegression(),
			'LogisticRegressionCV':LogisticRegressionCV(),
			'MDS':MDS(),
			'MLPClassifier':MLPClassifier(),
			'MLPRegressor':MLPRegressor(),
			'MaxAbsScaler':MaxAbsScaler(),
			'MeanShift':MeanShift(),
			'MinCovDet':MinCovDet(),