Skip to content

Commit

Permalink
Ordinal Encoding README added
Browse files Browse the repository at this point in the history
  • Loading branch information
Lycons-rage committed Jun 10, 2024
1 parent 84633e1 commit 806dcd5
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 1 deletion.
72 changes: 72 additions & 0 deletions Pre-Processing/Algorithms/Ordinal_Encoding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# OrdinalEncoding

`OrdinalEncoding` is a custom implementation of ordinal encoding for categorical variables. It assigns a unique integer value to each category, preserving the ordinal relationship if present.

![Ordinal Encoder by Scikit-learn](images/ordinal_enc_scikit-learn_ex.png)

## Features

- **Null Check**: Provides a null check function to ensure input data does not contain null values before encoding.
- **Fit Function**: Computes category mappings for each column based on unique values.
- **Transform Function**: Transforms categorical variables into encoded integers using the computed mappings.
- **Fit Transform**: Combines the fit and transform steps into a single method.

## Methods

- `null_check(data)`: Checks for null values in the input data.
- `fit(data)`: Computes category mappings for each column based on unique values.
- `transform(data)`: Transforms categorical variables into encoded integers using the computed mappings.
- `fit_transform(data)`: Combines the fit and transform steps into a single method.

## Exception Handling

The class includes basic exception handling:
- Raises a ValueError if input data contains null values.

## Installation

This implementation is a standalone Python class and does not require any specific installation. However, you need to have `numpy` and `pandas` installed in your environment.
Just run these command in the Algorithms directory
- First, create a virtual environment. For that, ```virtualenv``` module is required.
```
pip install virtualenv
```
Then to create a virtual environement:
```
virtualenv <environment_name>
```
This creates a virtual environment inside Algorithms directory, which then needs to be activated
```
py <environment_name>/Scripts/activate_this.py
```
- Secondly, install all the required libraries
```
pip install -r requirements.txt
```

## Testing

1. Load all the required libraries and Custom OrdinalEncoding class

![Load required libraries and StandardScaling Class](images/test_1.png)

2. Create a custom data frame

![Create a custom dataframe](images/test_2.png)

3. Create a OrdinalEncoding Class's object and call the desired functions

![Creating object and calling functions](images/test_3.png)

## Outputs

![Original Data](images/out_1.png)

![Scaled Data](images/out_2.png)

### Notes
1. **Ensure the class definition is available**: Include the `OrdinalEncoding` class in your script or save it in a module (e.g., `your_module.py`) and import it accordingly.
2. **Adjust paths**: Make sure to adjust the import path if you save the class in a different module.
3. **License**: Replace the placeholder in the License section with the actual license text or file link.

This README provides a comprehensive overview of the `OrdinalEncoding` class, including its features, usage examples, and how to handle potential issues.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
}
df = pd.DataFrame(data)

print(f"Original Data : \n{df}")

# Initialize the custom OrdinalEncoder
encoder = OrdinalEncoding()

# Fit the encoder to the data and transform it
try:
encoded_df = encoder.fit_transform(df)
print("\nEncoded DataFrame:")
print("\nEncoded Data:")
print(encoded_df)
except ValueError as e:
print(f"\nException: {e}")

0 comments on commit 806dcd5

Please sign in to comment.