-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
84 lines (65 loc) · 2.65 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import dataset
import tensorflow as tf
import numpy as np
import test
training_split = 0.95
def main():
data = dataset.Dataset("/Users/Huw/Documents/GitHub/Gambling_Predictor/data/book.csv",5)
train_data_len = int(training_split * len(data.processed_results))
train_data = data.processed_results[:train_data_len]
test_data = data.processed_results[train_data_len:]
def features_labels(datas):
features = {}
for d in datas:
for key in d.keys():
if key not in features:
features[key] = []
features[key].append(d[key])
for key in features.keys():
features[key] = np.array(features[key])
return features, features['result']
train_features, train_labels = features_labels(train_data)
test_features, test_labels = features_labels(test_data)
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x=train_features,
y=train_labels,
batch_size=500,
num_epochs=None,
shuffle=True
)
test_input_fn = tf.estimator.inputs.numpy_input_fn(
x=test_features,
y=test_labels,
num_epochs=1,
shuffle=False
)
feature_columns = []
for mode in ['home', 'away']:
feature_columns = feature_columns + [
tf.feature_column.numeric_column(key='{}-wins'.format(mode)),
tf.feature_column.numeric_column(key='{}-draws'.format(mode)),
tf.feature_column.numeric_column(key='{}-losses'.format(mode)),
tf.feature_column.numeric_column(key='{}-goals'.format(mode)),
tf.feature_column.numeric_column(key='{}-opposition-goals'.format(mode)),
tf.feature_column.numeric_column(key='{}-shots'.format(mode)),
tf.feature_column.numeric_column(key='{}-shots-on-target'.format(mode)),
tf.feature_column.numeric_column(key='{}-opposition-shots'.format(mode)),
tf.feature_column.numeric_column(key='{}-opposition-shots-on-target'.format(mode)),
]
model = tf.estimator.DNNClassifier(
model_dir='model/',
hidden_units=[18],
feature_columns=feature_columns,
n_classes=3,
label_vocabulary=['H', 'D', 'A'],
optimizer=tf.train.ProximalAdagradOptimizer(
learning_rate=0.1,
l1_regularization_strength=0.001
))
for i in range(0, 50):
model.train(input_fn=train_input_fn, steps=100)
print(i*100)
evaluation_result = model.evaluate(input_fn=test_input_fn)
predictions = list(model.predict(input_fn=test_input_fn))
test.calculate_accuracy(predictions, test_labels, test_features)
main()