输入数据去掉落无关项,整顿成练习数据和测试数据:
- dataX = df.drop(["win", "date", "home", "away"], axis=1)
- dataY = df["win"]
- train_x = np.array(dataX)[::2] # train set
- train_y = np.array(dataY)[::2]
- test_x = np.array(dataX)[1::2] # test set
- test_y = np.array(dataY)[1::2]
处理后的数据维度:
可以看到 10 个 epochs 之后,模型对于练习数据的精确度已经达到了 98.89%
搭建深度收集
这部分其实反而是这篇文┞仿中最简单的部分,因为我们有 Keras:
- from keras.models import Sequential
- from keras.layers.core import Dense
- model = Sequential()
- model.add(Dense(60, input_dim=train_x.shape[1], activation='relu'))
- model.add(Dense(30, activation='relu'))
- model.add(Dense(1, activation='sigmoid'))
- model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
最简单的三层全连接层收集。
因为收集的输出维度是 1,所以最后一层的激活函数是 sigmoid,损掉函数为 binary_crossentropy。
模型练习以及验证
再应用测试数据对该模型进行验证:
- def predict(home=None, away=None):
- home_data = game_detail_df[(game_detail_df['name']==home) & (game_detail_df['home']==1)].sort_values(by='date', ascending=False)[:5].mean()
- away_data = game_detail_df[(game_detail_df['name']==away) & (game_detail_df['home']==0)].sort_values(by='date', ascending=False
推荐阅读
CNN与RNN对中文文本进行分类--基于TENSORFLOW实现
Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践运行 python run_cnn.py test 在测试集长进行测试。 练习与验证还可以经由过程进一步的调节参数,来达到更>>>详细阅读
本文标题:使用深度学习来预测NBA比赛结果
地址:http://www.17bianji.com/lsqh/39191.html
1/2 1