def knn(self,
scoring_metric='roc_auc',
hyperparameter_grid=None,
randomized_search=True,
number_iteration_samples=10):
"""
A light wrapper for Sklearn's knn classifier that performs randomized search over an overridable default
hyperparameter grid.
Args:
scoring_metric (str): Any sklearn scoring metric appropriate for classification
hyperparameter_grid (dict): hyperparameters by name
randomized_search (bool): True for randomized search (default)
number_iteration_samples (int): Number of models to train during the randomized search for exploring the
hyperparameter space. More may lead to a better model, but will take longer.
Returns:
TrainedSupervisedModel:
"""
self.validate_classification('KNN')
if hyperparameter_grid is None:
neighbors = list(range(5, 26))
hyperparameter_grid = {'n_neighbors': neighbors, 'weights': ['uniform', 'distance']}
number_iteration_samples = 10
print('KNN Grid: {}'.format(hyperparameter_grid))
algorithm = get_algorithm(KNeighborsClassifier,
scoring_metric,
hyperparameter_grid,
randomized_search,
number_iteration_samples=number_iteration_samples)
trained_supervised_model = self._create_trained_supervised_model(algorithm)
return trained_supervised_model
advanced_supvervised_model_trainer.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录