This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
treat NaN value as a category for categorical value and temporarily u… (
#183) * treat NaN value as a category for categorical value and temporarily use CategoricalEncoder for Neither type
- Loading branch information
Showing
9 changed files
with
196 additions
and
49 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
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,53 @@ | ||
"""Fill NaNs.""" | ||
|
||
import numpy as np | ||
|
||
from foreshadow.base import BaseEstimator, TransformerMixin | ||
from foreshadow.utils import Constant | ||
from foreshadow.wrapper import pandas_wrap | ||
|
||
|
||
@pandas_wrap | ||
class NaNFiller(BaseEstimator, TransformerMixin): | ||
"""Fill NaN values in data.""" | ||
|
||
def __init__(self, fill_value=Constant.NAN_FILL_VALUE): | ||
self.fill_value = fill_value | ||
|
||
def fit(self, X, y=None): | ||
"""Empty fit. | ||
Args: | ||
X: input observations | ||
y: input labels | ||
Returns: | ||
self | ||
""" | ||
return self | ||
|
||
def transform(self, X, y=None): | ||
"""Fill nans in a column with defined fill_value. | ||
Args: | ||
X (:obj:`pandas.DataFrame`): X data | ||
y: input labels | ||
Returns: | ||
:obj:`pandas.DataFrame`: Transformed data | ||
""" | ||
return X.fillna(self.fill_value) | ||
|
||
def inverse_transform(self, X): | ||
"""Reverse nan filling transform. | ||
Args: | ||
X (:obj:`numpy.ndarray`): Transformed X data | ||
Returns: | ||
:obj:`numpy.ndarray`: Original data | ||
""" | ||
return X.replace(to_replace=Constant.NAN_FILL_VALUE, value=np.nan) |
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
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
Empty file.
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
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
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
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