Browse Source

Added polynomial regression function

master
Ryan Missel 5 years ago
parent
commit
b91af48922
2 changed files with 27 additions and 9 deletions
  1. +7
    -0
      hypotheses_modeling/hypotheses.txt
  2. +20
    -9
      hypotheses_modeling/team_regressions.py

+ 7
- 0
hypotheses_modeling/hypotheses.txt View File

@ -21,8 +21,15 @@ Team:
5. 5.
Individual:
Player 1 - fatigue + day / soreness
lr - 0.24677741789096985
pr - 0.32119826926167405
Perry: Perry:
7 day moving average team workload - normalized team fatigue: 0.0006 7 day moving average team workload - normalized team fatigue: 0.0006
21 day moving average team workload - normalized team fatigue: 0.0024 21 day moving average team workload - normalized team fatigue: 0.0024
normalized team fatigue - game day performance: 0.0696 normalized team fatigue - game day performance: 0.0696
normalized team fatigue - paper smoothed workload fatigue: 0.0324 normalized team fatigue - paper smoothed workload fatigue: 0.0324

+ 20
- 9
hypotheses_modeling/team_regressions.py View File

@ -1,4 +1,6 @@
from sklearn import linear_model from sklearn import linear_model
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
import pandas as pd import pandas as pd
from sklearn.metrics import mean_squared_error, r2_score from sklearn.metrics import mean_squared_error, r2_score
@ -34,6 +36,7 @@ def k_days_into_future_regression(X, y, k, n0):
def standard_lr(x, y): def standard_lr(x, y):
# Standard linear regression formula, gives back params and r2
regr = linear_model.LinearRegression() regr = linear_model.LinearRegression()
regr.fit(x, y) regr.fit(x, y)
predictions = regr.predict(x) predictions = regr.predict(x)
@ -42,19 +45,27 @@ def standard_lr(x, y):
return regr.intercept_, regr.coef_, r2, mse return regr.intercept_, regr.coef_, r2, mse
def main():
# fatigueSums = pd.read_csv("fatigue_total_sum.csv")
# workMovingAverage21 = pd.read_csv("21DaySlidingWorkAverage.csv", index_col=0)
# print(k_days_into_future_regression(workMovingAverage21, fatigueSums, 0, 21))
def poly_regression(x, y, degree):
# Polynomial regression with nth degree, gives back rmse and r2
polynomial_features = PolynomialFeatures(degree=degree)
x_poly = polynomial_features.fit_transform(x)
model = linear_model.LinearRegression()
model.fit(x_poly, y)
y_poly_pred = model.predict(x_poly)
rmse = np.sqrt(mean_squared_error(y, y_poly_pred))
r2 = r2_score(y, y_poly_pred)
return rmse, r2
wellness = pd.read_csv("../data_preparation/cleaned/time_series_normalized_wellness_menstruation.csv")
wellness = wellness.fillna(0)
x = wellness[['normSoreness', 'TimeSinceAugFirst']]
y = wellness['normFatigue']
print(wellness.isnull().sum())
def main():
player = pd.read_csv("../data_preparation/cleaned/personal.csv", index_col=0)
player = player[player['playerID'] == 1]
x = player[['fatigueNorm', 'day']]
y = player['sorenessNorm']
print(standard_lr(x, y)) print(standard_lr(x, y))
print(poly_regression(x, y, 5))
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save