Browse Source

add neural network bery col shit state of the art

master
Ryan Missel 5 years ago
parent
commit
0a1748fd9c
2 changed files with 120 additions and 17 deletions
  1. +120
    -0
      hypotheses_modeling/pytorch_shit.py
  2. +0
    -17
      hypotheses_modeling/ryan_regressions.txt

+ 120
- 0
hypotheses_modeling/pytorch_shit.py View File

@ -0,0 +1,120 @@
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))
x = torch.sigmoid(self.fc2(x))
return 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 = np.array(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()
for step in range(steps):
x, y = get_trainset(dataset, k, n0, x_columns, y_columns)
pred = net(x)
pred = pred.detach().numpy()
for row in range(len(pred)):
pred[row] = get_argmax(pred[row])
net_loss = loss(pred, y)
net_loss.backward()
optimizer.step()
print("Loss at Step {}: {}".format(step, net_loss))
def accuracy(net, x, y):
pred = net(x)
pred = pred.detach().numpy()
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))
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(100, 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
(0.0030010445831953553, array([ 5.97640029e-01, -1.59341568e-05]), 0.3568843263232311, 0.00117522635306064)
(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