Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from the wrong module like linear_model or ensemble.
Trying to import SVC directly from sklearn.
✗ Incorrect
The SVM classifier is in the svm module of scikit-learn.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rbf' or 'poly' which are other kernel types.
Forgetting the quotes around the kernel name.
✗ Incorrect
The linear kernel is specified by the string 'linear'.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' which is not a method.
Using 'predict' which is for making predictions, not training.
✗ Incorrect
The method to train the model is fit.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' instead of 'predict' for predictions.
Passing the wrong variable to accuracy_score.
✗ Incorrect
Use predict to get predictions, then pass them to accuracy_score to compute accuracy.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of fit_transform on training data.
Mixing up min_df and max_df parameters.
✗ Incorrect
min_df and max_df set frequency thresholds for words. fit_transform learns vocabulary and transforms texts.