def add_sequential(name, models, X_train, Y_train, X_test, Y_test): # Establish and reset variables acc_score_cv = None acc_score = None time_ = None ensemble = SequentialEnsemble(scorer=accuracy_score, random_state=seed) # Add a subsemble with 5 partitions as first layer ensemble.add('subsemble', models, partitions=10, folds=10) # Add a super learner as second layer ensemble.add('stack', models, folds=20) ensemble.add_meta(SVC()) start = time.time() ensemble.fit(X_train, Y_train) preds = ensemble.predict(X_test) acc_score = accuracy_score(preds, Y_test) end = time.time() time_ = end - start return { "Ensemble": name, "Meta_Classifier": "SVC", "Accuracy_Score": acc_score, "Runtime": time_ }
def build_ensemble(**kwargs): sc = StandardScaler() ests_1 = [('rfr', RandomForestRegressor(n_estimators=5)), ('rdg', Ridge(tol=1e-4, max_iter=4000)), ('mlr', MLPRegressor((100, 20), max_iter=1000))] ests_2 = [ ('rdg', Ridge(tol=1e-4, max_iter=4000)), ('svr', SVR(tol=1e-4, kernel='linear', degree=5, max_iter=4000)), ] ensemble = SequentialEnsemble(**kwargs, shuffle=False) ensemble.add( "blend", ests_1, preprocessing=[sc], ) ensemble.add("stack", ests_2, preprocessing=[sc]) ensemble.add_meta([('etc', ExtraTreesClassifier(n_estimators=5))]) return ensemble
# 'case-3': [pca], # 'case-4': [fa] } score = make_scorer(score_func=accuracy_score, greater_is_better=True, needs_proba=False, needs_threshold=False) ensemble = SequentialEnsemble(model_selection=True, n_jobs=1, shuffle=False, random_state=seed) ensemble.add('stack', ests_1, preprocessing=pre_cases) ensemble.add_meta(SVC(kernel='linear', degree=5, tol=1e-4)) # ensemble.fit(X_train, y_train) # y_pred = ensemble.predict(X_test) # ens = ensemble evaluator = Evaluator(scorer=score, random_state=seed, verbose=True) evaluator.fit(data_pix, spacial_pix, estimators=[], param_dicts=pars_1, n_iter=5, preprocessing=pre_cases) print(evaluator.results) spacial_pix = spacial_pix.astype('int') unique, counts = np.unique(y_test, return_counts=True)
'case-1.bag': { 'n_estimators': f, } } pre_cases = { # 'case-1': [], 'case-1': [StandardScaler()] } # scorer = make_scorer(r2_score, greater_is_better=False, needs_proba=False, needs_threshold=False) ensemble = SequentialEnsemble(model_selection=False, n_jobs=3, shuffle=True, random_state=seed, scorer=mean_absolute_error) ensemble.add('blend', ests, preprocessing=pre_cases) ensemble.add_meta(SVR()) # ensemble.fit(X_train, y_train) # y_pred = ensemble.predict(X_test) # print(mean_absolute_error(y_test, y_pred)) # ests = [ensemble] # evaluator = Evaluator(scorer=scorer, random_state=seed, verbose=3, cv=4, n_jobs=1) # evaluator.fit(X=image_set, y=label_set, estimators=ests, param_dicts=pars_1, # n_iter=40, preprocessing=pre_cases) # # print(evaluator.results)