コード例 #1
0
 def test_save_and_load_hierarchical_rf(self):
     classifier = HierarchicalRandomForest(self.taxonomy_dictionary)
     classifier.fit(self.features, self.labels)
     predicted_probs = classifier.predict_proba(self.features)
     classifier.save_model(self.tmp_dir)
     classifier2 = HierarchicalRandomForest(self.taxonomy_dictionary)
     classifier2.load_model(self.tmp_dir)
     predicted_probs2 = classifier2.predict_proba(self.features)
     self.assertTrue((predicted_probs == predicted_probs2).all(axis=None))
コード例 #2
0
 def test_larger_dictionary(self):
     taxonomy_dictionary = self.taxonomy_dictionary
     taxonomy_dictionary[
         'Stochastic'] = taxonomy_dictionary['Stochastic'] + ['new class']
     classifier = HierarchicalRandomForest(self.taxonomy_dictionary)
     classifier.fit(self.features, self.labels)
     predicted_probs = classifier.predict_proba(self.features)
     self.assertEqual(predicted_probs.shape, (len(self.features), 15))
コード例 #3
0
 def test_fit(self):
     taxonomy_dictionary = {
         'Stochastic': ['LPV', 'QSO', 'YSO', 'CV/Nova', 'Blazar', 'AGN'],
         'Periodic': ['RRL', 'EB', 'DSCT', 'Ceph', 'Periodic-Other'],
         'Transient': ['SNIa', 'SNII', 'SNIbc']
     }
     model = HierarchicalRandomForest(taxonomy_dictionary)
     model.fit(self.train_features, self.train_labels)
     probs = model.predict_proba(self.train_features)
     print(probs.head())
     predicted_classes = model.predict(self.train_features)
     print(predicted_classes.head())
コード例 #4
0
 def test_predict_proba(self):
     classifier = HierarchicalRandomForest(self.taxonomy_dictionary)
     classifier.fit(self.features, self.labels)
     predicted_probs = classifier.predict_proba(self.features)
     self.is_sum_one(predicted_probs)