> For the complete documentation index, see [llms.txt](https://mugdha-thanawala.gitbook.io/tkmt_package/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mugdha-thanawala.gitbook.io/tkmt_package/guides/ensemble-learning-techniques/rank-weighted-averaging.md).

# Rank Weighted Averaging

**Multiple models are trained on the data points and based on the individual accuracy, weights are assigned to those models and then predictions are made for each data point and the average of predictions from all the models are used to make the final prediction.**

{% hint style="info" %}
`from tkmt_package.ensemble import Rank_weighted`
{% endhint %}

Getting the weights for the base models based on their accuracies&#x20;

{% hint style="info" %}
`Rank_weighted.get_weights(threshold, base_model, train_X, test_X, train_y, test_y)`
{% endhint %}

```python
Parameters
----------
threshold: minimum accuracy expected from the models.
base_model: models statisfying the threshold. 
train_X: input train data.
test_X: input test data.
train_y: output train data.
test_y: output test data.

Example
-------
>>> from tkmt_package.ensemble import Rank_weighted
>>> rkwt = Rank_weighted()
>>> summary = rkwt.get_weights(threshold= 0.5,
              base_model= base_models,
              train_X= x_train,
              test_X= x_test,
              train_y= y_train,
              test_y= y_test)
```

Rank Weighted Averaging

{% hint style="info" %}

```
awe.get_weighted_Avg_technique(base_model= base_models,
                               train_X=x_train,
                               train_y= y_train,
                               test_X=x_test,
                               weights= weights1)
```

{% endhint %}

```python
Parameters
----------
base_model: models set as the base models for averaging.
train_X: input train data.
train_y: output train data.
test_X: input test data.
weights: weights obtained from the models.

Example
-------
>>> from Ensemble_Learning import Rank_weighted
>>> rkwt = Rank_weighted()
>>> summary.weights.values
>>> ypred_test = awe.get_weighted_Avg_technique(base_model= base_models,
                               train_X=x_train,
                               train_y= y_train,
                               test_X=x_test,
                               weights= weights1)
```
