# How was the model created?

To create this model 3 important steps were taken:

- Data ingestion.
- Use a Unsupervised model to avoid manual labeling of the data.
- Use a supervised model that was fitted with teh reclassified data.


## Data ingestion.

The first step was to identify the satellite images that will be used to train the model. The images were selected based on the following criteria:
- Low cloud coverage.
- Low cloud shadow coverage.
- They should have mixed cobertures of the classes that we want to identify.
- They should be from different seasons of the year.
- They should be in different parts of Colombia.


## Use a Unsupervised pipeline to avoid manual labeling of the data.

In order to cluster the different pixels of the images the following steps were taken:

- Dimensionality augmentation: During this process more than 50 indices were created using
[spyndex](https://spyndex.readthedocs.io/en/latest/index.html) api.
- At first a [UMAP](https://umap-learn.readthedocs.io/en/latest/index.html) + [HDBSCAN](https://hdbscan.readthedocs.io/en/latest/index.html) pipeline was proposed, but the results were not satisfactory.
- Then a [PCA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) + [KMeans](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html) pipeline was proposed, and the results were better.
- Different values of `n_components` for `PCA` and `n_clusters` for `KMeans` were tested, the metric used to evaluate the results was the [silhouette score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html). Different images that different hyperparameter combinations.
- The clusters where reclassified using visual interpretation of the coberture of the images. This step was done manually. It was probably the most important step of the process, due to the fact that the model will only be as good as the data that is used to train it.


## Use a supervised model that was fitted with the reclassified data.

The following pipeline was proposed:

- If any pixels are missing, the classifier will fill them in.
- Create indices using [spyndex](https://spyndex.readthedocs.io/en/latest/index.html) api..
- Use a [RobustScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.RobustScaler.html) for the data.
- Use a [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html) for the data (which may not be necessary).
- In order to use [PCA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) the classifier will use a [QuantileTransformer](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.QuantileTransformer.html) with a normal distribution as an output.
- Execute a [XGBoost](https://xgboost.readthedocs.io/en/stable/python/python_api.html#module-xgboost.sklearn) Algorithm
with fixed hyperparameters that were previously found using [GroupKFold](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GroupKFold.html)
validation where each image was a group.

