【发布时间】:2019-09-22 04:23:09
【问题描述】:
我正在学习机器学习,我的数据集由 6 列组成:
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 的代码以预测主队的奖金。
但它会向任何输入返回相同的预测 (0)。当我仅根据赔率进行尝试时,预测更准确,至少不一样。
代码
# 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]))
你知道问题出在哪里吗?
【问题讨论】:
标签: python tensorflow keras