Question: Machine Learning SVM Hyperparameter Tuning You May import any type of data you want. 1. Using GridSearchCV, determine the best choice of hyperparameters out of
Machine Learning
SVM Hyperparameter Tuning
You May import any type of data you want.
1. Using GridSearchCV, determine the best choice of hyperparameters out of the following possible values:
Kernel type: Linear, radial basis function
Box constraint (C): [1, 5, 10, 20]
Kernel width (gamma): 'auto','scale'
2. Report the time required to perform cross-validation via GridSearchCV. Report the mean and standard deviation of the performance metrics for the best performing model along with its associated hyperparameters. You may use the function collate_ht_results for this purpose.
Code::
#Summarizes model performance results produced during hyperparameter tuning
def collate_ht_results(ht_results,metric_keys=metric_keys,display=True):
ht_stats=dict()
for metric in metric_keys:
ht_stats[metric+"_mean"] = ht_results.cv_results_["mean_test_"+metric][ht_results.best_index_]
ht_stats[metric+"_std"] = metric_std = ht_results.cv_results_["std_test_"+metric][ht_results.best_index_]
if display:
print("test_"+metric,ht_stats[metric+"_mean"],"("+str(ht_stats[metric+"_std"])+")")
return ht_stats
UPDATE::
You can use any data set. if you need, 3 choices
#generate random data
rows, cols = 50, 5
r = np.random.RandomState(0)
y = r.randn(rows)
X = r.randn(rows, cols)
----------------------------------------
from sklearn import datasets
# FEATCHING FEATURES AND TARGET VARIABLES IN ARRAY FORMAT.
cancer = datasets.load_breast_cancer()
# Input_x_Features.
x = cancer.data
# Input_ y_Target_Variable.
y = cancer.target
# Feature Scaling for input features.
scaler = preprocessing.MinMaxScaler()
x_scaled = scaler.fit_transform(x)
---------------------------------------------
import numpy as np
X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]]) y = np.array([0, 0, 1, 1])
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
