def train_and_predict(self, param_dict, predict_on='val'):
"""Initializes an SVM classifier according to the desired parameter settings,
trains it, and returns the predictions on the appropriate evaluation dataset.
Args:
param_dict: A dictionary with keys representing parameter names and
values representing settings for those parameters.
predict_on: The dataset used for evaluating the model. Can set to
'Test' to get final results.
Returns: The predicted Y labels.
"""
if predict_on == 'test':
predict_X = self.data_loader.test_X
else:
predict_X = self.data_loader.val_X
self.model = SVC(C=param_dict['C'], kernel=param_dict['kernel'], gamma=param_dict['beta'])
self.model.fit(self.data_loader.train_X, self.data_loader.train_Y)
preds = self.predict_on_data(predict_X)
return preds
评论列表
文章目录