Enrollments Open for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee

  Apply 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):


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],
        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...