Python中的MXNet分类总是给出相同的预测
我在这里尝试的是,通过使用网球比赛统计数据集作为输入,我建立了一个神经网络模型,预测比赛结果(1或0) 通过遵循mxnet官方文件,我开发了以下程序。 我尝试了各种配置参数,如批次大小、单位大小、动作类型、学习率,但无论我能想到什么样的修改,我得到的精度始终在0.5左右,并且总是预测全部1或0Python中的MXNet分类总是给出相同的预测,python,machine-learning,deep-learning,mxnet,Python,Machine Learning,Deep Learning,Mxnet,我在这里尝试的是,通过使用网球比赛统计数据集作为输入,我建立了一个神经网络模型,预测比赛结果(1或0) 通过遵循mxnet官方文件,我开发了以下程序。 我尝试了各种配置参数,如批次大小、单位大小、动作类型、学习率,但无论我能想到什么样的修改,我得到的精度始终在0.5左右,并且总是预测全部1或0 import numpy as np from sklearn.preprocessing import normalize import mxnet as mx import logging impor
import numpy as np
from sklearn.preprocessing import normalize
import mxnet as mx
import logging
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
logging.basicConfig(level=logging.DEBUG, format='%(asctime)-15s %(message)s')
batch_size = 100
train_data = np.loadtxt("dm.csv",delimiter=",")
train_data = normalize(train_data, norm='l1', axis=0)
train_lbl = np.loadtxt("dm_lbl.csv",delimiter=",")
eval_data = np.loadtxt("dw.csv",delimiter=",")
eval_data = normalize(eval_data, norm='l1', axis=0)
eval_lbl = np.loadtxt("dw_lbl.csv",delimiter=",")
train_iter = mx.io.NDArrayIter(train_data, train_lbl, batch_size=batch_size, shuffle=True)
val_iter = mx.io.NDArrayIter(eval_data, eval_lbl, batch_size=batch_size)
data = mx.sym.var('data')
# The first fully-connected layer and the corresponding activation function
fc1 = mx.sym.FullyConnected(data=data, num_hidden=220)
#bn1 = mx.sym.BatchNorm(data = fc1, name="bn1")
act1 = mx.sym.Activation(data=fc1, act_type="sigmoid")
# The second fully-connected layer and the corresponding activation function
fc2 = mx.sym.FullyConnected(data=act1, num_hidden = 220)
#bn2 = mx.sym.BatchNorm(data = fc2, name="bn2")
act2 = mx.sym.Activation(data=fc2, act_type="sigmoid")
# The third fully-connected layer and the corresponding activation function
fc3 = mx.sym.FullyConnected(data=act2, num_hidden = 110)
#bn3 = mx.sym.BatchNorm(data = fc3, name="bn3")
act3 = mx.sym.Activation(data=fc3, act_type="sigmoid")
# output class(es)
fc4 = mx.sym.FullyConnected(data=act3, num_hidden=2)
# Softmax with cross entropy loss
mlp = mx.sym.SoftmaxOutput(data=fc4, name='softmax')
mod = mx.mod.Module(symbol=mlp,
context=mx.cpu(),
data_names=['data'],
label_names=['softmax_label'])
mod.fit(train_iter,
eval_data=val_iter,
optimizer='sgd',
optimizer_params={'learning_rate':0.03},
eval_metric='rmse',
num_epoch=10,
batch_end_callback = mx.callback.Speedometer(batch_size, 100)) # output progress for each 200 data batches)
prob = mod.predict(val_iter).asnumpy()
#print(prob)
for unit in prob:
print 'Classified as %d with probability %f' % (unit.argmax(), max(unit))
以下是日志输出:
2017-06-19 17:18:34,961 Epoch[0] Train-rmse=0.500574
2017-06-19 17:18:34,961 Epoch[0] Time cost=0.007
2017-06-19 17:18:34,968 Epoch[0] Validation-rmse=0.500284
2017-06-19 17:18:34,975 Epoch[1] Train-rmse=0.500703
2017-06-19 17:18:34,975 Epoch[1] Time cost=0.007
2017-06-19 17:18:34,982 Epoch[1] Validation-rmse=0.500301
2017-06-19 17:18:34,990 Epoch[2] Train-rmse=0.500713
2017-06-19 17:18:34,990 Epoch[2] Time cost=0.008
2017-06-19 17:18:34,998 Epoch[2] Validation-rmse=0.500302
2017-06-19 17:18:35,005 Epoch[3] Train-rmse=0.500713
2017-06-19 17:18:35,005 Epoch[3] Time cost=0.007
2017-06-19 17:18:35,012 Epoch[3] Validation-rmse=0.500302
2017-06-19 17:18:35,019 Epoch[4] Train-rmse=0.500713
2017-06-19 17:18:35,019 Epoch[4] Time cost=0.007
2017-06-19 17:18:35,027 Epoch[4] Validation-rmse=0.500302
2017-06-19 17:18:35,035 Epoch[5] Train-rmse=0.500713
2017-06-19 17:18:35,035 Epoch[5] Time cost=0.008
2017-06-19 17:18:35,042 Epoch[5] Validation-rmse=0.500302
2017-06-19 17:18:35,049 Epoch[6] Train-rmse=0.500713
2017-06-19 17:18:35,049 Epoch[6] Time cost=0.007
2017-06-19 17:18:35,056 Epoch[6] Validation-rmse=0.500302
2017-06-19 17:18:35,064 Epoch[7] Train-rmse=0.500712
2017-06-19 17:18:35,064 Epoch[7] Time cost=0.008
2017-06-19 17:18:35,071 Epoch[7] Validation-rmse=0.500302
2017-06-19 17:18:35,079 Epoch[8] Train-rmse=0.500712
2017-06-19 17:18:35,079 Epoch[8] Time cost=0.007
2017-06-19 17:18:35,085 Epoch[8] Validation-rmse=0.500301
2017-06-19 17:18:35,093 Epoch[9] Train-rmse=0.500712
2017-06-19 17:18:35,093 Epoch[9] Time cost=0.007
2017-06-19 17:18:35,099 Epoch[9] Validation-rmse=0.500301
Classified as 0 with probability 0.530638
Classified as 0 with probability 0.530638
Classified as 0 with probability 0.530638
.
.
.
Classified as 0 with probability 0.530638
有人能告诉我哪里错了吗
python version == 2.7.10
mxnet == 0.10.0
numpy==1.12.0
我从数据集中删除了一些非信息列和标题,然后将其转换为csv格式
train_data.shape == (491, 22)
train_lbl.shape == (491,)
eval_data.shape == (452, 22)
eval_lbl.shape == (452,)
网络的定义似乎是正确的。你能打印火车和火车的数据,看看在标准化后数据是否仍然是你所期望的吗?另外,您从原始数据中删除了哪些列?我上传了此程序中使用的数据集。非常感谢您在@Naveen发表的评论。火车和火车看起来不错,正态分布。但无论是否使用规范化代码,它们都会产生很差的结果:没有准确性/rmse改进。我从原始数据中删除了很多列,比如球员姓名,但是你能看看我上传的文件吗?这个链接有我在这个程序中使用的确切数据。