0
0
ML Pythonml~10 mins

Sentiment analysis with scikit-learn 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 class used to convert text data into numbers.

ML Python
from sklearn.feature_extraction.text import [1]
Drag options to blanks, or click blank then click option'
ALinearRegression
BCountVectorizer
CKMeans
DDecisionTreeClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a regression or clustering class instead of a text vectorizer.
Confusing the vectorizer with a classifier.
2fill in blank
medium

Complete the code to create a logistic regression model for sentiment classification.

ML Python
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
ALinearRegression
BSVC
CLogisticRegression
DRandomForestClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Using linear regression which is for continuous values, not classification.
Choosing clustering or tree-based models by mistake.
3fill in blank
hard

Fix the error in the code to fit the vectorizer on the training text data.

ML Python
vectorizer = CountVectorizer()
vectorizer.[1](train_texts)
Drag options to blanks, or click blank then click option'
Afit
Btransform
Cpredict
Dfit_transform
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform before fitting causes errors.
Using predict on the vectorizer which is not a model.
4fill in blank
hard

Fill both blanks to transform training texts and train the logistic regression model.

ML Python
X_train = vectorizer.[1](train_texts)
model.[2](X_train, train_labels)
Drag options to blanks, or click blank then click option'
Afit_transform
Bfit
Ctransform
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform without fitting vectorizer first.
Trying to predict before training the model.
5fill in blank
hard

Fill all three blanks to predict sentiment on test data and calculate accuracy.

ML Python
X_test = vectorizer.[1](test_texts)
predictions = model.[2](X_test)
accuracy = accuracy_score(test_labels, [3])
Drag options to blanks, or click blank then click option'
Atransform
Bpredict
Cpredictions
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit on test data which leaks training info.
Passing wrong variable to accuracy function.