【发布时间】:2021-07-01 04:28:37
【问题描述】:
总的来说,我在 Python 编程方面有相当多的经验,但对神经网络和深度学习非常陌生。在完成了 Tech With Tim 的 Mega AI 课程后,我决定自己创建一个神经网络。这很简单 - 它接受一个名字并根据其性别输出 0 或 1 - 0 = 男性,1 = 女性。
这是我的完整代码。
import numpy as np
import pandas as pd
import tensorflow as tf
import tflearn
encode_alphabet = '0ABCDEFGHIJKLMNOPQRSTUVWXYZ'
data = pd.read_csv("names.csv")
X = data.drop(["OUT"], 1).values.tolist()
y = [int("".join([str(j) for j in i])) for i in data[["OUT"]].values.tolist()]
print(len(X))
print(len(y))
tf.compat.v1.reset_default_graph()
net = tflearn.input_data(shape=[None, 12])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 1, activation="linear")
net = tflearn.regression(net)
model = tflearn.DNN(net)
model.fit(X, y, n_epoch=100, show_metric=True)
print(data)
names.csv 文件看起来像这样(前 5 行):
L0 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 L11 OUT
0 0 0 0 0 0 15 12 9 22 5 18 0
0 0 0 0 0 0 7 5 15 18 7 5 0
0 0 0 0 0 0 0 8 1 18 18 25 0
0 0 0 0 0 0 0 0 14 15 1 8 0
0 0 0 0 0 0 0 0 10 1 3 11 0
这是我得到的错误:
ValueError: Cannot feed value of shape (64,) for Tensor 'TargetsData/Y:0', which has shape '(?, 1)'
我尝试了各种模型形状,但似乎没有任何效果。 如果需要的话,我很高兴为你们提供更多信息,但我对这一切太陌生了,RTFM 回复真的无济于事。
提前非常感谢
【问题讨论】:
标签: python pandas numpy tensorflow neural-network