简体   繁体   English

如何使用Keras创建从表格数据进行训练的神经网络?

[英]How can I create a neural network with Keras that trains from tabular data?

I'm relatively new to Python, so please forgive the ignorance. 我是Python的新手,所以请原谅。 I have tabular data that looks like: 我有类似表格的数据:

Type,Name,Age,Breed1,Breed2,Gender,Color1,Color2,Color3,MaturitySize,FurLength,Vaccinated,Dewormed,Sterilized,Health,Quantity,Fee,State,RescuerID,VideoAmt,Description,PetID,PhotoAmt,AdoptionSpeed
2,Nibble,3,299,0,1,1,7,0,1,1,2,2,2,1,1,100,41326,8480853f516546f6cf33aa88cd76c379,0,Nibble is a 3+ month old ball of cuteness. He is energetic and playful. I rescued a couple of cats a few months ago but could not get them neutered in time as the clinic was fully scheduled. The result was this little kitty. I do not have enough space and funds to care for more cats in my household. Looking for responsible people to take over Nibble's care.,86e1089a3,1.0,2
2,No Name Yet,1,265,0,1,1,2,0,2,2,3,3,3,1,1,0,41401,3082c7125d8fb66f7dd4bff4192c8b14,0,I just found it alone yesterday near my apartment. It was shaking so I had to bring it home to provide temporary care.,6296e909a,2.0,0
1,Brisco,1,307,0,1,2,7,0,2,2,1,1,2,1,1,0,41326,fa90fa5b1ee11c86938398b60abc32cb,0,"Their pregnant mother was dumped by her irresponsible owner at the roadside near some shops in Subang Jaya. Gave birth to them at the roadside. They are all healthy and adorable puppies. Already dewormed, vaccinated and ready to go to a home. No tying or caging for long hours as guard dogs. However, it is acceptable to cage or tie for precautionary purposes. Interested to adopt pls call me.",3422e4906,7.0,3
1,Miko,4,307,0,2,1,2,0,2,1,1,1,2,1,1,150,41401,9238e4f44c71a75282e62f7136c6b240,0,"Good guard dog, very alert, active, obedience waiting for her good master, plz call or sms for more details if you really get interested, thanks!!",5842f1ff5,8.0,2

I have a ton of training data and I want to create a neural network to predict the last value AdoptionSpeed . 我有大量的训练数据,我想创建一个神经网络来预测最后一个值AdoptionSpeed

Here's what I have using keras so far: 到目前为止,这是我使用过的keras

from keras.models import Sequential
from keras.layers import Dense
import numpy

dataset = numpy.loadtxt("data/train.csv", delimiter=",")

X = dataset[:,0:8]
Y = dataset[:,8]

But I'm getting an error: 但是我遇到一个错误:

ValueError: could not convert string to float: Type

What am I doing wrong? 我究竟做错了什么?

The default dtype of numpy loadtxt is float . 默认的D型 numpy的loadtxt的是float Instead use: 而是使用:

dataset = np.loadtxt("data/train.csv", delimiter=",", dtype=np.str)

If you look at the csv file that you are passing to np.loadtxt funnction, some of the columns are not having float type of data. 如果查看传递给np.loadtxt函数的csv文件,则某些列没有float类型的数据。 Few columns are strings. 很少有列是字符串。 So, while loading the csv file, default datatype for conversion is float for np.loadtxt function. 因此,在加载csv文件时, np.loadtxt函数的默认转换数据类型为float。 This is the reason for the error. 这就是错误的原因。 Best way to overcome is by using python readlines function for a file and iterate over all the lines. 克服的最佳方法是对文件使用python readlines函数,然后遍历所有行。

Generally, neural network expects inputs to be in the form of numbers. 通常,神经网络期望输入为数字形式。 For converting the string to float values, you can use something like word2vec or Tf-Idf and their embedding alternatives. 要将string转换为float值,可以使用诸如word2vecTf-Idf类的东西及其嵌入替代方法。

As you want predict the Adoptionspeed , you can treat this problem as a regression problem. 如要预测Adoptionspeed ,可以将此问题视为回归问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于使用数据增强进行图像分类的卷积神经网络,如何在 keras 中获得可重现的结果? - How can I get reproducible results in keras for a convolutional neural network using data augmentation for image classification? 如何用Keras可视化神经网络架构? - How can a neural network architecture be visualized with Keras? 如果我从 Keras 创建一个 LSTM model 并从头开始创建一个神经网络,是否有可能? - Is it possible if I create an LSTM model from Keras and followed by a Neural Network from scratch? 如何从带有分支的 model (Python,keras)创建一个新的神经网络 model - how to create a new neural network model from a model with branchs (Python, keras) 如何为 PyTorch 神经网络加载 CSV 数据? - How can I load CSV data for a PyTorch neural network? 如何在Keras中训练HDF5文件中存储的数据的神经网络? - How do I train a neural network in Keras on data stored in HDF5 files? 如何在Keras实施的卷积神经网络的训练过程中修复我的骰子损失计算? - How can I fix my dice loss calculation during the training process of a convolutional neural network implemented in Keras? 如何在基于 keras 的神经网络中使用 tensorflow one hot encoding? - How can I use tensorflow one hot encoding with a keras based neural network? 我如何知道我的神经网络是否使用 Mean_Square_Error (Keras) 运行良好 - How can I know if my Neural Network is doing good or not using Mean_Square_Error (Keras) 我想将下面的代码(神经网络)从keras转换为pytorch - i want to convert the code below(neural network) from keras to pytorch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM