# Data Science: An Implementation of the AdaBoost Algorithm.

*This story is part of my **Data Science** series.*

In my previous story I have given a quick overview of the AdaBoost algorithm and its theory (see here). In this account we will look at an implementation of this algorithm in Rust (educational purposes only).

## Implementation:

The data we are looking at are from here. They are mainly intended as a classification problem with binary outcome.

For the purpose of this article it doesn’t mind of how these data are loaded into the application. We just assume they are pulled by the following method:

`fn fetch_data(data_type: DataType) -> Vec<Vec<f64>>;`

where the `data_type`

describes what data to fetch (training samples or test data).

The first column of this matrix structure is assumed to contain the binary outcome and the rest are just continuous feature variables.

A model to us is just the trait

`pub trait Model {`

fn predict(&self, x: &[f64]) -> f64;

}

So, something that can predict based on a given features sample `x`

.

Since AdaBoost can by applied on almost every model type, it is natural to leave the actual model as a parameter:

`pub struct AdaBoost<T>`

where

T: Model,

{

models: Vec<T>,

alphas: Vec<f64>,

}

Remember, AdaBoost produces a list of models that are combined together by a weighted sum. The weights are the `alphas`

.

The prediction of an AdaBoost trained model is then a weighted voting where a positive outcome represents a forecast of `1`

and a negative one of `0`

:

`impl<T> Model for…`