コード例 #1
0
    def test_prepare_outcomes(self):
        results = utilities.load_flu_data()

        # string type correct
        ooi = 'nr deaths'
        results[1][ooi] = results[1]['deceased population region 1'][:, -1]
        y, categorical = fs._prepare_outcomes(results[1], ooi)

        self.assertFalse(categorical)
        self.assertTrue(len(y.shape) == 1)

        # string type not correct --> KeyError
        with self.assertRaises(KeyError):
            fs._prepare_outcomes(results[1], "non existing key")

        # classify function correct
        def classify(data):
            result = data['deceased population region 1']
            classes = np.zeros(result.shape[0])
            classes[result[:, -1] > 1000000] = 1
            return classes

        y, categorical = fs._prepare_outcomes(results[1], classify)

        self.assertTrue(categorical)
        self.assertTrue(len(y.shape) == 1)

        # neither string nor classify function --> TypeError
        with self.assertRaises(TypeError):
            fs._prepare_outcomes(results[1], 1)
コード例 #2
0
 def test_prepare_outcomes(self):
     results = test_utilities.load_flu_data()
     
     # string type correct
     ooi = 'nr deaths'
     results[1][ooi] = results[1]['deceased population region 1'][:,-1]
     y, categorical = fs._prepare_outcomes(results[1], ooi)
     
     self.assertFalse(categorical)
     self.assertTrue(len(y.shape)==1)
     
     # string type not correct --> KeyError
     with self.assertRaises(KeyError):
         fs._prepare_outcomes(results[1], "non existing key")
     
     # classify function correct
     def classify(data):
         result = data['deceased population region 1']
         classes =  np.zeros(result.shape[0])
         classes[result[:, -1] > 1000000] = 1
         return classes
     
     y, categorical = fs._prepare_outcomes(results[1], classify)
     
     self.assertTrue(categorical)
     self.assertTrue(len(y.shape)==1)
     
     # neither string nor classify function --> TypeError
     with self.assertRaises(TypeError):
         fs._prepare_outcomes(results[1], 1)