prizepicks

 avatar
unknown
plain_text
a month ago
2.3 kB
2
Indexable
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

# Step 1: Load historical player performance data
# Replace 'historical_data.csv' with your actual data file
try:
    data = pd.read_csv('historical_data.csv')
except FileNotFoundError:
    print("Error: 'historical_data.csv' not found. Ensure the file is in the same directory as this script.")
    exit()

# Step 2: Preprocess the data
# Adjust the column names below to match your actual dataset
try:
    X = data[['player_matchup', 'team_strength', 'recent_performance']]  # Example feature columns
    y = data['projected_points']  # Target column
except KeyError:
    print("Error: Ensure the dataset has columns 'player_matchup', 'team_strength', 'recent_performance', and 'projected_points'.")
    exit()

# Step 3: Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Step 4: Train a machine learning model
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Step 5: Evaluate the model
predictions = model.predict(X_test)
mse = mean_squared_error(y_test, predictions)
print(f"Model trained successfully. Mean Squared Error on test set: {mse:.2f}")

# Step 6: Load PrizePicks lines and make predictions
# Replace 'prizepicks_lines.csv' with your actual data file
try:
    prizepicks_lines = pd.read_csv('prizepicks_lines.csv')
except FileNotFoundError:
    print("Error: 'prizepicks_lines.csv' not found. Ensure the file is in the same directory as this script.")
    exit()

# Predict outcomes based on PrizePicks lines
try:
    prizepicks_lines['predicted_points'] = model.predict(prizepicks_lines[['player_matchup', 'team_strength', 'recent_performance']])
    best_picks = prizepicks_lines[prizepicks_lines['predicted_points'] > prizepicks_lines['line']]
    print("Top Picks:")
    print(best_picks[['player_name', 'line', 'predicted_points']])
except KeyError:
    print("Error: Ensure 'prizepicks_lines.csv' has columns 'player_matchup', 'team_strength', 'recent_performance', and 'line'.")

# Optional: Save results to a file
best_picks.to_csv('best_picks.csv', index=False)
print("Results saved to 'best_picks.csv'.")
Leave a Comment