0
0
NLPml~10 mins

Logistic regression for text 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 logistic regression model from scikit-learn.

NLP
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
ALogisticRegression
BLinearRegression
CDecisionTreeClassifier
DKNeighborsClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing LinearRegression which is for regression, not classification.
Confusing with other classifiers like DecisionTreeClassifier.
2fill in blank
medium

Complete the code to convert text data into numerical features using CountVectorizer.

NLP
from sklearn.feature_extraction.text import [1]
Drag options to blanks, or click blank then click option'
ACountVectorizer
BDictVectorizer
CTfidfVectorizer
DLabelEncoder
Attempts:
3 left
💡 Hint
Common Mistakes
Using TfidfVectorizer when the task asks specifically for count-based features.
Using LabelEncoder which is for labels, not text features.
3fill in blank
hard

Fix the error in the code to train the logistic regression model on vectorized text data.

NLP
model = LogisticRegression()
X_train_vec = vectorizer.fit_transform(X_train)
model.[1](X_train_vec, y_train)
Drag options to blanks, or click blank then click option'
Apredict
Bscore
Ctransform
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using predict instead of fit causes errors because the model is not trained yet.
Using transform which is a method for vectorizers, not models.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their counts only if the count is greater than 2.

NLP
word_counts = {word: [1] for word, count in counts.items() if count [2] 2}
Drag options to blanks, or click blank then click option'
Acount
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word as the value instead of count.
Using < instead of > in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of word lengths for words longer than 4 characters.

NLP
lengths = [1]: [2] for [3] in words if len([3]) > 4}
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using item as the loop variable but not matching keys and values.
Using len(item) without defining item.