Example #1
0
    def test_generate_predictions(self):
        # Test KNN regressor multiple predictions against sklearn regressor predictions
        reg_obs = np.array([self.reg_obs1, self.reg_obs2, self.reg_obs3])
        knn_reg_preds = gp.generate_predictions(self.knn_regressor, reg_obs,
                                                'all')
        test_generate_predictions.knn_reg_preds = knn_reg_preds
        sklearn_reg_preds = self.sklearn_regressor.predict(reg_obs)
        test_generate_predictions.sklearn_reg_preds = sklearn_reg_preds
        self.assertTrue(np.mean(knn_reg_preds == sklearn_reg_preds))
        # Check that length of inputted observations and results match
        self.assertEqual(len(reg_obs), len(knn_reg_preds))

        # Test KNN classifier multiple predictions against sklearn classifier predictions
        clf_obs = np.array([self.clf_obs1, self.clf_obs2, self.clf_obs3])
        knn_clf_preds = gp.generate_predictions(self.knn_classifier, clf_obs,
                                                'all')
        test_generate_predictions.knn_clf_preds = knn_clf_preds
        sklearn_clf_preds = self.sklearn_classifier.predict(clf_obs)
        test_generate_predictions.sklearn_clf_preds = sklearn_clf_preds
        self.assertTrue(np.mean(knn_clf_preds == sklearn_clf_preds))
        # Check that length of inputted observations and results match
        self.assertEqual(len(clf_obs), len(knn_clf_preds))
    def test_accuracy(self):
        self.accuracy = 0.6666666666666666
        TestClassificationMetrics.assert_accuracy = mm.model_accuracy(
            ['Iris-virginica', 'Iris-virginica', 'Iris-setosa'],
            gp.generate_predictions(
                TestClassificationMetrics.test_knn_classifier, self.to_predict,
                'all'))

        self.assertEqual(self.accuracy, self.assert_accuracy)
        self.assertIsInstance(TestClassificationMetrics.assert_accuracy,
                              numbers.Number)
        self.assertIsInstance(TestClassificationMetrics.assert_accuracy, float)
        assert TestClassificationMetrics.assert_accuracy >= 0
 def test_model_num_incorrect(self):
     self.num_incorrect = 2
     TestClassificationMetrics.assert_num_incorrect = mm.model_num_incorrect(
         ['Iris-virginica', 'Iris-virginica', 'Iris-setosa'],
         gp.generate_predictions(
             TestClassificationMetrics.test_knn_classifier, self.to_predict,
             'all'))
     self.assertNotEqual(self.assert_num_incorrect, self.num_incorrect)
     self.assertIsInstance(TestClassificationMetrics.assert_num_incorrect,
                           numbers.Number)
     self.assertNotIsInstance(
         TestClassificationMetrics.assert_num_incorrect, float)
     assert TestClassificationMetrics.assert_num_incorrect >= 0
 def setUp(self):
     
     self.actual_mpg=[19,18,23,28]
     self.mpg_to_predict=np.array([[6,250,100,3282,15],[6,250,88,3139,14.5],[4,122,86,2220,14],[4,116,90,2123,14]])
     self.predicted_mpg= gp.generate_predictions(TestRegressionMetrics.test_knn_regressor,self.mpg_to_predict,'train')
 def setUp(self):
     self.to_predict = np.array([[6.3, 2.3, 4.4, 1.3], [6.8, 3.2, 5.9, 2.3],
                                 [4.3, 3, 1.1, 0.1]])
     gp.generate_predictions(TestClassificationMetrics.test_knn_classifier,
                             self.to_predict, 'all')