Intent classification with sklearn
An array X containing vectors describing each of the sentences in the ATIS dataset has been created for you, along with a 1D array y containing the labels. The labels are integers corresponding to the intents in the dataset. For example, label 0 corresponds to the intent atis_flight.
Now, you'll use the scikit-learn library to train a classifier on this same dataset. Specifically, you will fit and evaluate a support vector classifier.
This exercise is part of the course
Building Chatbots in Python
Exercise instructions
- Import the
SVCclass fromsklearn.svm. - Instantiate a classifier
clfby callingSVCwith a single keyword argumentCwith value1. - Fit the classifier to the training data
X_trainandy_train. - Predict the labels of the test set,
X_test.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import SVC
____
# Create a support vector classifier
clf = ____
# Fit the classifier using the training data
____
# Predict the labels of the test set
y_pred = ____
# Count the number of correct predictions
n_correct = 0
for i in range(len(y_test)):
if y_pred[i] == y_test[i]:
n_correct += 1
print("Predicted {0} correctly out of {1} test examples".format(n_correct, len(y_test)))