我正在学习机器学习,我的数据集由 7 列组成:
home_team, away_team, home_odds, away_odds, home_score, away_score, 1_if_home_wins_else_0
为了能够为团队提供 Tensorflow,我将每个团队都转换为整数,因此前两列是整数(如数据库 ID)
csv 中有 10k 行。
例子
我修改了pima Indians 糖尿病的代码来预测主队的获胜情况。
所以现在它“预测”主队是否赢(1)否则为0。
现在我想修改算法来预测准确的分数home_score,away_score。我知道输出是错误的,它只是在学习。
代码
# load the dataset
dataset = loadtxt('football_data.csv', delimiter=',')
# split into input (X) and output (y) variables
X = dataset[:, 0:4]
y = dataset[:, 6]
# define the keras model
model = Sequential()
model.add(Dense(12, input_dim=4, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=10)
# evaluate the keras model
_, accuracy = model.evaluate(X, y)
print('Accuracy: %.2f' % (accuracy * 100))
# make class predictions with the model
predictions = model.predict_classes(X)
# summarize the first 5 cases
for i in range(50):
print('%s => %d (expected %d)' % (X[i].tolist(), predictions[i], y[i]))
你知道怎么做吗?
www说
相关分类