0
0
NLPml~10 mins

SVM for 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 SVM classifier from scikit-learn.

NLP
from sklearn.[1] import SVC
Drag options to blanks, or click blank then click option'
Alinear_model
Bneighbors
Censemble
Dsvm
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from the wrong module like linear_model or ensemble.
Trying to import SVC directly from sklearn.
2fill in blank
medium

Complete the code to create an SVM classifier with a linear kernel.

NLP
model = SVC(kernel=[1])
Drag options to blanks, or click blank then click option'
A'linear'
B'rbf'
C'poly'
D'sigmoid'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rbf' or 'poly' which are other kernel types.
Forgetting the quotes around the kernel name.
3fill in blank
hard

Fix the error in the code to fit the SVM model on training data.

NLP
model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Atrain
Btransform
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' which is not a method.
Using 'predict' which is for making predictions, not training.
4fill in blank
hard

Fill both blanks to create a dictionary of predictions for each test sample and calculate accuracy.

NLP
predictions = model.[1](X_test)
accuracy = accuracy_score(y_test, [2])
Drag options to blanks, or click blank then click option'
Apredict
Bpredictions
Cfit
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' instead of 'predict' for predictions.
Passing the wrong variable to accuracy_score.
5fill in blank
hard

Fill all three blanks to create a TF-IDF vectorizer, transform text data, and train the SVM model.

NLP
vectorizer = TfidfVectorizer([1]=1, [2]=0.9)
X_train_tfidf = vectorizer.[3](train_texts)
model.fit(X_train_tfidf, train_labels)
Drag options to blanks, or click blank then click option'
Amin_df
Bfit_transform
Cmax_df
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of fit_transform on training data.
Mixing up min_df and max_df parameters.