Giter Club home page Giter Club logo

randomforest-cpp's Introduction

Random Forest (c++)

Introduction

An implementation of Random Forests, which is written in C++. The speed and perfomance is similar to sklearn-version.

build

I just uses the standard library without any third-class library.

cd build
cmake ../
make -j4

Load Data

The format of train data file is like data/debug.txt which is a sparse matrix. The format of test data is like data/debug_test.txt.

Train

Parameters:

 * @param(int) nEstimators The number of trees in the forest. Default: 10
 * @param(string) criterion The function to measure the quality of a split.
 * Supported criteria are “gini” for the Gini impurity and “entropy” for
 * the information gain. Default: gini
 * @param(string) maxFeatures
 *          * If “auto”, then max_features=sqrt(n_features).
 *          * If “sqrt”, then max_features=sqrt(n_features) (same as “auto”).
 *          * If “log2”, then max_features=log2(n_features).
 *          * If "None", then max_features=n_features.
 * Default: "log2"
 * @param(int) maxDepth The maximum depth of the tree. -1 means any depth. Default: -1
 * @param(int) minSamplesSplit The minimum number of samples required to split
 * an internal node. Default:2
 * @param(int) minSamplesLeaf The minimum number of samples required to be at
 * a leaf node. Default:1
 * @param(int) nJobs The number of jobs to run in parallel for both fit and
 * predict. Default:1
RandomForest randomForest(100, "gini", "log2", -1, 150, 1, 1000000, 8);
randomForest.fit(trainData);

Test

auto results = randomForest.predictProba(testData);
writeDataToCSV(results, testData, "../results/trainResults.csv", false);

Performance

For a dataset which has about ~1.7 million samples, the performance of my implementation is similar to sklearn-version.

performance

randomforest-cpp's People

Contributors

zexinyan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.