决策树变量的面向对象实现

oo_trees的Python项目详细描述


这个存储库将包含决策树的几个变体/ 集成分类算法,以面向对象的方式编写。 我的直接目标是试图重现一些关于典型相关的this paper的结果。 森林,我正在测试它。

如果可能,外部参数名将与scikit-learn匹配 实现decision treesrandom forests

用法

scikit-learn的一个主要区别是数据集和 属性被视为一级对象。此外,所有 分类器必须使用其训练数据集初始化(相反 调用fit

fromoo_trees.datasetimportDatasetfromoo_trees.decision_treeimportDecisionTreefromoo_trees.random_forestimportRandomForestX=examples# numpy 2D numeric arrayy=outcomes# numpy 1D arraydataset=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变量:

fromoo_trees.datasetimportDatasetfromoo_trees.attributeimportNumericAttribute,CategoricalAttributeX=examplesy=outcomesattributes=[NumericAttribute(index=0,name='age'),CategoricalAttribute(index=1,name='sex'),NumericAttribute(index=2,name='income')]dataset=Dataset(X,y,attributes)

对于每种属性类型,找到最佳分割的逻辑是不同的, 在将来,可能会有额外的特定于类型的参数(例如 作为重要性或编号到名称的映射)对分类或 显示。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java通过两个整数数组对正整数和负整数进行排序   java无参数和默认构造函数混淆   java加载文件MD5的最快方法是什么?   java如何在变量声明中使用带“e”的float   java将项目导入到STS iMac   java在使用图像时旋转图像   java Break语句不起作用   java提供了错误类型Spring的id   java如何为多个变量设置相同的函数属性?   JavaMaven:如何添加编译阶段后生成的资源   java HashMap已损坏/性能问题   java Hibernate SQL中间表b/w父表和子表(不同类型)   java PDFbox找不到字体:/Helv   Java:向自实现的双链接列表添加排序函数   为使用Java BouncyCastle生成的X509Certificate提供密钥使用的安全性   java Hibernate在读写方面的性能   C#相当于Java的DataOutputStream?