Complete the code to import the base class for creating a custom transformer in scikit-learn.
from sklearn.base import [1]
The BaseEstimator class is the base class to inherit from when creating custom transformers in scikit-learn.
Complete the code to define the fit method for a custom transformer class.
class MyTransformer(BaseEstimator, TransformerMixin): def fit(self, X, y=None): # No fitting needed, just return self return [1]
X instead of self.None which breaks chaining.The fit method should return self to allow method chaining in scikit-learn.
Fix the error in the transform method to correctly transform input data by doubling all values.
def transform(self, X): return X [1] 2
To double all values in X, multiply by 2 using the * operator.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
{word: [1] for word in words if len(word) [2] 3}word instead of len(word) as the dictionary value.< which filters wrong words.The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if count is greater than zero.
result = {{ [1]: [2] for word, count in word_counts.items() if count [3] 0 }}word.lower() instead of uppercase.< which filters wrong counts.The comprehension maps the uppercase version of each word (word.upper()) to its count (count) only if the count is greater than zero (> 0).