Реализация Custom RandomSearchCV без использования sklearn - PullRequest
0 голосов
/ 21 января 2020

def RandomSearchCV (x_train, y_train, классификатор, param_range, folds): # x_train: его numpy массив формы, (n, d) # y_train: его numpy массив формы, (n,) или ( n, 1) # классификатор: обычно это KNeighborsClassifier () # param_range: это кортеж, похожий на (a, b) a #1.generate 10 unique values(uniform random distribution) in the given range "param_range" and store them as "params" # ex: if param_range = (1, 50), we need to generate 10 random numbers in range 1 to 50 #2.devide numbers ranging from 0 to len(X_train) into groups= folds # ex: folds=3, and len(x_train)=100, we can devide numbers from 0 to 100 into 3 groups group 1: 0-33, group 2:34-66, group 3: 67-100 #3.for each hyperparameter that we generated in step 1: # and using the above groups we have created in step 2 you will do cross-validation as follows # first we will keep group 1+group 2 i.e. 0-66 as train data and group 3: 67-100 as test data, and find train and test accuracies # second we will keep group 1+group 3 i.e. 0-33, 67-100 as train data and group 2: 34-66 as test data, and find train and test accuracies # third we will keep group 2+group 3 i.e. 34-100 as train data and group 1: 0-33 as test data, and find train and test accuracies # based on the 'folds' value we will do the same procedure # find the mean of train accuracies of above 3 steps and store in a list "train_scores" # find the mean of test accuracies of above 3 steps and store in a list "test_scores" #4. return both "train_scores" and "test_scores" 5. вызовите функцию RandomSearchCV (x_train, y_train, классификатор, param_range, folds) и сохраните возвращенные значения в "train_score" и "cv_scores" 6. построите график зависимости гиперпараметра от точности, как показано в справочном блокноте, и выберите лучший гиперпараметр 7. нанесите на карту границы решения для модели, инициализированной с наилучшим гиперпараметром, как показано в последней ячейке эталонной записной книжки

...