> 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/case-study/case-study-2.md).

# Case Study 2

The dataset was provided by the Prognostics CoE at NASA Ames. It is of a Li-ion battery which was run through 3 different operational profiles (charge, discharge and impedance) at room temperature. Here, the discharge capacity is the output feature while temperature, current and voltage are all input features.&#x20;

Importing the libraries&#x20;

```python
from tkmt_package.preprocessing import Preprocessing
from tkmt_package.ensemble import Averaging
from tkmt_package.evaluation import Evaluation
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
from sklearn.ensemble import ExtraTreesRegressor
```

Importing the dataset

```python
df = pd.read_csv(r"https://raw.githubusercontent.com/tkmtpackage/tkmt_ensemble/main/B0005.csv")
df.head()
```

![](/files/Vw7KrrIqEHcAIEtnIvmo)

Rearranging the features

```python
dy= df[['ambient_temperature','voltage_measured', 'current_measured', 'temperature_measured',
       'current_load', 'voltage_load', 'capacity']]
```

Data Preprocessing

```python
prep= Preprocessing() 
X1,y1= prep.data_preparation(dy)
X_scal,y_scal = prep.data_normalization()
X_scal.shape,y_scal.shape
x_train,x_test,y_train,y_test = prep.data_split_train_test(X_scal,y_scal)
```

Weighted Averaging&#x20;

```python
wtavg = weighted_Averaging()
base_model =[('rfr', RandomForestRegressor()), ('knn', KNeighborsRegressor()), ('lr', LinearRegression()),
             ('rd', Ridge()),('etr', ExtraTreesRegressor()) ]
base_model
y_pred1 = wtavg.get_weighted_Avg_technique(base_model=base_model,
                                  train_X = x_train,
                                  train_y = y_train,
                                  test_X  = x_test,
                                  weights = [0.2,0.1,0.04,0.06,0.6])
```

Performance Evaluation

```python
eva= Evaluation()
eva.performance_evaluation(y_test,y_pred1)
```

![](/files/GECsI6GYTR97x3b2h43S)

```python
true2,pred2 =eva.get_plot_regression(true=y_test, pred=y_pred1, ascending=False, label='Discharge Capacity')
```

![](/files/S8lpafFGLyqKEQ79ECgf)

```python
# convert scaled data into its original format.
import numpy as np
true2 = prep.scaled_y.inverse_transform(np.array(y_test).reshape(-1,1))
pred2 =  prep.scaled_y.inverse_transform(np.array(y_pred1).reshape(-1,1))
true0,pred0 =eva.get_plot_regression(true=true2, pred=pred2, ascending=False, label='Discharge Capacity')
```

![](/files/ehLnK0yr5OsuoCYdKVWE)
