> 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/data-preprocessing.md).

# Data Preprocessing

## About

**Data preprocessing is done using tools to assign input and output variables, perform data scaling and train test split.**&#x20;

{% hint style="info" %}
`from tkmt_package.preprocessing import Preprocessing`
{% endhint %}

**Data Preparation**

Assigns the dependent and the independent variables.

{% hint style="info" %}
`Preprocessing.data_preparation(dataset)`
{% endhint %}

```css
Parameters
----------
dataset: variable assigned to the dataset.

Attributes
----------
X: input/dependent variables; returns all columns except the last. 
y: output/ independent variable; returns the last column only.

Example
-------
>>> from tkmt_package.preprocessing import Preprocessing
>>> dy = df[['cycle','voltage', 'current', 'temperature']]
>>> prep = Preprocessing()
>>> X1,y1= prep.data_preparation(dy)
```

**Data Normalisation**

Rescales the data such that all the feature values are in the range 0 to 1.

{% hint style="info" %}
`Preprocessing.data_normalisation()`
{% endhint %}

```python
Attributes
----------
X_scal: scaled dependent variables; 
        returns all columns except last with its values rescaled between 0 to 1.
        
y_scal: scaled independent variables;  
        returns the last column with its values rescaled between 0 to 1.

Example
-------
>>> from tkmt_package.preprocessing import Preprocessing
>>> prep = Preprocessing()
>>> X_scal,y_scal = prep.data_normalization()
```

**Train Test Split**

Splits the data such that 80% of the data goes for training and 20% of the data goes for testing with the random state as 42.

{% hint style="info" %}
`Preprocessing.data_split_train_test(sample_X, sample_y)`
{% endhint %}

```python
Parameters
----------
sample_X: input features 
sample_y: output features

Attributes
----------
X_train: 80% of the data in X.
X_test: 20% of the data in X.
y_train: 80% of the data in y.
y_test: 20% of the data in y.

Example
-------
>>> from tkmt_package.preprocessing import Preprocessing
>>> prep = Preprocessing()
>>> X_train,X_test,y_train,y_test = prep.data_split_train_test(X,y)
```
