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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//! Bike Sharing dataset.
//!
//! Rental counts of the Capital Bikeshare system in Washington, D.C., over the
//! two years 2011 and 2012. Each record also carries the weather and the season
//! of its period. The task is to predict the rental count from the calendar and
//! weather attributes. Each sample carries its calendar date, and the rows stay
//! in chronological order.
//!
//! The one source archive holds two aggregations of the same rental log. Each
//! one has its own loader:
//!
//! - `bike_sharing_hourly::BikeSharingHourly` - 17,379 hourly records
//! - `bike_sharing_daily::BikeSharingDaily` - 731 daily records
//!
//! **Columns (16 hourly, 15 daily):**
//!
//! | Name | Type | Description |
//! |--------------|-----------|----------------------------------|
//! | `dteday` | `String` | calendar date as `YYYY-MM-DD` |
//! | `season` | `Numeric` | `1` = winter, `2` = spring, `3` = summer, `4` = fall |
//! | `yr` | `Numeric` | `0` = 2011, `1` = 2012 |
//! | `mnth` | `Numeric` | month, `1` to `12` |
//! | `hr` | `Numeric` | hour, `0` to `23`. The hourly subset alone holds it |
//! | `holiday` | `Numeric` | `1` on a holiday, else `0` |
//! | `weekday` | `Numeric` | `0` = Sunday to `6` = Saturday |
//! | `workingday` | `Numeric` | `1` on a day that is neither a weekend nor a holiday, else `0` |
//! | `weathersit` | `Numeric` | `1` = clear, `2` = mist, `3` = light rain or snow, `4` = heavy rain or snow |
//! | `temp` | `Numeric` | temperature in Celsius, divided by 41 |
//! | `atemp` | `Numeric` | apparent temperature in Celsius, divided by 50 |
//! | `hum` | `Numeric` | humidity, divided by 100 |
//! | `windspeed` | `Numeric` | wind speed, divided by 67 |
//! | `casual` | `Numeric` | rentals by users without a membership |
//! | `registered` | `Numeric` | rentals by members |
//! | `cnt` | `Numeric` | total rentals, the sum of `casual` and `registered` |
//!
//! The source designates the weather and calendar columns as the inputs
//! (`FEATURE_NAMES` on each loader) and `casual`, `registered`, and `cnt` as
//! the labels (`TARGET_NAMES` on each loader).
//!
//! Both subsets span `2011-01-01` to `2012-12-31`. The source normalizes
//! `temp`, `atemp`, `hum`, and `windspeed` to `[0, 1]`. The three targets make
//! a multi-output target.
//!
//! **Samples:**
//! - Hourly subset: 17,379
//! - Daily subset: 731
//!
//! **Application:** Regression / demand forecasting
//!
//! **Missing values:** none. No field is empty in either subset. The hourly
//! subset holds 17,379 of the 17,544 hours of the two years, because the source
//! omits the hours with no rental activity. The daily subset covers all 731
//! days.
//!
//! **Source:** UCI Machine Learning Repository
//! <https://doi.org/10.24432/C5W894>
use crateDOWNLOAD_RETRIES;
use crate;
use ReaderBuilder;
use ;
use Array1;
use File;
use PathBuf;
/// The URL for the Bike Sharing dataset (the ZIP archive that holds both
/// `hour.csv` and `day.csv`).
///
/// # Citation
///
/// Fanaee-T, H. (2013). Bike Sharing \[Dataset\]. UCI Machine Learning
/// Repository. <https://doi.org/10.24432/C5W894>
const BIKE_DATA_URL: &str =
"https://archive.ics.uci.edu/static/public/275/bike+sharing+dataset.zip";
/// The filename used for the downloaded ZIP archive inside the temp directory.
const BIKE_ZIP_FILENAME: &str = "bike+sharing+dataset.zip";
/// Source column index of the date (`dteday`). Column 0 is `instant`, a 1-based
/// row counter that carries no information, so no loader keeps it.
const DATE_COLUMN: usize = 1;
/// Number of target columns (`casual`, `registered`, `cnt`), in source order.
const N_TARGETS: usize = 3;
/// The names of the target columns, in source order.
const TARGET_NAMES: = ;
/// Number of columns that come before the features (`instant` and `dteday`).
const N_LEADING_COLUMNS: usize = 2;
/// Get one CSV member of the shared Bike Sharing ZIP archive.
///
/// Both subsets come from the same archive, under different member names. Each
/// one caches its own member as a separate file with its own SHA256 hash.
///
/// # Parameters
///
/// - `dir` - The directory that stores the dataset.
/// - `cache_filename` - The name of the cached file (for example,
/// `"bike_sharing_hourly.csv"`).
/// - `dataset_name` - The dataset name for error messages.
/// - `expected_sha256` - The expected SHA256 hash of the CSV member.
/// - `member_filename` - The name of the member inside the archive
/// (`"hour.csv"` or `"day.csv"`).
///
/// # Returns
///
/// - `PathBuf` - Path to the cached CSV file.
///
/// # Errors
///
/// Returns `DatasetError` if the download, the extraction, or the hash check
/// fails.
/// Parse one Bike Sharing CSV (hourly or daily) into a [`Table`].
///
/// The two subsets share one column layout: `instant`, `dteday`, the feature
/// columns, then `casual`, `registered`, and `cnt`. Only the feature list
/// differs, so `feature_names` selects the subset. The file is comma-separated
/// and starts with a header row.
///
/// The parser drops `instant`, a 1-based row counter. It keeps `dteday`
/// verbatim as a `YYYY-MM-DD` string.
///
/// # Parameters
///
/// - `dataset_name` - The dataset name for error messages.
/// - `file_path` - Path to the CSV file.
/// - `feature_names` - The feature column names, in source order.
/// - `n_samples` - Expected number of records, used to reserve capacity.
///
/// # Returns
///
/// - `Table` - One `dteday` column, one column per feature name, and the three
/// target columns.
///
/// # Errors
///
/// Returns `DatasetError` if:
/// - The file cannot be read
/// - A row has an unexpected number of columns
/// - A date field is empty
/// - A feature or target value does not parse as `f64`
/// - The file holds no records