Get Started

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 is a part of the course

“Building Chatbots in Python”

View Course

Exercise instructions

  • Import the SVC class from sklearn.svm.
  • Instantiate a classifier clf by calling SVC with a single keyword argument C with value 1.
  • Fit the classifier to the training data X_train and y_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)))

This exercise is part of the course

Building Chatbots in Python

IntermediateSkill Level
4.2+
5 reviews

Learn the fundamentals of how to build conversational bots using rule-based systems as well as machine learning.

Here, you'll use machine learning to turn natural language into structured data using spaCy, scikit-learn, and rasa NLU. You'll start with a refresher on the theoretical foundations and then move onto building models using the ATIS dataset, which contains thousands of sentences from real people interacting with a flight booking system.

Exercise 1: Understanding intents and entitiesExercise 2: Intent classification with regex IExercise 3: Intent classification with regex IIExercise 4: Entity extraction with regexExercise 5: Word vectorsExercise 6: word vectors with spaCyExercise 7: Intents and classificationExercise 8: Intent classification with sklearn
Exercise 9: Entity extractionExercise 10: Using spaCy's entity recognizerExercise 11: Assigning roles using spaCy's parserExercise 12: Robust language understanding with rasa NLUExercise 13: Rasa NLUExercise 14: Data-efficient entity recognition

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free