Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the necessary module for text vectorization.
ML Python
from sklearn.feature_extraction.text import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing CountVectorizer which counts words but doesn't weigh them.
Choosing LabelEncoder which is for labels, not text features.
Choosing train_test_split which is for splitting data.
✗ Incorrect
TfidfVectorizer converts text to numerical features based on term frequency and inverse document frequency, which is common in text classification.
2fill in blank
mediumComplete the code to split the dataset into training and testing sets.
ML Python
from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=[1], random_state=42)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1.0 which means all data is test set.
Using 0.5 which splits data evenly, less common for training.
Using 0.1 which is too small for testing.
✗ Incorrect
A test size of 0.2 means 20% of data is used for testing, which is a common practice.
3fill in blank
hardFix the error in the model training code by filling the blank with the correct method name.
ML Python
model = LogisticRegression()
model.[1](X_train, y_train) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' which is not a method in sklearn models.
Using 'fit_transform' which is for transformers, not models.
Using 'predict' which is for prediction, not training.
✗ Incorrect
The 'fit' method trains the model on the training data.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.
ML Python
{word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' which would select shorter words.
Using 'word' as value instead of its length.
Using 'len(word)' in the condition but not as value.
✗ Incorrect
We want the length of each word as the value, and only include words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if the count is greater than 1.
ML Python
{ [1]: [2] for [3] in word_counts if word_counts[[3]] > 1 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word.lower()' instead of uppercase.
Using the word itself as value instead of its count.
Using a variable name not in the loop.
✗ Incorrect
We map the uppercase version of each word to its count, iterating over words in word_counts, filtering counts greater than 1.