# Training and Evaluating Machine Learning Models

This notebook explores several basic machine learning estimators in cuML, demonstrating how to train them and evaluate them with built-in metrics functions. All of the models are trained on synthetic data, generated by cuML’s dataset utilities.

1. Random Forest Classifier
2. UMAP
3. DBSCAN
4. Linear Regression

## Classification

### Random Forest Classification and Accuracy metrics

The Random Forest classification model builds several decision trees, and aggregates each of their outputs to make a prediction. For more information on cuML’s implementation of the Random Forest Classification model please refer to: [Random Forest Classifier API reference](../api/generated/cuml.ensemble.RandomForestClassifier/index.html.md)

Accuracy score is the ratio of correct predictions to the total number of predictions. It is used to measure the performance of classification models. For more information on the accuracy score metric please refer to: [https://en.wikipedia.org/wiki/Accuracy_and_precision](https://en.wikipedia.org/wiki/Accuracy_and_precision)

For more information on cuML’s implementation of accuracy score metrics, see the [accuracy score API reference](../api/generated/cuml.metrics.accuracy_score/index.html.md).

The cell below shows an end-to-end pipeline of the Random Forest Classification model. Here the dataset was generated using cuML’s make_classification dataset. The generated dataset was used to train and run predict on the model, and the performance is evaluated using cuML’s accuracy metric.

```none
[1]:
```

## Clustering

### UMAP and Trustworthiness metrics

UMAP is a dimensionality reduction algorithm which performs non-linear dimension reduction. It can also be used for visualization. For additional information on the UMAP model, see the [UMAP API reference](../api/generated/cuml.manifold.UMAP/index.html.md).

Trustworthiness is a measure of the extent to which the local structure is retained in the embedding of the model. Therefore, if a sample predicted by the model lay within the unexpected region of the nearest neighbors, then those samples would be penalized. For more information on the trustworthiness metric please refer to: [https://scikit-learn.org/stable/modules/generated/sklearn.manifold.trustworthiness.html](https://scikit-learn.org/stable/modules/generated/sklearn.manifold.trustworthiness.html)

See the [trustworthiness API reference](../api/generated/cuml.metrics.trustworthiness/index.html.md) for cuML’s implementation of the metric.

The cell below shows an end-to-end pipeline of the UMAP model. Here, the blobs dataset is created using cuML’s make_blobs function to be used as the input. The output of UMAP’s fit_transform is evaluated using cuML’s trustworthiness function.

```none
[2]:
```

### DBSCAN and Adjusted Random Index

DBSCAN is a popular clustering algorithm. For additional information on the model, see the [DBSCAN API reference](../api/generated/cuml.cluster.DBSCAN/index.html.md).

We create the blobs dataset using cuML’s make_blobs function.

Adjusted random index is a metric which is used to measure the similarity between two data clusters, and it is adjusted to take into consideration the chance grouping of elements. For more information on Adjusted random index please refer to: [https://en.wikipedia.org/wiki/Rand_index](https://en.wikipedia.org/wiki/Rand_index)

The cell below shows an end-to-end pipeline of the DBSCAN model. The output of DBSCAN’s fit_predict is evaluated using cuML’s Adjusted Random Index function.

```none
[3]:
```

## Regression

### Linear regression and R^2 score

Linear Regression is a simple machine learning model where the response y is modelled by a linear combination of the predictors in X.

R^2 score is also known as the coefficient of determination. It is used as a metric for scoring regression models. It scores the output of the model based on the proportion of total variation of the model. For more information on the R^2 score metrics please refer to: [https://en.wikipedia.org/wiki/Coefficient_of_determination](https://en.wikipedia.org/wiki/Coefficient_of_determination)

For more information on cuML’s implementation of the R² score metric, see the [R² score API reference](../api/generated/cuml.metrics.r2_score/index.html.md).

The cell below uses the Linear Regression model and evaluates its performance using cuML’s R² score metric. See the [Linear Regression API reference](../api/generated/cuml.linear_model.LinearRegression/index.html.md) for more information on cuML’s implementation.

```none
[4]:
```
