Python RBF神经网络can';t分类MNIST数据集
我已经实现了一个RBF神经网络分类器。 我使用我的实现对MNIST数据集进行分类,但它不是在学习,总是预测单个类。如果有人能帮助我确定我的实施中存在的问题,我将不胜感激 我必须注意到,由于它一个接一个地工作,所以实现相当慢,但我不知道如何使它一批接一批地工作。(我一般不熟悉tensorflow和python) 我的执行情况如下: 用法:Python RBF神经网络can';t分类MNIST数据集,python,tensorflow,machine-learning,neural-network,classification,Python,Tensorflow,Machine Learning,Neural Network,Classification,我已经实现了一个RBF神经网络分类器。 我使用我的实现对MNIST数据集进行分类,但它不是在学习,总是预测单个类。如果有人能帮助我确定我的实施中存在的问题,我将不胜感激 我必须注意到,由于它一个接一个地工作,所以实现相当慢,但我不知道如何使它一批接一批地工作。(我一般不熟悉tensorflow和python) 我的执行情况如下: 用法: mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.lo
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
y_train = to_one_hot(y_train,10)
y_test = to_one_hot(y_test,10)
x_train = np.asarray([np.asarray(x).reshape(-1) for x in x_train])
x_test = np.asarray([np.asarray(x).reshape(-1) for x in x_test])
M = 784
K = 1000
L = 10
lr = 0.01
rbfnn = RBF_NN(M,K,L,lr)
#Selecting prototypes from the train set
idx = np.random.randint(len(x_train), size=K)
prototypes = x_train[idx,:]
init = tf.global_variables_initializer()
sess = tf.InteractiveSession()
sess.run(init,feed_dict={rbfnn.prototypes_input:prototypes})
rbfnn.fit(x_train,y_train,prototypes,epoch_count=1, print_step=1,sess=sess)
y_test_p = []
for xi,yi in zip(x_test,y_test):
yp = rbfnn.predict(xi,sess=sess)
y_test_p.append(yp)
y_test_t = [np.argmax(yi) for yi in y_test]
acc = accuracy_score(y_test_t,y_test_p,)
precc = precision_score(y_test_t,y_test_p, average='macro')
recall = recall_score(y_test_t,y_test_p, average = 'macro')
f1 = f1_score(y_test_t,y_test_p,average='macro')
print("Accuracy:",acc)
print("Precision:",precc)
print("Recall:",recall)
print("F1 score:",f1)
sess.close()
实施情况良好。然而,它似乎对数据非常敏感。 如果添加以下行,它将开始正常学习:
x_train = (x_train-x_train.min())/(x_train.max()-x_train.min())
x_test = (x_test-x_test.min())/(x_test.max()-x_test.min())
通过这种方式,数据被规范化,以便每个特征的间隔为0到1
x_train = (x_train-x_train.min())/(x_train.max()-x_train.min())
x_test = (x_test-x_test.min())/(x_test.max()-x_test.min())