决策树C4.5实例练习

本文通过实例详细介绍了如何使用C4.5决策树算法进行数据分类,包括数据预处理、特征选择及模型构建过程,帮助读者深入理解决策树的工作原理。
摘要由CSDN通过智能技术生成









以下为在网上找的MATLAB实现C4.5的代码

function [tree test_targets] = C4_5(train_patterns, train_targets, test_patterns, inc_node, Nu)

% Classify using Quinlan's C4.5 algorithm
% Inputs:
% 	training_patterns   - Train patterns 行是特征,列是样本
%	training_targets	- Train targets  1行多列,列是训练样本个数
%       test_patterns       - Test  patterns 行是特征,列是样本
%	inc_node            - Percentage of incorrectly assigned samples at a node
%       inc_node为防止过拟合参数,表示样本数小于一定阈值结束递归,可设置为5-10
%       Nu is to determine whether the variable is discrete or continuous (the value is always set to 10)
%
% Outputs
%	test_targets        - Predicted targets 1行m列(列的长度是测试样本的个数)

%NOTE: In this implementation it is assumed that a pattern vector with fewer than 10 unique values (the parameter Nu)
%is discrete, and will be treated as such. Other vectors will be treated as continuous

[Ni, M]	    = size(train_patterns);%输入向量为NI*M的矩阵,其中M表示训练样本个数,Ni为特征维数维数
inc_node    = inc_node*M/100;

%Find which of the input patterns are discrete, and discretisize the corresponding
%dimension on the test patterns
discrete_dim = zeros(1,Ni);
for i = 1
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值