1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| def get_data(): tic = time.time() print('load .csv') cvs_path = '/Users/wonderhoi/Downloads/mipace_mlproject.csv' df = pd.read_csv(cvs_path)
human_features = np.zeros((540, 12), dtype=float) human_labels = []
for item in df.itertuples(): human_features[[item[0]], :] = [item[1], item[2], 0 if item[3] == 'Male' else 1, item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], item[12]] human_labels.append(item[13])
scaler = Normalizer() human_features = scaler.fit_transform(human_features)
human_features = torch.FloatTensor(human_features) human_labels = torch.FloatTensor(human_labels)
X_train, x_test, Y_train, y_train = train_test_split(human_features, human_labels, test_size=0.2)
train = HumanDataset(X_train, Y_train)
toc = time.time() print('Loading Time: ' + str(1000 * (toc - tic)) + 'ms') print('') return train, x_test, y_train
|