[英]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? 我究竟做错了什么?
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
值,可以使用诸如word2vec
或Tf-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.