0
0
ML Pythonml~10 mins

Text classification pipeline in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ATfidfVectorizer
Btrain_test_split
CLabelEncoder
DCountVectorizer
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.
2fill in blank
medium

Complete 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'
A0.2
B0.5
C0.1
D1.0
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.
3fill in blank
hard

Fix 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'
Atrain
Bpredict
Cfit_transform
Dfit
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.
4fill in blank
hard

Fill 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'
Alen(word)
B<
C>
Dword
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.
5fill in blank
hard

Fill 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'
Aword.upper()
Bword_counts[word]
Cword
Dword.lower()
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.