以下是前3行数据集(目标列是第19列,功能是前18列):
user gender age how_tall_in_meters weight body_mass_index x1 debora Woman 46 1.62 75 28.6 -3 debora Woman 46 1.62 75 28.6 -3
此处未显示的目标列具有字符串值.
from pandas import read_csvimport numpy as npfrom sklearn.linear_model.stochastic_gradIEnt import SGDClassifIErfrom sklearn import preprocessingimport sklearn.metrics as metricsfrom sklearn.cross_valIDation import train_test_split#d = pd.read_csv("data.csv",dtype={'A': np.str(),'B': np.str(),'S': np.str()})dataset = np.genfromtxt(open('data.csv','r'),delimiter=',',dtype='f8')[1:]target = np.array([x[19] for x in dataset])train = np.array([x[1:] for x in dataset])print(target)
我得到的错误是:
Traceback (most recent call last): file "C:\Users\Cameron\Desktop\Project - Machine learning\datafilesforproj\SGD_classifIEr.py",line 12,in <module> dataset = np.genfromtxt(open('data.csv',dtype='f8')[1:] file "C:\python33\lib\site-packages\numpy\lib\npyio.py",line 1380,in genfromtxt first_values = split_line(first_line) file "C:\python33\lib\site-packages\numpy\lib\_iotools.py",line 217,in _delimited_splitter line = line.split(self.comments)[0]TypeError: Can't convert 'bytes' object to str implicitly解决方法 对我有用的是改变界限
dataset = np.genfromtxt(open('data.csv',dtype='f8')[1:]
至
dataset = np.genfromtxt('data.csv',dtype='f8')[1:]
(不幸的是,我不太清楚底层问题是什么)
总结以上是内存溢出为你收集整理的python – 使用numpy.genfromtxt给出TypeError:无法隐式地将’bytes’对象转换为str全部内容,希望文章能够帮你解决python – 使用numpy.genfromtxt给出TypeError:无法隐式地将’bytes’对象转换为str所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)