コード例 #1
0
 def test_can_clone_selective_regularization(self):
     X = np.random.normal(size=(10, 3))
     y = np.random.normal(size=(10, ))
     model = SelectiveRegularization(unpenalized_inds=[0],
                                     penalized_model=LassoCV(),
                                     fit_intercept=True)
     model.cv = 2
     model2 = clone(model, safe=False)
     assert model2.cv == 2
コード例 #2
0
    def test_can_pass_through_attributes(self):
        X = np.random.normal(size=(10, 3))
        y = np.random.normal(size=(10, ))
        model = SelectiveRegularization(unpenalized_inds=[0],
                                        penalized_model=LassoCV(),
                                        fit_intercept=True)

        # _penalized_inds is only set during fitting
        with self.assertRaises(AttributeError):
            inds = model._penalized_inds

        # cv exists on penalized model
        old_cv = model.cv
        model.cv = 2

        model.fit(X, y)

        # now we can access _penalized_inds
        assert np.array_equal(model._penalized_inds, [1, 2])

        # check that we can read the cv attribute back out from the underlying model
        assert model.cv == 2