Package of some useful ML functions and tools
Project description
synergos
set of tools to improve ML tasks in sklearn and tensorflow
Installation
Run the following to install:
$ pip install synergos
Usage of functions
PercentileTargetEncoder
PercentileTargetEncoder is used for encoding categorical values by changing values to percentiles of distribution inspration from: https://maxhalford.github.io/blog/target-encoding/
THE MOST IMPORTANT FEATURES OF THE ENCODER:
- DO NOT EXPAND NUMBER OF FEATURES IN UNCONTROLLED WAY FOR HIGH CARDINALITY DATA LIKE IN ONE-HOT ENCODING
- AUTOMATICALLY ENCODE RARE, MISSING AND UNKNOWN LABELS
- OVERFITTING CONTROLLED BY PARAMETER: m, 1<=m<np.Inf
- DISTRIBUTION SHAPE CAN BE ANALYSED BY PARAMETER: p (p=[0.1, 0.5, 0.9])
- COMPATIBILITY WITH SKLEARN PIPELINES
- NEEDS 'TARGET' VALUES - FOR USE IN SUPERVISED LEARNING
- 'TARGET' DISTRIBUTION SHAPE CEN BE NORMALIZED AUTOMATICALLY BY PARAMETER use_internal_yeo_johnson=True
PARAMETERS features: list of features for encoding, if None transformer find categorical values automatically
ignored_features: list of ignored features when features are found automatically with option features = None
p: percentil value to calculate new feature, default value is 0.5 (median), range 0<p<1, single value or list of values
m: regularization parameter to prevent overfitting, default value is 1, int in range for 1 to np.inf, single value or list of values
remove_original: if True original categorical value is dropped, default value is True
return_df: if True pd.Dataframe as return, if False np.array as return, default value is True
use_internal_yeo_johnson: if True, yeo-johnson transformation is used to normalize 'Target' before encoding, default value is True
import pandas as pd
from synergos.transformers import PercentileTargetEncoder
if __name__ == '__main__':
df = pd.DataFrame({
'x_0': ['a'] * 5 + ['b'] * 5,
'x_1': ['c'] * 9 + ['d'] * 1,
'y': [1, 1, 1, 1, 0, 1, 0, 0, 0, 0]
})
print(df.head(10))
pte = PercentileTargetEncoder(features=None,
ignored_features=None,
p=[0.8], m=[3],
remove_original=True,
return_df=True,
use_internal_yeo_johnson=False)
out = pte.fit_transform(X=df[['x_0', 'x_1']], y=df['y'])
print(out)
df_test = pd.DataFrame({
'x_0': ['a'] * 5 + ['V'] * 1 + ['b'] * 4,
'x_1': ['c'] * 8 + [''] * 1 + ['d'] * 1,
'y': [1, 1, 1, 1, 0, 1, 0, 0, 0, 0]
})
out_test = pte.transform(X=df_test)
print(out_test)
yeo_johnson_inverse
param: features: list of features for encoding, if None transformer find categorical values automatically
from synergos.functions import yeo_johnson_inverse
if __name__ == '__main__':
x = [-0.66666667, -0.5, 0., 2.33333333, 8.66666667]
lmbda = 2.5
y = yeo_johnson_inverse(x, lmbda)
print(y)
Developing Synergos
To install Synergos, along the tools you need to develop and run tests, run the following in your virtualenv:
$ pip install -e .[dev]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synergos-0.0.3.tar.gz.
File metadata
- Download URL: synergos-0.0.3.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23dcde03d5c0bb6eb056cd6128344a0366714a96298ed5ed0aacedd93220694d
|
|
| MD5 |
e5c1f4a225d44acbb8c9ef0c96961416
|
|
| BLAKE2b-256 |
c75d0b94626dd15eb9dc8058cc536cf7179decc0150d6dcc2a4e714852d1bfc8
|
File details
Details for the file synergos-0.0.3-py3-none-any.whl.
File metadata
- Download URL: synergos-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
307250b3375cb3adf7dda4fed5c95665d0df5afda2a75c7a8ae259925f52b64a
|
|
| MD5 |
f33088e083c027f66b71ca996fc6ad57
|
|
| BLAKE2b-256 |
2eb4985c1a0994c92b9eef4dd3189d0d7de3fb7bcfa3c654415874656e72ccba
|