【发布时间】:2020-01-22 21:27:00
【问题描述】:
我正在学习机器学习,我的数据集由 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 diabetes 的代码来预测主队的奖金。
所以现在它“预测”主队是否获胜 (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]))
你知道怎么做吗?
【问题讨论】:
-
看看函数式 API。有了这个,您可以创建多个输出,这是您想要的。 keras.io/getting-started/functional-api-guide/…
标签: python machine-learning keras neural-network