> 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-1.md).

# Case Study 1

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/YdCNhlXJ5h4mSujELBM4)

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)
```

Averaging

```python
awe= Averaging()
awe.set_base_models()
base_model =[('rfr', RandomForestRegressor()), ('knn', KNeighborsRegressor()), ('lr', LinearRegression()),
             ('rd', Ridge()),('etr', ExtraTreesRegressor()) ]
base_model
y_test_pred = awe.get_Averaging_technique(base_model= base_model,
                                          train_X=x_train,
                                          train_y= y_train,
                                          test_X=x_test)
y_test_pred
```

Performance Evaluation

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

![](/files/w7DCLmlSDZNV89CDSaGI)

```python
true1,pred1 =eva.get_plot_regression(true=y_test, pred=y_test_pred, ascending=False, label='Discharge Capacity')
```

![](/files/kglJ7gW4zE0xMcjDPY1y)

```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_test_pred).reshape(-1,1))
true0,pred0 =eva.get_plot_regression(true=true2, pred=pred2, ascending=False, label='Discharge Capacity')
```

![](/files/0279dsVSSFXEhaFrcQeZ)
