Kir*_*ril 5 c++ algorithm machine-learning decision-tree
我一直在寻找C4.5算法的C++实现,但我还没有找到.我找到了Quinlan的C4.5 Release 8,但它是用C语言编写的......有没有人看过C4.5算法的任何开源C++实现?
如果我找不到开源C++实现,我正在考虑移植J48源代码(或者简单地在C版本周围编写一个包装器),但我希望我不必这样做!如果您遇到过算法的C++实现,请告诉我.
我一直在考虑围绕C5.0算法的C实现编写一个瘦C++包装器的选项(C5.0是C4.5的改进版本).我下载并编译了C5.0算法的C实现,但看起来它不容易移植到C++.C实现使用了很多全局变量,只是在C函数周围编写一个瘦C++包装器不会导致面向对象的设计,因为每个类实例都将修改相同的全局参数.换句话说:我没有封装,这是我需要的一个非常基本的东西.
为了获得封装,我需要将C代码的完整端口转换为C++,这与将Java版本(J48)移植到C++中大致相同.
以下是一些具体要求:
这是一个很好的场景:假设我正在进行10倍交叉验证,我希望同时使用各自的训练集切片训练10个决策树.如果我只为每个切片运行C程序,我将不得不运行10个进程,这并不可怕.但是,如果我需要实时对数千个数据样本进行分类,那么我将不得不为每个我想要分类的样本开始一个新的过程,而且效率不高.
我可能已经找到了C5.0 (See5.0) 的可能的 C++“实现”,但我还无法深入研究源代码来确定它是否真的像宣传的那样工作。
为了重申我最初的担忧,该移植的作者对 C5.0 算法进行了以下陈述:
See5Sam [C5.0] 的另一个缺点是不可能同时拥有多个应用程序树。每次运行可执行文件时都会从文件中读取应用程序,并将其存储在各处的全局变量中。
一旦我有时间研究源代码,我就会更新我的答案。
看起来不错,这是 C++ 接口:
class CMee5
{
public:
/**
Create a See 5 engine from tree/rules files.
\param pcFileStem The stem of the See 5 file system. The engine
initialisation will look for the following files:
- pcFileStem.names Vanilla See 5 names file (mandatory)
- pcFileStem.tree or pcFileStem.rules Vanilla See 5 tree or rules
file (mandatory)
- pcFileStem.costs Vanilla See 5 costs file (mandatory)
*/
inline CMee5(const char* pcFileStem, bool bUseRules);
/**
Release allocated memory for this engine.
*/
inline ~CMee5();
/**
General classification routine accepting a data record.
*/
inline unsigned int classifyDataRec(DataRec Case, float* pOutConfidence);
/**
Show rules that were used to classify the last case.
Classify() will have set RulesUsed[] to
number of active rules for trial 0,
first active rule, second active rule, ..., last active rule,
number of active rules for trial 1,
first active rule, second active rule, ..., last active rule,
and so on.
*/
inline void showRules(int Spaces);
/**
Open file with given extension for read/write with the actual file stem.
*/
inline FILE* GetFile(String Extension, String RW);
/**
Read a raw case from file Df.
For each attribute, read the attribute value from the file.
If it is a discrete valued attribute, find the associated no.
of this attribute value (if the value is unknown this is 0).
Returns the array of attribute values.
*/
inline DataRec GetDataRec(FILE *Df, Boolean Train);
inline DataRec GetDataRecFromVec(float* pfVals, Boolean Train);
inline float TranslateStringField(int Att, const char* Name);
inline void Error(int ErrNo, String S1, String S2);
inline int getMaxClass() const;
inline int getClassAtt() const;
inline int getLabelAtt() const;
inline int getCWtAtt() const;
inline unsigned int getMaxAtt() const;
inline const char* getClassName(int nClassNo) const;
inline char* getIgnoredVals();
inline void FreeLastCase(void* DVec);
}
Run Code Online (Sandbox Code Playgroud)
我想说这是迄今为止我找到的最好的选择。