Halloween Sale: Flat 70% + Addl. 25% Off + 30 Days Extra Lab on all Courses | Use Coupon HS25 in Checkout | Offer Expires In

  Enroll Now

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_)

No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...