def quantile_transform(): a, b = _randint(100, 1000), _randint(1000, 1e5) c = _randchoice(['normal', 'uniform']) scaler = QuantileTransformer(n_quantiles=a, output_distribution=c, subsample=b) tmp = str(a) + "_" + str(b) + "_" + c + "_" + QuantileTransformer.__name__ return scaler, tmp
def mutate_classifier(self, best_classifier, worst_classifier): best_params = best_classifier.get_params() worst_params = worst_classifier.get_params() mutated_params = {} for k, v in best_params.items(): if isinstance(v, float): mutated_params[k] = _randuniform( best_params[k], (best_params[k] + worst_params[k]) / 2) elif isinstance(v, int): mutated_params[k] = _randint( best_params[k], int( (best_params[k] + worst_params[k]) / 2)) else: mutated_params[k] = best_params[k] # for k,v in best_params.items(): # print('best param = ', k,v) # for k,v in mutated_params.items(): # print('mutated param = ', k,v) mutated_classifier = new_classifier(best_classifier) mutated_classifier.set_params(**mutated_params) return mutated_classifier
def polynomial(): a = _randint(2,10) b = _randchoice([True, False]) c = _randchoice([True, False]) scaler=PolynomialFeatures(degree=a, interaction_only=b, include_bias=c) tmp = str(a) + "_" + str(b) + "_" + str(c)+ "_"+PolynomialFeatures.__name__ return scaler, tmp
def KNN(): a = _randint(2, 25) b = _randchoice(['uniform', 'distance']) c = _randchoice(['minkowski', 'chebyshev']) if c == 'minkowski': d = _randint(1, 15) else: d = 2 model = KNeighborsClassifier(n_neighbors=a, weights=b, algorithm='auto', p=d, metric=c, n_jobs=-1) tmp = str(a) + "_" + b + "_" + c + "_" + str( d) + "_" + KNeighborsClassifier.__name__ return model, tmp
def LR(): a = _randchoice(['l2']) b = _randuniform(0.0, 0.1) c = _randint(1, 500) # model = LogisticRegression(penalty=a, tol=b, C=float(c), solver='liblinear', multi_class='warn') model = LogisticRegression(penalty=a, tol=b, C=float(c)) tmp = a + "_" + str(round( b, 5)) + "_" + str(c) + "_" + LogisticRegression.__name__ return model, tmp
def SVM(): # from sklearn.preprocessing import MinMaxScaler # scaling = MinMaxScaler(feature_range=(-1, 1)).fit(train_data) # train_data = scaling.transform(train_data) # test_data = scaling.transform(test_data) a = _randint(1, 500) b = _randchoice(['linear', 'poly', 'rbf', 'sigmoid']) c = _randint(2, 10) d = _randuniform(0.0, 1.0) e = _randuniform(0.0, 0.1) f = _randuniform(0.0, 0.1) model = SVC(C=float(a), kernel=b, degree=c, gamma=d, coef0=e, tol=f, cache_size=20000) tmp = str(a) + "_" + b + "_" + str(c) + "_" + str(round(d, 5)) + "_" + str( round(e, 5)) + "_" + str(round(f, 5)) + "_" + SVC.__name__ return model, tmp
def RF(): a = _randint(50, 150) b = _randchoice(['gini', 'entropy']) c = _randuniform(0.0, 1.0) model = RandomForestClassifier(n_estimators=a, criterion=b, min_samples_split=c, max_features=None, min_impurity_decrease=0.0, n_jobs=-1) tmp = str(a) + "_" + b + "_" + str(round( c, 5)) + "_" + RandomForestClassifier.__name__ return model, tmp
def mutate_preprocessor(self, best_preprocessor, worst_preprocessor): best_params = best_preprocessor.get_params() worst_params = worst_preprocessor.get_params() mutated_params = {} for k, v in best_params.items(): if isinstance(v, float): mutated_params[k] = _randuniform( best_params[k], (best_params[k] + worst_params[k]) / 2) elif isinstance(v, int): mutated_params[k] = _randint( best_params[k], (best_params[k] + worst_params[k]) / 2) else: mutated_params[k] = best_params[k] mutated_preprocessor = new_preprocessor(best_preprocessor) mutated_preprocessor.set_params(**best_params) return mutated_preprocessor
def robust_scaler(): a,b=_randint(0,50),_randint(51,100) scaler = RobustScaler(quantile_range=(a, b)) tmp=str(a)+"_"+str(b)+"_"+RobustScaler.__name__ return scaler, tmp