January 2018
Beginner to intermediate
316 pages
7h 14m
English
We will use the same structure as our custom category imputer. The main difference here is that we will utilize scikit-learn's Imputer class to actually make the transformation on our columns:
# Lets make an imputer that can apply a strategy to select columns by name from sklearn.preprocessing import Imputerclass CustomQuantitativeImputer(TransformerMixin): def __init__(self, cols=None, strategy='mean'): self.cols = cols self.strategy = strategy def transform(self, df): X = df.copy() impute = Imputer(strategy=self.strategy) for col in self.cols: X[col] = impute.fit_transform(X[[col]]) return X def fit(self, *_): return self
For our CustomQuantitativeImputer, we have added a strategy parameter that will allow us ...
Read now
Unlock full access