Aan de slagGa gratis aan de slag

Fitting and testing the model

In the previous exercise, you split the dataset into X_train, X_test, y_train, and y_test. These datasets have been pre-loaded for you. You'll now create a support vector machine classifier model (SVC()) and fit that to the training data. You'll then calculate the accuracy on both the test and training set to detect overfitting.

Deze oefening maakt deel uit van de cursus

Dimensionality Reduction in Python

Cursus bekijken

Oefeninstructies

  • Import SVC from sklearn.svm and accuracy_score from sklearn.metrics
  • Create an instance of the Support Vector Classification class (SVC()).
  • Fit the model to the training data.
  • Calculate accuracy scores on both train and test data.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import SVC from sklearn.svm and accuracy_score from sklearn.metrics
from ____ import ____
from ____ import ____

# Create an instance of the Support Vector Classification class
svc = ____

# Fit the model to the training data
svc.fit(____, ____)

# Calculate accuracy scores on both train and test data
accuracy_train = accuracy_score(____, svc.predict(____))
accuracy_test = accuracy_score(____, svc.predict(____))

print(f"{accuracy_test:.1%} accuracy on test set vs. {accuracy_train:.1%} on training set")
Code bewerken en uitvoeren