PerryXDeng 5 years ago
parent
commit
347f70de1e
5 changed files with 6166 additions and 6055 deletions
  1. +6
    -2
      data_preparation/IndividualMetrics.R
  2. +6036
    -6036
      data_preparation/cleaned/personal.csv
  3. BIN
      hypotheses_modeling/model.ckpt
  4. +124
    -0
      hypotheses_modeling/pytorch_shit.py
  5. +0
    -17
      hypotheses_modeling/ryan_regressions.txt

+ 6
- 2
data_preparation/IndividualMetrics.R View File

@ -46,6 +46,7 @@ unknownCol <- c()
desireCol <- c()
for(day in dayList) for(day in dayList)
@ -73,6 +74,7 @@ for(day in dayList)
if(length(wellnessDay$SleepHours) > 0) if(length(wellnessDay$SleepHours) > 0)
{ {
desireCol <- c(desireCol, wellnessDay$Desire)
fatigueRawCol <- c(fatigueRawCol, mean(wellnessDay$Fatigue, na.rm =T)) fatigueRawCol <- c(fatigueRawCol, mean(wellnessDay$Fatigue, na.rm =T))
sleepQualityCol <- c(sleepQualityCol, mean(wellnessDay$SleepQuality, na.rm = T)) sleepQualityCol <- c(sleepQualityCol, mean(wellnessDay$SleepQuality, na.rm = T))
sleepHoursCol <- c(sleepHoursCol, sum(wellnessDay$SleepHours, na.rm = T)) sleepHoursCol <- c(sleepHoursCol, sum(wellnessDay$SleepHours, na.rm = T))
@ -80,6 +82,7 @@ for(day in dayList)
} }
else else
{ {
desireCol <- c(desireCol, median(wellnessData$Desire))
sleepQualityCol <- c(sleepQualityCol, median(wellnessData$SleepQuality, na.rm = T)) sleepQualityCol <- c(sleepQualityCol, median(wellnessData$SleepQuality, na.rm = T))
sleepHoursCol <- c(sleepHoursCol, median(wellnessData$SleepHours)) sleepHoursCol <- c(sleepHoursCol, median(wellnessData$SleepHours))
fatigueRawCol <- c(fatigueRawCol, median(wellnessData$Fatigue)) fatigueRawCol <- c(fatigueRawCol, median(wellnessData$Fatigue))
@ -160,7 +163,8 @@ massiveTibble <- tibble(day = dayCol,
BestOutOfMyselfNotAtAll = notatAllCol, BestOutOfMyselfNotAtAll = notatAllCol,
BestOutOfMyselfAbsolutely = absCol, BestOutOfMyselfAbsolutely = absCol,
BestOutOfMyselfSomewhat = somewhatCol, BestOutOfMyselfSomewhat = somewhatCol,
BestOutOfMyselfUnknown = unknownCol)
BestOutOfMyselfUnknown = unknownCol,
desire = desireCol)
write.csv(massiveTibble, "cleaned/personal.csv") write.csv(massiveTibble, "cleaned/personal.csv")
@ -194,7 +198,7 @@ ggplot(data = massiveTibble) +
ggplot(data = massiveTibble) + ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Percieved Fatigue") + ggtitle("Team's Percieved Fatigue") +
geom_point(mapping = aes(x=day, y=fatigue)) +
geom_point(mapping = aes(x=day, y=fatigueNormSliding)) +
labs(x = "Days Since August First 2017", y = "Teams Fatigue")+ labs(x = "Days Since August First 2017", y = "Teams Fatigue")+
theme_bw() theme_bw()

+ 6036
- 6036
data_preparation/cleaned/personal.csv
File diff suppressed because it is too large
View File


BIN
hypotheses_modeling/model.ckpt View File


+ 124
- 0
hypotheses_modeling/pytorch_shit.py View File

@ -0,0 +1,124 @@
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
import pandas as pd
class Net(nn.Module):
def __init__(self, input_shape):
super().__init__()
self.fc1 = nn.Linear(input_shape, 8)
self.fc2 = nn.Linear(8, 4)
def forward(self, x):
x = torch.sigmoid(self.fc1(x))
return self.fc2(x)
def get_argmax(array):
max = 0
index = 0
for i in range(len(array)):
if array[i] > max:
max = array[i]
index = i
one_hot = [0,0,0,0]
one_hot[index] = 1
return one_hot
def get_trainset(dataset, k, n0, x_columns, y_columns):
inp = dataset[x_columns]
out = dataset[y_columns]
col = "day"
x = []
y = []
input_shape = 0
output_shape = 0
for player in out["playerID"].unique():
XPlayer = inp[inp["playerID"] == player]
YPlayer = out[out["playerID"] == player]
for day in YPlayer[col][n0 - 1:]:
prev = day - k
xprev = XPlayer[XPlayer[col] == prev].drop(columns=[col, "playerID"]).to_numpy()
if xprev.shape[0] != 1:
continue
else:
xprev = xprev[0, :]
yt = YPlayer[YPlayer[col] == day].drop(columns=[col, "playerID"]).to_numpy()[0, :]
if input_shape == 0:
input_shape = xprev.shape[0]
else:
if input_shape != xprev.shape[0]:
print("INCONSISTENT INPUT DIMENSION")
exit(2)
if output_shape == 0:
output_shape = yt.shape[0]
else:
if output_shape != yt.shape[0]:
print("INCONSISTENT OUTPUT DIMENSION")
exit(2)
x.append(xprev)
y.append(yt)
x = torch.FloatTensor(x)
y = torch.LongTensor(y)
return x, y
def time_series_sigmoid_classification(steps, dataset, k, n0, x_columns, y_columns):
net = Net(1)
optimizer = optim.Adam(net.parameters(), lr=.001)
loss = nn.CrossEntropyLoss()
x, y = get_trainset(dataset, k, n0, x_columns, y_columns)
accuracy(net, x, y)
for step in range(steps):
optimizer.zero_grad()
x, y = get_trainset(dataset, k, n0, x_columns, y_columns)
pred = net(x)
net_loss = loss(pred, torch.max(y, 1)[1])
net_loss.backward()
optimizer.step()
print("Loss at Step {}: {}".format(step, net_loss))
x, y = get_trainset(dataset, k, n0, x_columns, y_columns)
accuracy(net, x, y)
def accuracy(net, x, y):
pred = net(x)
pred = pred.detach().numpy()
for row in range(len(pred)):
pred[row] = get_argmax(pred[row])
total = len(pred)
correct = 0
for i in range(len(pred)):
equal = True
for j in range(len(pred[i])):
if pred[i][j] != y[i][j]:
equal = False
if equal:
correct += 1
accuracy = (correct / total) * 100
print("Accuracy for set: {}%".format(accuracy))
torch.save(net, "model.ckpt")
def main():
filename = "personal.csv"
df = pd.read_csv(filename)
x = ["day", "playerID", "fatigueSliding"]
y = ["day", "playerID", "BestOutOfMyselfAbsolutely", "BestOutOfMyselfSomewhat", "BestOutOfMyselfNotAtAll", "BestOutOfMyselfUnknown"]
time_series_sigmoid_classification(2, df, 0, 30, x, y)
if __name__ == '__main__':
main()

+ 0
- 17
hypotheses_modeling/ryan_regressions.txt View File

@ -37,20 +37,3 @@ Player 9 for sleepQualityNorm
Player 12 for sleepQualityNorm Player 12 for sleepQualityNorm
(0.0030010445831953553, array([ 5.97640029e-01, -1.59341568e-05]), 0.3568843263232311, 0.00117522635306064) (0.0030010445831953553, array([ 5.97640029e-01, -1.59341568e-05]), 0.3568843263232311, 0.00117522635306064)
(0.6154637522814207, 0.4127840710858218) (0.6154637522814207, 0.4127840710858218)
Player 3 for BestOutOfMyselfAbsolutely
(0.5591113560131244, array([-0.06273135, 0.00144052]), 0.19693367374327753, 0.00034431962962114574)
(0.29946330051959735, 0.4074811906349808)
Player 9 for BestOutOfMyselfAbsolutely
(0.6212790914046262, array([ 0.23297634, -0.00209794]), 0.49210290965481174, 0.0002682490835151878)
(0.2897694328560262, 0.5496315964616945)
Player 3 for BestOutOfMyselfUnknown
(0.45258982162191874, array([ 0.0601493 , -0.00149072]), 0.20252316026232742, 0.0003459027048924739)
(0.2980996120964688, 0.41962026820540466)
Player 9 for BestOutOfMyselfUnknown
(0.34069195794958324, array([-0.22074479, 0.00217018]), 0.4646199842752917, 0.0003011772648087732)
(0.3048702214016301, 0.5319467359793901)

Loading…
Cancel
Save