Пример #1
0
 def test_SimpleTree_classification_pickle(self):
     lrn = SimpleTreeCls()
     clf = lrn(self.data_cls)
     p = clf(self.data_cls, clf.Probs)
     clf_ = pickle.loads(pickle.dumps(clf))
     p_ = clf_(self.data_cls, clf.Probs)
     np.testing.assert_almost_equal(p, p_)
Пример #2
0
 def test_SimpleTree_single_instance(self):
     data = Orange.data.Table('iris')
     lrn = SimpleTreeCls()
     clf = lrn(data)
     for ins in data[::20]:
         clf(ins)
         val, prob = clf(ins, clf.ValueProbs)
         self.assertEqual(sum(prob[0]), 1)
Пример #3
0
 def test_SimpleTree_classification(self):
     lrn = SimpleTreeCls()
     clf = lrn(self.data_cls)
     p = clf(self.data_cls, clf.Probs)
     self.assertEqual(p.shape, (self.N, self.cls_vals))
     self.assertAlmostEqual(p.min(), 0)
     self.assertAlmostEqual(p.max(), 1)
     np.testing.assert_almost_equal(p.sum(axis=1), np.ones(self.N))
 def test_SimpleTree_classification_tree(self):
     lrn = SimpleTreeCls(min_instances=6, max_majority=0.7)
     clf = lrn(self.data_cls)
     self.assertEqual(
         clf.dumps_tree(clf.node),
         '{ 1 4 -1.17364 { 1 5 0.37564 { 2 0.00 0.00 0.56 } '
         '{ 2 0.00 3.00 1.14 } } { 1 4 -0.41863 { 1 5 0.14592 '
         '{ 2 3.54 0.54 0.70 } { 2 2.46 0.46 2.47 } } { 1 4 0.24404 '
         '{ 1 4 0.00654 { 1 3 -0.15750 { 2 1.00 0.00 0.45 } '
         '{ 2 1.00 3.00 0.48 } } { 2 1.00 5.00 0.70 } } { 1 5 0.32635 '
         '{ 2 0.52 2.52 4.21 } { 2 2.48 3.48 1.30 } } } } }')
Пример #5
0
 def test_SimpleTree_to_string_classification(self):
     domain = Domain([
         DiscreteVariable(name='d1', values='ef'),
         ContinuousVariable(name='c1')
     ], DiscreteVariable(name='cls', values='abc'))
     data = Table(domain, [['e', 1, 'a'], ['e', 1, 'b'], ['e', 2, 'b'],
                           ['f', 2, "c"], ["e", 3, "a"], ['f', 3, "c"]])
     lrn = SimpleTreeCls(min_instances=1)
     clf = lrn(data)
     clf_str = clf.to_string()
     res = '\nd1 ([2.0, 2.0, 2.0])\n: e\n   c1 ([2.0, 2.0, 0.0])\n   : <=2.5\n      c1 ([1.0, 2.0, 0.0])\n      : <=1.5 --> a ([1.0, 1.0, 0.0])\n      : >1.5 --> b ([0.0, 1.0, 0.0])\n   : >2.5 --> a ([1.0, 0.0, 0.0])\n: f --> c ([0.0, 0.0, 2.0])'
     self.assertEqual(clf_str, res)