def test_lasso_scorer_feature(self):
     data = Table('housing')
     learner = LassoRegressionLearner()
     scores = learner.score_data(data)
     for i, attr in enumerate(data.domain.attributes):
         score = learner.score_data(data, attr)
         self.assertEqual(score, scores[i])
示例#2
0
 def test_lasso_scorer_feature(self):
     data = Table('housing')
     learner = LassoRegressionLearner()
     scores = learner.score_data(data)
     for i, attr in enumerate(data.domain.attributes):
         score = learner.score_data(data, attr)
         self.assertEqual(score, scores[i])
 def test_comparison_elastic_net(self):
     alphas = [0.001, 0.1, 1, 10, 100]
     for a in alphas:
         lasso = LassoRegressionLearner(alpha=a)
         lasso_model = lasso(self.housing)
         elastic = ElasticNetLearner(alpha=a, l1_ratio=1)
         elastic_model = elastic(self.housing)
         d = np.sum(lasso_model.coefficients - elastic_model.coefficients)
         self.assertEqual(d, 0)
 def test_comparison_elastic_net(self):
     alphas = [0.001, 0.1, 1, 10, 100]
     for a in alphas:
         lasso = LassoRegressionLearner(alpha=a)
         lasso_model = lasso(self.housing)
         en = ElasticNetLearner(alpha=a, l1_ratio=1)
         en_model = en(self.housing)
         np.testing.assert_allclose(lasso_model.coefficients,
                                    en_model.coefficients,
                                    atol=1e-07)
示例#5
0
 def test_scorer_feature(self):
     learners = [LinearRegressionLearner(),
                 RidgeRegressionLearner(),
                 LassoRegressionLearner(alpha=0.01),
                 ElasticNetLearner(alpha=0.01)]
     for learner in learners:
         scores = learner.score_data(self.housing)
         for i, attr in enumerate(self.housing.domain.attributes):
             score = learner.score_data(self.housing, attr)
             self.assertEqual(score, scores[i])
示例#6
0
 def test_scorer(self):
     learners = [LinearRegressionLearner(),
                 RidgeRegressionLearner(),
                 LassoRegressionLearner(alpha=0.01),
                 ElasticNetLearner(alpha=0.01)]
     for learner in learners:
         scores = learner.score_data(self.housing)
         self.assertEqual('LSTAT',
                          self.housing.domain.attributes[np.argmax(scores)].name)
         self.assertEqual(len(scores), len(self.housing.domain.attributes))
 def test_Regression(self):
     ridge = RidgeRegressionLearner()
     lasso = LassoRegressionLearner()
     elastic = ElasticNetLearner()
     elasticCV = ElasticNetCVLearner()
     mean = MeanLearner()
     learners = [ridge, lasso, elastic, elasticCV, mean]
     res = CrossValidation(self.housing, learners, k=2)
     rmse = RMSE(res)
     for i in range(len(learners) - 1):
         self.assertLess(rmse[i], rmse[-1])
 def test_scorer(self):
     data = Table('housing')
     learners = [
         LinearRegressionLearner(),
         RidgeRegressionLearner(),
         LassoRegressionLearner(alpha=0.01),
         ElasticNetLearner(alpha=0.01)
     ]
     for learner in learners:
         scores = learner.score_data(data)
         self.assertEqual('NOX',
                          data.domain.attributes[np.argmax(scores)].name)
         self.assertEqual(len(scores), len(data.domain.attributes))
 def test_lasso_scorer(self):
     data = Table('housing')
     learner = LassoRegressionLearner()
     scores = learner.score_data(data)
     self.assertEqual(len(scores), len(data.domain.attributes))
示例#10
0
 def test_lasso_scorer(self):
     data = Table('housing')
     learner = LassoRegressionLearner()
     scores = learner.score_data(data)
     self.assertEqual(len(scores), len(data.domain.attributes))