Question: Do a grid-search over a predefined range of the parameters. Loop over all possible combinations of parameters, estimate the accuracy of your model using K-Folds

Do a grid-search over a predefined range of the parameters. Loop over all possible combinations of parameters, estimate the accuracy of your model using K-Folds cross-validation, and then choose the parameter combination that produces the highest validation accuracy.

Do a grid-search over a predefined range of the parameters. Loop over

TO DO 1:

from sklearn.model_selection import cross_val_score, GridSearchCV grid=None # ToDo: replace it to proper GridSearchCV object and run the grid search with cross validation

# complete your code here

TO DO 2: The GridSearchCV object scores, among other things, the best combination of parameters as well as the cross-validation accuracy achieved with those parameters. Print those quantities for our model.

TO DO 3: The GridSearchCV object also stores the classifier trained with the best hyperparameters. Pass this best estimator into the nonlinear_plot function to view the best decision boundary. What can you tell about the best decision boundary?

DATA TO BE USED:

def part3data(N=100, seed=1235): np.random.seed(seed) X = np.random.uniform(-1,1,(N,2)) y = np.array([1 if y-x > 0 else -1 for (x,y) in zip(X[:,0]**2 * np.sin(2*np.pi*X[:,0]), X[:,1])]) X = X + np.random.normal(0,.1,(N,2)) return X, y

X, y = part3data(N=300, seed=1235)

MODEL TO BE USED:

nlsvm = SVC(kernel="rbf", C=1, gamma=1) nlsvm.fit(X, y)

Part A: Below is an experiment where we search over a logarithmic range between 25 and 25 for C and a range between 25 and 25 for . For the accuracy measure we use K-Folds CV with K=3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!