October 2018
Intermediate to advanced
172 pages
4h 6m
English
In order to optimize the inverse regularization strength, we will plot the accuracy scores for the training and testing sets, using the following code:
import matplotlib.pyplot as plt from sklearn.svm import LinearSVCtraining_scores = []testing_scores = []param_list = [0.0001, 0.001, 0.01, 0.1, 10, 100, 1000]# Evaluate the training and test classification errors for each value of the parameterfor param in param_list: # Create SVM object and fit svm = LinearSVC(C = param, random_state = 42) svm.fit(X_train, y_train) # Evaluate the accuracy scores and append to lists training_scores.append(svm.score(X_train, y_train) ) testing_scores.append(svm.score(X_test, y_test) ) # Plot resultsplt.semilogx(param_list, ...
Read now
Unlock full access