Project - Predicting Titanic Passenger Survival using Machine Learning and Python

You are currently auditing this course.
12 / 21

Titanic Machine Learning Project - Create an Imputer for String Categorical Columns

We will also need an imputer for the string categorical columns (the regular SimpleImputer does not work on those):

INSTRUCTIONS

Now let's create a class named MostFrequentImputer for the imputer:

class << your code comes here >> (BaseEstimator, TransformerMixin):
    def fit(self, X, y=None):
        self.most_frequent_ = pd.Series([X[c].value_counts().index[0] for c in X],
                                        index=X.columns)
        return self
    def transform(self, X, y=None):
        return X.fillna(self.most_frequent_)
Get Hint See Answer

Loading comments...