【机器学习】【随机森林-2】Random Forest算法的Python实现

1.随机森林基本原理

随机森林的基本原理,以及数学示例,可以看以前博客:【机器学习】【随机森林-1】Random Forest算法讲解 + 示例展示数学求解过程

2.Python实现代码

随机森林可以自己实现,下面是一个在GitHub上找到的一个随机森林算法的实现代码,可以看看。

2.1代码

2.1.1RandomForest.h

/************************************************
*Random Forest Program
*Function:		trian&test Random Forest Model
*Author:		handspeaker@163.com
*CreateTime:	2014.7.10
*Version:		V0.1
*************************************************/
#ifndef RANDOM_FOREST_H
#define RANDOM_FOREST_H

#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"Tree.h"
#include"Sample.h"

class RandomForest
{
public:
	/*************************************************************
	*treeNum:	the number of trees in this forest
	*maxDepth:	the max Depth of one single tree
	*minLeafSample:terminate criterion,the min samples in a leaf              
	*minInfoGain:terminate criterion,the min information
	*            gain in a node if it can be splitted
	**************************************************************/
	RandomForest(int treeNum,int maxDepth,int minLeafSample,float minInfoGain);
	RandomForest(const char*modelPath);
	~RandomForest();
	/*************************************************************
	*trainset:	the trainset,every row is a sample,every column is 
	*a feature,the total size is SampleNum*featureNum
	*labels:the labels or regression values of the trainset,
	*the total size is SampleNum
	*SampleNum:the total number of trainset
	*featureNum:the number of features
	*classNum:the class number,regressiong is 1
	*isRegression:if the problem is regression(true) or classification(false)
	*trainFeatureNumPerNode:the feature number used in every node while training
	*************************************************/
	void train(float**trainset,float*labels,int SampleNum,int featureNum,
			   int classNum,bool isRegressi
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值