决策树变体的面向对象实现
项目描述
此存储库将包含决策树/集成分类算法的几个变体,以面向对象风格编写。我的直接目标是尝试在这篇论文上重现一些关于典型相关森林的结果,我正在使用相同的数据集进行测试。
尽可能的情况下,外部参数名称将与scikit-learn对决策树和随机森林的实现相匹配。
使用方法
与scikit-learn相比的一个主要区别是,数据集及其属性被视为一等对象。此外,所有分类器都必须使用其训练数据集进行初始化(而不是调用fit)。
from oo_trees.dataset import Dataset
from oo_trees.decision_tree import DecisionTree
from oo_trees.random_forest import RandomForest
X = examples # numpy 2D numeric array
y = outcomes # numpy 1D array
dataset = Dataset(X, y)
training_dataset, test_dataset = dataset.random_split(0.75)
d_tree = DecisionTree(training_dataset)
forest = RandomForest(training_dataset)
print(d_tree.classify(test_dataset.X[0]))
print(forest.classify(test_dataset.X[0]))
d_tree_confusion_matrix = d_tree.performance_on(test_dataset)
forest_confusion_matrix = forest.performance_on(test_dataset)
print(d_tree_confusion_matrix.accuracy)
print(forest_confusion_matrix.accuracy)
初始化数据集时,我们假设所有训练示例的属性都是分类的。如果不是这种情况,您可以在初始化时传递一个额外的attribute_types变量。
from oo_trees.dataset import Dataset
from oo_trees.attribute import NumericAttribute, CategoricalAttribute
X = examples
y = outcomes
attributes = [
NumericAttribute(index=0, name='age'),
CategoricalAttribute(index=1, name='sex'),
NumericAttribute(index=2, name='income')
]
dataset = Dataset(X, y, attributes)
查找最佳分割的逻辑因属性类型而异,并且将来可能会有更多特定类型的参数(例如重要性或数字到名称映射)用于分类或显示。
项目详细信息
关闭
oo_trees-0.0.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f67442d6b872e51a338791e0612210b7c9ba111b0e32efa738b5a90f6ddb7557 |
|
MD5 | a77b1b32863e724b09484c9c85570e12 |
|
BLAKE2b-256 | ef60e5f388298fd023b70d8b9d1aa053089ca8ced85ee6bab5447ef941eb16bf |