Load Iris data. Returns: Iris data as a numpy ndarray of size [n, 4] and dtype `float32`, n being the number of available samples. Iris classification target as a numpy ndarray of [n, 3] and dtype `float32`. The order of the data is randomly shuffled.
()
| 176 | |
| 177 | |
| 178 | def load(): |
| 179 | """Load Iris data. |
| 180 | |
| 181 | Returns: |
| 182 | Iris data as a numpy ndarray of size [n, 4] and dtype `float32`, n being the |
| 183 | number of available samples. |
| 184 | Iris classification target as a numpy ndarray of [n, 3] and dtype `float32`. |
| 185 | The order of the data is randomly shuffled. |
| 186 | """ |
| 187 | iris_x = [] |
| 188 | iris_y = [] |
| 189 | for line in IRIS_DATA: |
| 190 | items = line.split(',') |
| 191 | xs = [float(x) for x in items[:4]] |
| 192 | iris_x.append(xs) |
| 193 | assert items[-1].startswith('Iris-') |
| 194 | iris_y.append(IRIS_CLASSES.index(items[-1].replace('Iris-', ''))) |
| 195 | |
| 196 | # Randomly shuffle the data. |
| 197 | iris_xy = list(zip(iris_x, iris_y)) |
| 198 | np.random.shuffle(iris_xy) |
| 199 | iris_x, iris_y = zip(*iris_xy) |
| 200 | return (np.array(iris_x, dtype=np.float32), |
| 201 | _to_one_hot(iris_y, len(IRIS_CLASSES))) |
| 202 | |
| 203 | |
| 204 | def _to_one_hot(indices, num_classes): |
nothing calls this directly
no test coverage detected