Example #1
0
def fetchNewMatches():
    db.create_database(dbfile)  # create db if not exists

    classificationmodel = ml.load_model(
        classificationmodelname)  # load model for classification
    regressionmodel = ml.load_model(
        regressionmodelname)  # load model for regression

    for match in fetching.fetchseason(
            season):  # for each past match of season 2019-2020
        hometeamdata = db.get_teamhistory(dbfile, match["home-team"],
                                          match["date"])  # get history
        awayteamdata = db.get_teamhistory(dbfile, match["away-team"],
                                          match["date"])  # get history
        prepared_data = ml.prepare_matchdata(
            match, hometeamdata, awayteamdata)  # prepare data for model

        predictedClassificationResult = ml.exec_classification_model(
            classificationmodel, prepared_data)  # run the model
        predictedRegressionResult = ml.exec_regression_model(
            regressionmodel, prepared_data)  # run the model

        db.add_match(dbfile, match["home-team"], match["away-team"],
                     match["date"], predictedClassificationResult,
                     predictedRegressionResult, match["odds-home"],
                     match["odds-draw"], match["odds-away"],
                     match["home-goals"], match["home-shots"],
                     match["home-shots-on-target"], match["away-goals"],
                     match["away-shots"], match["away-shots-on-target"])
    return "ok"
Example #2
0
def retrainRegression():
    matches = []
    for match in db.get_matches(dbfile):  # for each match in db
        hometeamdata = db.get_teamhistory(dbfile, match["home-team"],
                                          match["date"])  # get history
        awayteamdata = db.get_teamhistory(dbfile, match["away-team"],
                                          match["date"])  # get history
        prepared_data = ml.prepare_regressiontrainingmatchdata(
            match, hometeamdata, awayteamdata)  # prepare data for model

        matches.append(prepared_data)

    model = ml.retrain_regression_model(matches)  # build&create model

    ml.save_model(model, regressionmodelname)  # save model

    # repredict everything!
    for match in db.get_matches(dbfile):
        hometeamdata = db.get_teamhistory(dbfile, match["home-team"],
                                          match["date"])  # get history
        awayteamdata = db.get_teamhistory(dbfile, match["away-team"],
                                          match["date"])  # get history
        prepared_data = ml.prepare_matchdata(
            match, hometeamdata, awayteamdata)  # prepare data for model

        predictedRegressionResult = ml.exec_regression_model(
            model, prepared_data)  # run the model

        db.update_matchprediction_regression(dbfile, match["home-team"],
                                             match["away-team"], match["date"],
                                             predictedRegressionResult)

    return "ok"
Example #3
0
def predict_match(classificationmodel, regressionmodel, match):
    hometeamdata = db.get_teamhistory(dbfile, match[4],
                                      match[2])  # get history
    awayteamdata = db.get_teamhistory(dbfile, match[5],
                                      match[2])  # get history
    prepared_data = ml.prepare_matchdata(
        match[2], hometeamdata, awayteamdata)  # prepare data for model
    predictedClassificationResult = ml.exec_classification_model(
        classificationmodel, prepared_data)  # run the model
    predictedRegressionResult = ml.exec_regression_model(
        regressionmodel, prepared_data)  # run the model

    return predictedClassificationResult, predictedRegressionResult
Example #4
0
def main():
    db.create_database(dbfile)
    fetchNewMatches()
    dbmatch = db.get_match(dbfile, "sc-paderborn-07", "borussia-dortmund",
                           20200601)
    hometeamdata = db.get_teamhistory(dbfile, "sc-paderborn-07", 20200601)
    awayteamdata = db.get_teamhistory(dbfile, "borussia-dortmund", 20200601)
    jasonstring = ml.prepare_matchdata(dbmatch, hometeamdata,
                                       awayteamdata)  # prepare data for model

    df = pd.read_json(jasonstring).T  # read json and create dataframe
    model = ml.load_model("model02_H3_M")  # load model
    predictedResultArray = ml.exec_classification_model(
        model, df)  # retrieve result from model
    predictedResult = numpy.argmax(predictedResultArray,
                                   axis=None)  # get max value
    print(predictedResult)