def run_experiment(x, y, x_train, y_train, x_test, y_test, ds_name, class_list, max_depth=None): alphas = [10**-x for x in np.arange(-1, 9.01, 1)] # TODO: Allow for better tuning of hidden layers based on dataset provided d = min(x.shape[1], 5) hiddens = [(h, ) * l for l in [1, 2, 3] for h in [d, d // 2, d * 2]] learning_rates = sorted([(2**x) / 1000 for x in range(5)] + [0.000001]) params = { 'CLF__activation': ['relu', 'logistic'], 'CLF__alpha': alphas, 'CLF__learning_rate_init': learning_rates, 'CLF__hidden_layer_sizes': hiddens } clf = neural_network.MLPClassifier() pipe = Pipeline([('Scale', StandardScaler()), ('CLF', clf)]) cv = exp.basic_results(pipe, 'NeuralNet', ds_name, x_train, y_train, x_test, y_test, class_list, params) exp.make_complexity_curve(cv.best_estimator_, 'NeuralNet', ds_name, x, y, 'CLF__alpha', 'Alpha', alphas, 'log')
def run_experiment(x, y, x_train, y_train, x_test, y_test, ds_name, class_list, max_depth=None): neighbor_count = np.arange(1, 51, 1) params = { 'CLF__metric': ['manhattan', 'euclidean', 'chebyshev'], 'CLF__n_neighbors': neighbor_count, 'CLF__weights': ['uniform'] } clf = neighbors.KNeighborsClassifier() pipe = Pipeline([('Scale', StandardScaler()), ('CLF', clf)]) cv = exp.basic_results(pipe, 'KNN', ds_name, x_train, y_train, x_test, y_test, class_list, params) exp.make_complexity_curve(cv.best_estimator_, 'KNN', ds_name, x, y, 'CLF__n_neighbors', 'Neighbor count', neighbor_count, 'linear')
def run_experiment(x, y, x_train, y_train, x_test, y_test, ds_name, class_list, max_depth=None): n_estimators = np.arange(1, 51, 1) params = { 'CLF__n_estimators': n_estimators, 'CLF__learning_rate': [(2**x)/100 for x in range(7)]+[1]} clf = ensemble.AdaBoostClassifier(algorithm='SAMME') pipe = Pipeline([('Scale', StandardScaler()), ('CLF', clf)]) cv = exp.basic_results(pipe, 'BOOST', ds_name, x_train, y_train, x_test, y_test, class_list, params) exp.make_complexity_curve(cv.best_estimator_, 'BOOST', ds_name, x, y, 'CLF__n_estimators', 'Estimators', n_estimators, 'linear')
def run_experiment(x, y, x_train, y_train, x_test, y_test, ds_name, class_list, max_depth=None): if not max_depth: max_depth = np.arange(1, x_train.shape[1] * 2, 1) params = {'CLF__criterion': ['gini', 'entropy'], 'CLF__max_depth': max_depth, 'CLF__class_weight': ['balanced', None]} # , 'DT__max_leaf_nodes': max_leaf_nodes} clf = tree.DecisionTreeClassifier() pipe = Pipeline([('Scale', StandardScaler()), ('CLF', clf)]) cv = exp.basic_results(pipe, 'DT', ds_name, x_train, y_train, x_test, y_test, class_list, params) exp.make_complexity_curve(cv.best_estimator_, 'DT', ds_name, x, y, 'CLF__max_depth', 'Max Depth', max_depth, 'linear')
def run_experiment(x, y, x_train, y_train, x_test, y_test, ds_name, class_list): kernels = ['rbf', 'poly', 'sigmoid'] iters = [-1, int((1e6 / x.shape[0]) / .8) + 1] C_values = np.arange(0.001, 2.5, 0.25) params = { 'CLF__kernel': kernels, 'CLF__max_iter': iters, 'CLF__C': C_values } clf = svm.SVC() pipe = Pipeline([('Scale', StandardScaler()), ('CLF', clf)]) cv = exp.basic_results(pipe, 'SVC', ds_name, x_train, y_train, x_test, y_test, class_list, params) exp.make_complexity_curve(cv.best_estimator_, 'SVC', ds_name, x, y, 'CLF__kernel', 'Kernels', kernels, 'linear')