Skip to content

Instantly share code, notes, and snippets.

@torryt
Created February 23, 2017 21:54
Show Gist options
  • Save torryt/f18524037f36f0eee325b7647acffe52 to your computer and use it in GitHub Desktop.
Save torryt/f18524037f36f0eee325b7647acffe52 to your computer and use it in GitHub Desktop.
def load_car():
bc = Bunch()
fn = osp.join(osp.dirname(__file__), 'car.csv')
with open(fn, 'r') as csvfile:
data = np.array(list(csv.reader(csvfile))).T.tolist()
numeric_data = [to_numeric(col) for col in data]
ndata = np.array(numeric_data).T
bc.target = ndata[:, -1]
bc.data = ndata[:, 0:-1]
return bc
def to_numeric(str_list):
unique_values = list(set(str_list))
return [unique_values.index(s) for s in str_list]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment