kochlisGit / ProphitBet-Soccer-Bets-Predictor

ProphitBet is a Machine Learning Soccer Bet prediction application. It analyzes the form of teams, computes match statistics and predicts the outcomes of a match using Advanced Machine Learning (ML) methods. The supported algorithms in this application are Neural Networks, Random Forests & Ensembl Models.
MIT License
338 stars 121 forks source link

Help adding predictions for number of goals (combine NN RF and poisson) #47

Open KnightRider37 opened 1 year ago

KnightRider37 commented 1 year ago

Hi,

Maybe several of us here can find a way to add predictions for number of goals per game. I'm only starting with python and having hard time integrating this feature, but maybe someone more knowledgeable would be able to do it. I was thinking something like combining NN RF and poisson to get the right outcome:

import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import PoissonRegressor from sklearn.neural_network import MLPRegressor from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_squared_error from sklearn.preprocessing import StandardScaler import numpy as np

Assuming you have a pandas DataFrame 'df' with features and target variable

X = df[['feature1', 'feature2', 'feature3']] # Features y = df['goals'] # Target variable

Split the data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Train a Poisson Regression model

poisson_model = PoissonRegressor() poisson_model.fit(X_train, y_train)

Train a Neural Network model

scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test)

neural_network_model = MLPRegressor(hidden_layer_sizes=(50, 50), max_iter=1000) neural_network_model.fit(X_train_scaled, y_train)

Train a Random Forest model

random_forest_model = RandomForestRegressor(n_estimators=100, random_state=42) random_forest_model.fit(X_train, y_train)

Make predictions with each model

poisson_predictions = poisson_model.predict(X_test) neural_network_predictions = neural_network_model.predict(X_test_scaled) random_forest_predictions = random_forest_model.predict(X_test)

Simple blending: Average predictions

blended_predictions = np.mean([poisson_predictions, neural_network_predictions, random_forest_predictions], axis=0)

Evaluate the performance of the blended model

mse_blended = mean_squared_error(y_test, blended_predictions) print(f"Mean Squared Error (Blended Model): {mse_blended}")

What do you think?

KnightRider37 commented 1 year ago

We could use data from: https://soccerdata.readthedocs.io/en/latest/intro.html