Some ML models for classification and regression implemented from scratch in C.
PLA | ADALINE | |
---|---|---|
Simple linear regression (Least squares with gradient decent) | Evolution of loss |
---|---|
gnuplot
(optionnal) This is just for theplot.sh
script, you can compile and use the library without thisrainy-csv
(optionnal) This is my library, I used it just for the tests, so you can skip it too, it is used as git submodule so it will be automatically downloaded when you clone with--recurse-submodules
If you are planning to run the tests, please clone with
$ git clone --recurse-submodules https://github.com/hazyuun/machine-learning-models
to automatically get rainy-csv
.
If you won't run the tests, then clone as usual :
$ git clone https://github.com/hazyuun/machine-learning-models
Just use the Makefile
$ make USE_RAINY_CSV=1 all
Output will be in lib
for the library, and in bin
for the tests, note that USE_RAINY_CSV
macro needs to be defined to compile the tests.
if you want to compile the library without rainy-csv
support, run :
$ make lib
otherwise, run
$ make USE_RAINY_CSV=1 lib
Output will be in lib
directory
$ make test
Output will be in bin
directory
#include <helpers/model.h>
#include <helpers/csv2dataset.h>
#include <utils/export.h>
int main(int argc, char **argv) {
(void)argc;
(void)argv;
/* Load data */
labeled_dataset_t *data;
data = csv_to_labeled_dataset("./test-data/noisy01.csv");
/* Make and train the model */
single_layer_model_t *model;
model = make_single_layer_model(LOG_REG_MODEL, 2, &sigmoid);
history_t *history = model->train(model, data);
/* Generate the output files for plotting */
gp_export_labeled_dataset(data, "data.in");
gp_export_single_layer_model(model, history);
}
First of all, after compiling, run the test of your choice, eg.
$ ./bin/rg_simple_linreg_test
Some output files will be generated, those files are used by the gnuplot scripts to show the result
Run the plot.sh
bash script to see the plots
- Reminder : you will need gnuplot for that
For the classification tests run :
$ ./plot.sh
For the linear regression ones run :
$ ./plot.sh --lin-reg
- Test files prefixed with
cl_
are for classification, and ones prefixed withrg_
are for regression.