适用于强力球比赛预测的LSTM

时间:2019-03-31 18:17:46

标签: python tensorflow machine-learning data-science recurrent-neural-network

请注意,这不会用于预测强力球比赛,这只是一个了解机器学习技术的简单项目,我知道不可能预测实际的强力球。

我使用可预测的算法创建了一个简单的游戏。

游戏生成一组6个数字。数字来自 1-49 [数字无法重复]

示例:41、35、1、2、49、24 以上数字的总和是151

游戏的目的是预测总和是高于还是低于某一点。可以说:150

样本表: enter image description here

我目前有限的理解是,我可能可以使用LSTM网络来预测总和,然后预测下一个结果。

我使用了以下基于股票预测网络的实现,因此它可能适合或可能不适合此特定任务。

Run code in Google Colab

# -*- coding: utf-8 -*-
"""ML LSTM.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/13be9SAeFogZLEJlg6DMLCizL67ib7c-t

### Code for Python Array
"""

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential, load_model
from keras.layers import LSTM, Dense, Dropout

!git clone https://github.com/updatesvc/gameML.git

!ls gameML

df = pd.read_csv('gameML/bets (1).csv',sep=';')
df =  df.sort_values('betid')
df = df[0:5000]
df.head()

conditions = [
    (df['result'] == 'L'),
    (df['result'] == 'M'),
    (df['result'] == 'H')]
choices = [0,0.5,1]
df['resultB'] = np.select(conditions, choices)

df.head()

df = df['sum'].values
print(df.shape)

df = df.reshape(-1, 1)
print(df.shape)

dataset_train = np.array(df[:int(df.shape[0]*0.8)])
dataset_test = np.array(df[int(df.shape[0]*0.8)-100:])
print(dataset_train.shape)
print(dataset_test.shape)

scaler = MinMaxScaler(feature_range=(0,1))
dataset_train = scaler.fit_transform(dataset_train)
dataset_train[:5]

dataset_test = scaler.transform(dataset_test)
dataset_test[:5]

def create_dataset(df):
    x = []
    y = []
    for i in range(100, df.shape[0]):
        x.append(df[i-100:i, 0])
        y.append(df[i, 0])
    x = np.array(x)
    y = np.array(y)
    return x,y

x_train, y_train = create_dataset(dataset_train)
x_train[:1]

x_test, y_test = create_dataset(dataset_test)
x_test[:1]

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))

import tensorflow as tf
model = Sequential()
model.add(LSTM(units=96, return_sequences=True, input_shape=(x_train.shape[1], 1)))
model.add(Dropout(0.2))
model.add(LSTM(units=96, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=96, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=96))
model.add(Dropout(0.2))
model.add(Dense(units=1,activation=tf.nn.softmax))

model.compile(loss='mean_squared_error', optimizer='adam')

model.fit(x_train, y_train, epochs=1, batch_size=32)

#print(x_test[i])

predictions = model.predict(x_train)

predictions = scaler.inverse_transform(predictions)

for i in range (100):
  print ("actual value "+str(y_train[i])+" and prediciton "+str(predictions[i]))

根据代码,预测值均相同,似乎不正确。 可能有什么问题,我需要使用其他类型的神经网络吗?

0 个答案:

没有答案