Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions feature_engine/creation/cyclical_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ class CyclicalFeatures(
https://towardsdatascience.com/cyclical-features-encoding-its-about-time-ce23581845ca

http://blog.davidkaleko.com/feature-engineering-cyclical-features.html

Examples
--------

>>> import pandas as pd
>>> from feature_engine.creation import CyclicalFeatures
>>> X = pd.DataFrame(dict(x= [1,4,3,3,4,2,1,2]))
>>> cf = CyclicalFeatures()
>>> cf.fit(X)
>>> cf.transform(X)
x x_sin x_cos
0 1 1.000000e+00 6.123234e-17
1 4 -2.449294e-16 1.000000e+00
2 3 -1.000000e+00 -1.836970e-16
3 3 -1.000000e+00 -1.836970e-16
4 4 -2.449294e-16 1.000000e+00
5 2 1.224647e-16 -1.000000e+00
6 1 1.000000e+00 6.123234e-17
7 2 1.224647e-16 -1.000000e+00
"""

def __init__(
Expand Down
30 changes: 30 additions & 0 deletions feature_engine/creation/math_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ class MathFeatures(BaseCreation):

In insurance, we can sum the damage to various parts of a car to obtain the
total damage.

Examples
--------

>>> import pandas as pd
>>> from feature_engine.creation import MathFeatures
>>> X = pd.DataFrame(dict(x1 = [1,2,3], x2 = [4,5,6]))
>>> mf = MathFeatures(variables = ["x1","x2"], func = "sum")
>>> mf.fit(X)
>>> mf.transform(X)
x1 x2 sum_x1_x2
0 1 4 5
1 2 5 7
2 3 6 9

>>> mf = MathFeatures(variables = ["x1","x2"], func = "prod")
>>> mf.fit(X)
>>> mf.transform(X)
x1 x2 prod_x1_x2
0 1 4 4
1 2 5 10
2 3 6 18

>>> mf = MathFeatures(variables = ["x1","x2"], func = "mean")
>>> mf.fit(X)
>>> mf.transform(X))
x1 x2 mean_x1_x2
0 1 4 2.5
1 2 5 3.5
2 3 6 4.5
"""

def __init__(
Expand Down
16 changes: 16 additions & 0 deletions feature_engine/creation/relative_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ class RelativeFeatures(BaseCreation):

- Ratio between income and debt to create the debt_to_income_ratio.
- Subtraction of rent from income to obtain the disposable_income.

Examples
--------

>>> import pandas as pd
>>> from feature_engine.creation import RelativeFeatures
>>> X = pd.DataFrame(dict(x1 = [1,2,3], x2 = [4,5,6], x3 = [3,4,5]))
>>> rf = RelativeFeatures(variables = ["x1","x2"],
>>> reference = ["x3"],
>>> func = ["div"])
>>> rf.fit(X)
>>> rf.transform(X)
x1 x2 x3 x1_div_x3 x2_div_x3
0 1 4 3 0.333333 1.333333
1 2 5 4 0.500000 1.250000
2 3 6 5 0.600000 1.200000
"""

def __init__(
Expand Down
14 changes: 14 additions & 0 deletions feature_engine/datetime/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ class DatetimeFeatures(BaseEstimator, TransformerMixin, GetFeatureNamesOutMixin)
--------
pandas.to_datetime
pandas.dt

Examples
--------

>>> import pandas as pd
>>> from feature_engine.datetime import DatetimeFeatures
>>> X = pd.DataFrame(dict(date = ["2022-09-18", "2022-10-27", "2022-12-24"]))
>>> dtf = DatetimeFeatures(features_to_extract = ["year", "month", "day_of_month"])
>>> dtf.fit(X)
>>> dtf.transform(X)
date_year date_month date_day_of_month
0 2022 9 18
1 2022 10 27
2 2022 12 24
"""

def __init__(
Expand Down