-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c008e32
commit 832f563
Showing
7 changed files
with
130 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 nikhil kala | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
MIT License | ||
Copyright (c) 2020 nikhil kala | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MIT License | ||
Copyright (c) 2020 Nikhil Kala | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# Categorical-Encode | ||
# categorical-encode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
def categorical( | ||
dataframe=None, | ||
normalize=False, | ||
drop_columns=[], | ||
drop_na=False, | ||
target_columns=[], | ||
): | ||
""" | ||
:rtype: Pandas DataFrame | ||
:param dataframe: The Input DataFrame(X) which you want to categorically encode. | ||
:param normalize: This parameter determines if it will be between 0-1(1 included) or 1 to no. of classes (1 - no. of classes). default:False | ||
:param drop_columns: This specifies the dataframe columns that need to be dropped as they are useless. default: No Columns | ||
:param drop_na: This drops empty values (NaN) if is set to True. default: False | ||
:param target_columns: This creates the target DataFrame(Y) without applying any Encoding. default: No Columns | ||
:return: This Returns Two DataFrame(X,Y) if target_columns are provided Else only the Input dataframe(X) which is encoded. | ||
""" | ||
|
||
import pandas as pd | ||
if not isinstance(dataframe, pd.DataFrame): | ||
raise ValueError('Type Error : Expects pd.DataFrame for the parameter -> "dataframe"' | ||
) | ||
if len(dataframe.columns) == 0: | ||
raise ValueError('Data Error : The parameter -> "dataframe" is empty' | ||
) | ||
|
||
# This Drops the columns if columns are provided for the dataframe using parameter: drop_columns | ||
|
||
dataframe.drop(columns=drop_columns, inplace=True) | ||
|
||
# This drops empty values (NaN) if drop_na flag is set to True. | ||
|
||
dataframe.dropna(inplace=drop_na) | ||
|
||
# Initializes the target_dataframe | ||
|
||
target_dataframe = pd.DataFrame(dataframe[target_columns]) | ||
|
||
# If target_columns is provided target_columns are not encoded and removed from the input dataframe. | ||
|
||
if len(target_columns) > 0: | ||
dataframe.drop(columns=target_columns, inplace=True) | ||
|
||
for i in dataframe.columns: | ||
lst = dataframe[i].unique() | ||
dic = dict(zip(lst, range(1, len(lst) + 1))) | ||
dataframe[i] = dataframe[i].map(dic) | ||
|
||
# The normalize flag determines if it will be between 0-1 or 1 to no. of classes (1 - no. of classes). | ||
|
||
if normalize: | ||
dataframe[i] /= len(lst) | ||
|
||
# If target_columns is provided then it is returned as a Dataframe(Y) along with Input Dataframe(X). | ||
|
||
if len(target_columns) > 0: | ||
return (dataframe, target_dataframe) | ||
else: | ||
return dataframe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Inside of setup.cfg | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from distutils.core import setup | ||
setup( | ||
name = 'categorical_encode', | ||
packages = ['categorical_encode'], | ||
version = '0.1', | ||
license='MIT', | ||
description = 'This Library converts categorical data of any kind {integer, float, strings} into discrete values{1,2,3... # Classes}.', | ||
author = 'Nikhil Kala', | ||
author_email = 'nikhilkala8@gmail.com', | ||
url = 'https://github.com/nikhilkala/Categorical-Encode', | ||
download_url = 'https://github.com/nikhilkala/Categorical-Encode/archive/v0.1.tar.gz', | ||
keywords = ['Machine Learning', 'Categorical Data', 'Encoding', 'Deep Learning','Pandas', 'DataFrame', 'Normalization'], | ||
install_requires=[ | ||
'pandas', | ||
], | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development :: Build Tools', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8' | ||
], | ||
) |