Load data from CSV files and return them as numpy arrays The use_labels parameter indicates whether one should read the first column (containing class labels). If false, return all 0s.
(filename, use_labels=True)
| 21 | |
| 22 | |
| 23 | def load_data(filename, use_labels=True): |
| 24 | """ |
| 25 | Load data from CSV files and return them as numpy arrays |
| 26 | The use_labels parameter indicates whether one should |
| 27 | read the first column (containing class labels). If false, |
| 28 | return all 0s. |
| 29 | """ |
| 30 | |
| 31 | # load column 1 to 8 (ignore last one) |
| 32 | data = np.loadtxt(open("data/" + filename), delimiter=',', |
| 33 | usecols=range(1, 9), skiprows=1) |
| 34 | if use_labels: |
| 35 | labels = np.loadtxt(open("data/" + filename), delimiter=',', |
| 36 | usecols=[0], skiprows=1) |
| 37 | else: |
| 38 | labels = np.zeros(data.shape[0]) |
| 39 | return labels, data |
| 40 | |
| 41 | |
| 42 | def save_results(predictions, filename): |