请帮帮我失踪的地方?为什么我总是得到这个错误:
'DataFrame'对象没有属性'train'
# -*- coding: utf-8 -*-
import tensorflow as tf
from tensorflow.contrib import rnn
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv("all.csv")
x = dataset.iloc[:, 1:51].values
y = dataset.iloc[:, 51].values
time_steps=5
num_units=128
n_input=50
learning_rate=0.001
n_classes=2
batch_size=5
#weights and biases of appropriate shape to accomplish above task
out_weights=tf.Variable(tf.random_normal([num_units,n_classes]))
out_bias=tf.Variable(tf.random_normal([n_classes]))
#defining placeholders
#input image placeholder
x=tf.placeholder("float",[None,time_steps,n_input])
#input label placeholder
y=tf.placeholder("float",[None,n_classes])
#processing the input tensor from [batch_size,n_steps,n_input] to
"time_steps"
number of [batch_size,n_input] tensors
input=tf.unstack(x ,time_steps,1)
#defining the network
lstm_layer=rnn.BasicLSTMCell(num_units,forget_bias=1)
outputs,_=rnn.static_rnn(lstm_layer,input,dtype="float32")
#converting last output of dimension [batch_size,num_units] to
[batch_size,n_classes] by out_weight multiplication
prediction=tf.matmul(outputs[-1],out_weights)+out_bias
#loss_function
损耗= tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits =预测,标签= Y)) #优化 选择= tf.train.AdamOptimizer(learning_rate = learning_rate).minimize(损失)
#model evaluation
correct_prediction=tf.equal(tf.argmax(prediction,1),tf.argmax(y,1))
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
#initialize variables
init=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
iter=1
while iter<800:
batch_x,batch_y=dataset.train.next_batch(batch_size=batch_size)
batch_x=batch_x.reshape((batch_size,time_steps,n_input))
sess.run(opt, feed_dict={x: batch_x, y: batch_y})
if iter %10==0:
acc=sess.run(accuracy,feed_dict={x:batch_x,y:batch_y})
los=sess.run(loss,feed_dict={x:batch_x,y:batch_y})
print("For iter ",iter)
print("Accuracy ",acc)
print("Loss ",los)
print("__________________")
iter=iter+1
答案 0 :(得分:2)
如错误所述,您的pandas“DataFrame”对象没有名为“next_batch”的属性/方法。
您可能遵循了使用Tensorflow辅助方法加载MNIST数据库的教程。但是pandas会返回一个与您期望的“DataSet”类不同的对象。