Skip to content

overvac/mltemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

mltemplate

πŸš€ Modern C++17 Machine Learning Template

A complete starter template for building machine learning projects in pure C++17.
Combines mlcore, dataframe, and matplotlib-cpp into a single ready-to-run example.

C++17 Platforms License Build


πŸ“– Overview

mltemplate is a modern C++17 machine learning template that integrates:

  • mlcore β†’ ML algorithms (Random Forest, SVM, KNN, etc.)
  • dataframe β†’ Pandas-like DataFrame in C++
  • matplotlib-cpp β†’ C++ wrapper for Python’s Matplotlib

It demonstrates an end-to-end ML pipeline in C++: load a dataset, preprocess features, train a model, visualize results, and export predictions to CSV. The repository includes a working Random Forest example on the Pima Indians Diabetes dataset.


πŸ›  Requirements

  • C++17 or newer
  • Python with Matplotlib (required by matplotlib-cpp)

Dependencies


πŸš€ Installation

# Clone repository
git clone --recursive https://github.com/overvac/mltemplate.git
cd mltemplate

# Build and run (MSVC / GCC / Clang)
# Windows (MSVC)
cl /std:c++17 /O2 main.cpp

# Linux / macOS
g++ -std=c++17 -O2 main.cpp -o app
./app

▢️ Example Program

#include "mltemplate/mltemplate.h"

int main()
{
    c_dataframe df("diabetes.csv");
    df.print();

    std::vector<std::string> feature_column_names = {
        "Pregnancies", "Glucose", "BloodPressure", "SkinThickness",
        "Insulin", "BMI", "DiabetesPedigreeFunction", "Age"
    };

    auto features = n_mlcore::n_preprocessing::c_transform::get().transpose<double>(
        df.at<double>(feature_column_names)
    );
    auto outcomes = df.at<int>("Outcome");

    n_mlcore::n_supervised::c_rf forest(500);
    forest.fit(features, outcomes);

    auto fi = forest.feature_importances();
    n_plt::bar(fi);
    n_plt::show();

    std::vector<int> predicted;
    predicted.reserve(features.size());
    for (const auto& f : features)
    {
        int p = forest.predict({ f })[0];
        predicted.push_back(p);
    }

    df.add_column<int>("Predicted", predicted);
    df.to_csv("solved_diabetes.csv");

    return 0;
}

πŸ“Š Output

  • Prints dataset summary from diabetes.csv
  • Trains a Random Forest classifier (mlcore)
  • Plots feature importances (matplotlib-cpp)
  • Saves predictions to solved_diabetes.csv

πŸ“œ License

Released under the MIT License.

About

Machine learning template in C++17

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published