def useLRtoPredictScore(targetFileName, exam_mark=None, needNorm=True):
    if exam_mark is None:
        exam_mark = DATA_MARK

    _file_Relative_Path = os.path.join(exam_mark, targetFileName)
    student_data, headerArray = load_data_from_file(_file_Relative_Path)

    _score_map = get_final_score_map()
    _score_array = []
    for _student_record in student_data:
        _score_array.append(_score_map[_student_record[0]])

    targetFeatureIndexArray = [i for i in range(1, headerArray.__len__())]
    featureMatrix = getSerevalColumn(student_data, targetFeatureIndexArray)

    if needNorm:
        featureMatrix = normizeMatrix(featureMatrix)

    _lr = LinearRegression(fit_intercept=True)
    _lr.fit(featureMatrix, _score_array)
    y_predicted = _lr.predict(featureMatrix)
    # y_predicted.astype(int)

    print()
    # print(headerArray);
    # print(_lr.coef_)
    # print(_lr.intercept_)

    print(getprecisionWithTorlerate(y_predicted, _score_array, 0.5),
          getprecisionWithTorlerate(y_predicted, _score_array, 1.5),
          getprecisionWithTorlerate(y_predicted, _score_array, 2.5),
          spearmanr(y_predicted, _score_array),
          r2_score(_score_array, y_predicted))
def useElaticNettoPredictScoreWithKFold(targetFileName,
                                        exam_mark=None,
                                        needNorm=True):
    if exam_mark is None:
        exam_mark = DATA_MARK

    featureMatrix, _score_array = getDataAndScore(targetFileName, exam_mark)

    if needNorm:
        featureMatrix = normizeMatrix(featureMatrix)

    _lr = ElasticNetCV(alphas=[0.0001, 0.0005, 0.001, 0.01, 0.1, 1, 10],
                       l1_ratio=[1e-4, .01, .1, .5, .9, .99],
                       max_iter=5000,
                       cv=model_selection.StratifiedKFold(5, shuffle=True))
    precision_array = []
    for _index in range(10):
        _scores = model_selection.cross_val_score(
            _lr,
            featureMatrix,
            _score_array,
            cv=model_selection.StratifiedKFold(5, shuffle=True),
            scoring=lr_precision)
        precision_array.append(_scores.mean())
    print(np.array(precision_array).mean())
def useLRtoPredictScoreWithKFold(targetFileName,
                                 exam_mark=None,
                                 needNorm=True):
    if exam_mark is None:
        exam_mark = DATA_MARK

    featureMatrix, _score_array = getDataAndScore(targetFileName, exam_mark)

    if needNorm:
        featureMatrix = normizeMatrix(featureMatrix)

    _lr = LinearRegression(fit_intercept=True)
    precision_array = []
    for _index in range(10):
        _scores = model_selection.cross_val_score(
            _lr,
            featureMatrix,
            _score_array,
            cv=model_selection.StratifiedKFold(5, shuffle=True),
            scoring=lr_precision)
        precision_array.append(_scores.mean())
    print(np.array(precision_array).mean())
def useLassotoPredictScoreWithKFold(targetFileName,
                                    exam_mark=None,
                                    needNorm=True):
    if exam_mark is None:
        exam_mark = DATA_MARK

    featureMatrix, _score_array = getDataAndScore(targetFileName, exam_mark)

    if needNorm:
        featureMatrix = normizeMatrix(featureMatrix)

    _lr = LassoCV(alphas=[0.01, 0.05, 0.1, 0.5, 1, 10],
                  cv=model_selection.StratifiedKFold(5, shuffle=True),
                  tol=1e-4)
    precision_array = []
    for _index in range(10):
        _scores = model_selection.cross_val_score(
            _lr,
            featureMatrix,
            _score_array,
            cv=model_selection.StratifiedKFold(5, shuffle=True),
            scoring=lr_precision)
        precision_array.append(_scores.mean())
    print(np.array(precision_array).mean())