コード例 #1
0
def algo_run(model, pre_processing_pipeline, scaler, sampler, seed):

    start_time = datetime.datetime.now()

    df = utils.get_dataset()
    df = pre_processing_pipeline[1](df)

    X, y = utils.X_y_split(df)

    if "Keras" in model[0]:
        model_eval = model[1][:-1] + ",input_dim=" + str(X.shape[1]) + ")"
    else:
        model_eval = model[1]

    model_eval = eval(model_eval)
    try:
        y_predicted = utils.cross_validation_average_results(
            model_eval,
            X,
            y,
            n_splits=5,
            scaler=scaler[1],
            sampling_technique=sampler[1])
        threshold = utils.max_threshold(y_predicted,
                                        y,
                                        threshold_range=(0.2, 0.6),
                                        iterations=1000,
                                        visualization=False)
        y_pred = utils.predict_with_threshold(y_predicted, threshold)
        result = utils.profit_share(y_pred, y)
        precision = utils.calculate_precision_score(y_pred, y)
        recall = utils.calculate_recall_score(y_pred, y)
    except:
        result = -1
        recall = -1
        precision = -1

    time_elapsed = datetime.datetime.now() - start_time

    # Create result string
    result_string = ",".join([
        str(seed), model[0], pre_processing_pipeline[0], scaler[0], sampler[0],
        str(time_elapsed),
        str(precision),
        str(recall),
        str(result)
    ])
    # Write result to a file
    with open(file_name, "a") as myfile:
        myfile.write(result_string + "\n")
    # Output result to terminal
    print(model[0] + ": " + str(result))
    if result > 0.6:
        print(
            "!!!!!!!!!!!!!!!!!!!!!!!!!yey!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"
        )
コード例 #2
0
def algo_run(model, pre_processing_pipeline, scaler, sampler, seed):

    start_time = datetime.datetime.now()

    df = utils.get_dataset()
    if pre_processing_pipeline[1] != None:
        df = pre_processing_pipeline[1](df)
    X, y = utils.X_y_split(df)

    if "Keras" in model[0]:
        model_eval = model[1][:-1] + ",input_dim=" + str(X.shape[1]) + ")"
    elif "GP" in model[0]:
        model_eval = model[1][:-1] + ",random_state=" + str(
            seed) + ",feature_names=" + str(list(X.columns)) + ")"
    elif "Tree" in model[0]:
        model_eval = model[1][:-1] + ",random_state=" + str(seed) + ")"
    elif "XG" in model[0]:
        model_eval = model[1][:-1] + ",seed=" + str(seed) + ")"
    else:
        model_eval = model[1]

    model_eval = eval(model_eval)

    y_predicted = utils.cross_validation_average_results(
        model_eval,
        X,
        y,
        n_splits=5,
        scaler=scaler[1],
        sampling_technique=sampler[1])
    mean_s_error = utils.calculate_mean_absolute_error(y_predicted, y)
    explained_variance = utils.calculate_explained_variance_score(
        y_predicted, y)

    time_elapsed = datetime.datetime.now() - start_time

    # Create result string
    result_string = ",".join([
        str(seed), model[0], pre_processing_pipeline[0], scaler[0], sampler[0],
        str(time_elapsed),
        str(mean_s_error),
        str(explained_variance)
    ])
    # Write result to a file
    with open(file_name, "a") as myfile:
        myfile.write(result_string + "\n")

    print(model[0] + ": " + str(mean_s_error))

    if 'GS_GP' in model[1]:
        idx = model_eval._program.parents['parent_idx']
        fade_nodes = model_eval._program.parents['parent_nodes']
        print(model_eval._programs[-2][idx])
コード例 #3
0
def algo_run(seed, model):

    start_time = datetime.datetime.now()

    df = utils.get_dataset()

    X, y = utils.X_y_split(df)

    model_eval = add_seed(model, seed, X)

    model_eval = eval(model_eval)

    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        test_size=0.20,
                                                        random_state=seed)

    model_eval.fit(X_train, y_train)
    y_predicted = model_eval.predict(X_test)

    mean_s_error = utils.calculate_mean_absolute_error(y_predicted, y_test)
    explained_variance = utils.calculate_explained_variance_score(
        y_predicted, y_test)

    time_elapsed = datetime.datetime.now() - start_time

    # Create result string
    log_parameters = [
        seed, model[0], time_elapsed, mean_s_error, explained_variance
    ]

    if 'GS_GP' in model[0]:
        #idx = model_eval._program.parents['parent_idx']
        if "p_gs_crossover=0.0" in model[0]:
            fade_nodes = model_eval._program.parents['parent_nodes']
        #log_parameters.append(len(model_eval._programs[-2][idx].program))

    result_string = ",".join([str(value) for value in log_parameters])
    # Write result to a file
    with open(file_name, "a") as myfile:
        myfile.write(result_string + "\n")

    print(result_string)