예제 #1
0
def CART_DE(dataset):

    dataset = normalize(dataset)
    mre_list = []
    sa_list = []

    for train, test in KFold_df(dataset, 3):

        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]

        # max_depth: [1:12], min_samples_leaf: [1:12], min_samples_split: [2:21]

        def cart_builder(a, b, c):
            model = DecisionTreeRegressor(max_depth=a,
                                          min_samples_leaf=b,
                                          min_samples_split=c)
            model.fit(train_input, train_actual_effort)
            test_predict_effort = model.predict(test_input)
            test_predict_Y = test_predict_effort
            test_actual_Y = test_actual_effort.values
            # mre_list.append(mre_calc(test_predict_Y, test_actual_Y))
            # sa_list.append(sa_calc(test_predict_Y, test_actual_Y))
            return mre_calc(test_predict_Y, test_actual_Y)  ############# MRE
            # return sa_calc(test_predict_Y, test_actual_Y)  ############# SA

        output = de(cart_builder,
                    bounds=[(1, 12), (0.00001, 0.5), (0.00001, 1)])
        mre_list.append(output)  ############# MRE
        # sa_list.append(output)  ############# SA

    return mre_list  ############# MRE
예제 #2
0
def CART(dataset, a=12, b=1, c=2):

    dataset = normalize(dataset)
    mre_list = []
    sa_list = []
    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]
        # max_depth: [1:12], min_samples_leaf: [1:12], min_samples_split: [2:21]

        model = DecisionTreeRegressor(max_depth=a,
                                      min_samples_leaf=b,
                                      min_samples_split=c)
        model.fit(train_input, train_actual_effort)
        test_predict_effort = model.predict(test_input)
        test_predict_Y = test_predict_effort
        test_actual_Y = test_actual_effort.values

        mre_list.append(mre_calc(test_predict_Y,
                                 test_actual_Y))  ######### for MRE
        sa_list.append(sa_calc(test_predict_Y,
                               test_actual_Y))  ######### for SA

    mre_mean = np.mean(mre_list)  ######### for MRE
    sa_mean = np.mean(sa_list)  ######### for SA

    return mre_mean  ######### for MRE
예제 #3
0
def CART_FLASH(dataset, metrics):
    dataset = normalize(dataset)
    score_list = []

    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]
        # max_depth: [1:12], min_samples_leaf: [1:12], min_samples_split: [2:21]

        output = flash(metrics, train_input, train_actual_effort, test_input,
                       test_actual_effort, 10)
        score_list.append(output)

    return score_list
예제 #4
0
def RF(dataset, max_depth=3):

    dataset = normalize(dataset)
    mre_list = []
    sa_list = []
    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]

        model = RandomForestRegressor(max_depth)
        model.fit(train_input, train_actual_effort)
        test_predict_effort = model.predict(test_input)
        test_predict_Y = test_predict_effort
        test_actual_Y = test_actual_effort.values

        mre_list.append(mre_calc(test_predict_Y,
                                 test_actual_Y))  ######### for MRE
        sa_list.append(sa_calc(test_predict_Y,
                               test_actual_Y))  ######### for SA

    return mre_list, sa_list
예제 #5
0
def SVM(dataset):

    dataset = normalize(dataset)
    mre_list = []
    sa_list = []
    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]

        model = svm.SVR(gamma='scale')
        model.fit(train_input, train_actual_effort)
        test_predict_effort = model.predict(test_input)
        test_predict_Y = test_predict_effort
        test_actual_Y = test_actual_effort.values

        mre_list.append(mre_calc(test_predict_Y,
                                 test_actual_Y))  ######### for MRE
        sa_list.append(sa_calc(test_predict_Y,
                               test_actual_Y))  ######### for SA

    return mre_list, sa_list
예제 #6
0
def KNN(dataset, n_neighbors=3):

    dataset = normalize(dataset)
    mre_list = []
    sa_list = []
    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_effort = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_effort = test.iloc[:, -1]

        model = neighbors.KNeighborsRegressor(n_neighbors)
        model.fit(train_input, train_actual_effort)
        test_predict_effort = model.predict(test_input)
        test_predict_Y = test_predict_effort
        test_actual_Y = test_actual_effort.values

        mre_list.append(mre_calc(test_predict_Y,
                                 test_actual_Y))  ######### for MRE
        sa_list.append(sa_calc(test_predict_Y,
                               test_actual_Y))  ######### for SA

    return mre_list, sa_list
def cart_classifier(dataset):

    dataset = normalize(dataset)
    detail_report = []
    for train, test in KFold_df(dataset, 3):
        train_input = train.iloc[:, :-1]
        train_actual_output = train.iloc[:, -1]
        test_input = test.iloc[:, :-1]
        test_actual_output = test.iloc[:, -1]

        model = DecisionTreeClassifier()
        # model = GaussianNB()
        # model = RandomForestClassifier()
        # model = SVC(gamma='scale')
        # model = KNeighborsClassifier()
        model.fit(train_input, train_actual_output)
        test_predict_output = model.predict(test_input)
        test_actual_output = test_actual_output.values
        # print(test_actual_output, "???")
        # print(test_predict_output, "!!!")
        detail_report = classification_report(test_actual_output, test_predict_output,
                                              target_names=['Unarchived', 'Archived'])

    return detail_report