'Implement Hyperparameter Tuning in SVM
I would like to implement a function for SVM with the requirement:
Consider the binary classification that consists of distinguishing class 6 from the rest of the data points. Use SVMs combined with polynomial kernels to solve this classification problem. For each value of the polynomial degree, $d$ = 1, 2, 3, 4, plot the average 5-fold cross-validation error plus or minus one standard deviation as a function of $C$ (let the other parameters of the polynomial kernels be equal to their default values) on the training data.
def cross_validation_score(X, y, c_vals, n_folds, d_vals): """ Calculates the cross validation error and returns its mean and standard deviation.
Args:
X: features
y: labels
c_vals: list of C values
n_folds: number of cross-validation folds
d_vals: list of degrees of the polynomial kernel
Returns:
Tuple of (list of error_mean, list of error_std)
"""
error_mean = np.zeros((len(c_vals),len(d_vals)))
error_std = np.zeros((len(c_vals),len(d_vals)))
////code in here
return error_mean, error_std
Can anyone help me to implement that function? Thanks!
I have try to follow cross_val_error function from scikit-learn but it's quite complicated for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
