Krahwazi

NRL Simulator/Score Predictor/Try Predictor

Feb 17th, 2024 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | Sports | 0 0
  1. # Load historical NRL match data
  2. data = pd.read_csv('nrl_data.csv')
  3.  
  4. # Feature engineering
  5. # For example, create features such as player-specific performance in different weather conditions, team performance against specific opponents, etc.
  6.  
  7. # Data imputation
  8. # Implement data imputation techniques for handling missing values in additional data sources
  9.  
  10. # Define features and targets
  11. X = data[features]
  12. y_score = data['score']
  13. y_try = data['try']
  14.  
  15. # Split data into training and testing sets
  16. X_train, X_test, y_train_score, y_test_score, y_train_try, y_test_try = train_test_split(X, y_score, y_try, test_size=0.2, random_state=42)
  17.  
  18. # Model training and tuning
  19. # Score prediction model
  20. score_model = RandomForestRegressor()
  21. score_param_grid = {'n_estimators': [100, 200, 300], 'max_depth': [None, 10, 20, 30]}
  22. score_grid_search = GridSearchCV(score_model, score_param_grid, cv=5)
  23. score_grid_search.fit(X_train, y_train_score)
  24. best_score_model = score_grid_search.best_estimator_
  25.  
  26. # Try prediction model
  27. try_model = RandomForestClassifier()
  28. try_param_grid = {'n_estimators': [100, 200, 300], 'max_depth': [None, 10, 20, 30]}
  29. try_grid_search = GridSearchCV(try_model, try_param_grid, cv=5)
  30. try_grid_search.fit(X_train, y_train_try)
  31. best_try_model = try_grid_search.best_estimator_
  32.  
  33. # Model evaluation
  34. score_predictions = best_score_model.predict(X_test)
  35. score_mse = mean_squared_error(y_test_score, score_predictions)
  36.  
  37. try_predictions = best_try_model.predict(X_test)
  38. try_accuracy = accuracy_score(y_test_try, try_predictions)
  39.  
  40. # Predict scores and tries for upcoming matches
  41. upcoming_matches = pd.read_csv('upcoming_matches.csv')
  42. upcoming_features = preprocess_features(upcoming_matches)
  43. upcoming_features = pd.merge(upcoming_features, player_stats, on='player_id', how='left')
  44. upcoming_features = pd.merge(upcoming_features, team_stats, on='team_id', how='left')
  45. upcoming_features = pd.merge(upcoming_features, weather_data, on='match_id', how='left')
  46. upcoming_features = pd.merge(upcoming_features, betting_odds, on='match_id', how='left')
  47.  
  48. upcoming_score_predictions = best_score_model.predict(upcoming_features)
  49. upcoming_try_predictions = best_try_model.predict(upcoming_features)
  50.  
  51. # Display predictions for upcoming matches
  52. for i in range(len(upcoming_matches)):
  53.     print(f"Match {i+1}: Predicted Score: {upcoming_score_predictions[i]}, Predicted Tries: {upcoming_try_predictions[i]}")
  54.  
Tags: #nrl
Advertisement
Add Comment
Please, Sign In to add comment