【发布时间】:2017-06-30 10:09:24
【问题描述】:
作为机器学习和 tflearn/tensorflow 的新手,我试图按照 tflearn(泰坦尼克号)的快速入门教程进行操作。
修改它以满足我的需要我得到了这个代码:
from __future__ import print_function
import numpy as np
import tflearn
# Load CSV file, indicate that the first column represents labels
from tflearn.data_utils import load_csv
data, labels = load_csv('nowcastScaled.csv', target_column=1, n_classes=2)
# Preprocessing function
def preprocess(data):
return np.array(data, dtype=np.float32)
# Preprocess data
data = preprocess(data)
# Build neural network
net = tflearn.input_data(shape=[None, 2])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
loss='categorical_crossentropy')
# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)
但是我收到了这个错误:
ValueError: 无法为张量提供形状 (16, 1) 的值 u'InputData/X:0',形状为'(?, 2)'
我的 csv 文件由 2 列组成,一个是索引(条目的编号,因为这只是一个测试,我将自己限制为 100 个条目),另一个是拥塞分数(我试图预测的内容, 0 到 200 之间),都是数值。
我有点理解我试图给它一个错误的价值(或者至少是他没有等待的东西),但我不知道如何纠正它。
【问题讨论】:
标签: python machine-learning tensorflow tflearn