def train_and_predict(self, param_dict, predict_on='val'):
"""Initializes a LR 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 = linear_model.LogisticRegression(penalty=param_dict['penalty'],
C=param_dict['C'])
self.model.fit(self.data_loader.train_X, self.data_loader.train_Y)
preds = self.predict_on_data(predict_X)
return preds
logistic_regression.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录