Source

orange-modelmaps / archive / rf2matrix.py

Full commit
import pickle

import orange
import orngTree
import orngEnsemble

from tools import *
from classifier2matrix import *
from matrix2network import *

TREE_LIMIT = 1000
KNN = 2
data_d = getData(ROOT + "tab/zoo.tab")

gini = orange.MeasureAttribute_gini()

tree = orngTree.TreeLearner(storeNodeClassifier = 1, \
                            storeContingencies=0, \
                            storeDistributions=1, \
                            minExamples=5, \
                            storeExamples=1).instance()
tree.split.discreteSplitConstructor.measure = tree.split.continuousSplitConstructor.measure = gini
tree.maxDepth = 5
tree.split = orngEnsemble.SplitConstructor_AttributeSubset(tree.split, 3)

forestLearner = orngEnsemble.RandomForestLearner(learner=tree, trees=TREE_LIMIT)
forest = forestLearner(data_d)

smx, RV = classifier2matrix(data_d, 5, forest.classifiers, OUT_FILE + "-rf")
methods, uuids, res, projections, classifiers, attrs = RV
#net = matrix2network(smx, 0.0, KNN)
#net.items = smx.items

smx.results = dict(zip(uuids, zip(methods, res, projections, classifiers, attrs)))
saveModel(smx, "%sdst/zoo-rf-%d" % (ROOT, smx.dim))