I have a project in python that is from kaggle.com. I am having problems reading in the data set. It has one csv file. We need to read it in and put the target and train parts of it in arrays.
Here are the first 3 rows of data set (the target column is the 19th column and the features are the first 18 columns):
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
The target column which is not shown here has string values.
from pandas import read_csv
import numpy as np
from sklearn.linear_model.stochastic_gradient import SGDClassifier
from sklearn import preprocessing
import sklearn.metrics as metrics
from 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)
The error I'm getting is:
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','r'), delimiter=',', 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