0
0
NLPml~10 mins

Multi-class text classification in NLP - 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 library for text vectorization.

NLP
from sklearn.feature_extraction.text import [1]
Drag options to blanks, or click blank then click option'
ACountVectorizer
BLabelEncoder
Ctrain_test_split
DTfidfVectorizer
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'CountVectorizer' which counts word occurrences but doesn't weigh them.
Selecting 'LabelEncoder' which is for encoding labels, not text features.
2fill in blank
medium

Complete the code to split data into training and testing sets.

NLP
from sklearn.model_selection import [1]
X_train, X_test, y_train, y_test = [1](X, y, test_size=0.2, random_state=42)
Drag options to blanks, or click blank then click option'
Atrain_test_split
Bcross_val_score
CGridSearchCV
DKFold
Attempts:
3 left
💡 Hint
Common Mistakes
Using cross-validation functions instead of splitting data.
Confusing with KFold which is for cross-validation, not simple splitting.
3fill in blank
hard

Fix the error in the model training code by filling the blank with the correct classifier.

NLP
from sklearn.linear_model import [1]
model = [1]()
model.fit(X_train, y_train)
Drag options to blanks, or click blank then click option'
ALinearRegression
BLogisticRegression
CKNeighborsClassifier
DDecisionTreeRegressor
Attempts:
3 left
💡 Hint
Common Mistakes
Using regression models for classification tasks.
Choosing classifiers that are not imported or mismatched.
4fill in blank
hard

Fill both blanks to create a dictionary of word counts for words longer than 3 characters.

NLP
word_counts = {word: [1] for word in text.split() if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Atext.count(word)
B>
C>=
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator like '<' or '<='.
Using the length of the word as the value instead of the count.
5fill in blank
hard

Fill all three blanks to create a dictionary of words and their counts for words longer than 4 characters.

NLP
filtered_counts = [1]{word: [2] for word in words if len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Adict(
Bwords.count(word)
C>
Dlist(
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or <= instead of > for filtering word length.
Using list() instead of dict() to create the dictionary.