File size: 6,267 Bytes
13bb27f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
261
262
263
264
# NYC Taxi Fare Dataset Guide

This guide explains how to properly obtain and set up the NYC Taxi Fare Prediction dataset.

## Dataset Information

- **Name**: NYC Taxi Fare Prediction
- **Source**: Kaggle Competition
- **Records**: ~55 million records (2.63 GB)
- **Time Period**: 2009-2015
- **Link**: https://www.kaggle.com/c/nyc-taxi-fare-prediction/data

## Option 1: Download from Kaggle (Recommended for Production)

### Prerequisites

1. **Kaggle Account**
   - Sign up at https://www.kaggle.com
   - Free account is sufficient

2. **Kaggle API Setup**
   
   Install kaggle CLI:
   ```bash

   pip install kaggle

   ```

### Step-by-Step Setup

#### 1. Get Your Kaggle Credentials

1. Go to https://www.kaggle.com/settings/account
2. Click "Create New API Token"
3. This downloads `kaggle.json`

#### 2. Place Credentials

**On Linux/Mac:**
```bash

mkdir -p ~/.kaggle

cp kaggle.json ~/.kaggle/

chmod 600 ~/.kaggle/kaggle.json

```

**On Windows:**
```

Place kaggle.json in: C:\Users\<YourUsername>\.kaggle\

```

#### 3. Download the Dataset

**Method A: Using the provided script**

```bash

cd ML_Pro

python download_dataset.py

```

This:
- Authenticates with Kaggle
- Downloads the official dataset
- Extracts to `data/` directory
- Validates file structure

**Method B: Using Kaggle CLI directly**

```bash

kaggle competitions download -c nyc-taxi-fare-prediction

unzip -d data/ nyc-taxi-fare-prediction.zip

```

**Method C: Manual download**

1. Visit: https://www.kaggle.com/c/nyc-taxi-fare-prediction/data
2. Click "Download All"
3. Extract contents to `data/` folder

### Verify Download

After download, verify the dataset:

```bash

# Check file exists

ls -lh data/



# Check CSV structure

head -5 data/train.csv



# Check row count (takes 1-2 minutes)

wc -l data/train.csv

```

Expected output:
```

-rw-r--r--  1 user  staff  2.6G  May  7 12:34 train.csv

```

## Option 2: Generate Synthetic Data (Quick Testing)

For quick testing without downloading the large dataset:

```bash

python generate_synthetic_data.py

```

This creates: `data/nyc_taxi_fare.csv` (100,000 records, ~6 MB)

**Advantages:**
- βœ“ Instant generation (< 30 seconds)
- βœ“ No large download required
- βœ“ Realistic data structure
- βœ“ Good for prototyping

**Disadvantages:**
- βœ— Not real historical data
- βœ— Smaller dataset (100K vs 55M records)
- βœ— For assignment validation only

## Option 3: Sample Dataset (Medium Size)

For intermediate testing with real data:

```bash

# Download and sample first 500K rows

head -500001 data/train.csv > data/train_sample.csv



# Or use Python

python -c "

import pandas as pd

df = pd.read_csv('data/train.csv', nrows=500000)

df.to_csv('data/train_sample.csv', index=False)

"

```

## Dataset Format

### Columns (Expected)

| Column | Type | Description |
|--------|------|-------------|
| `key` | string | Unique identifier |
| `fare_amount` | float | Taxi fare ($) - **TARGET** |
| `pickup_datetime` | string | Pickup timestamp |
| `pickup_longitude` | float | Pickup location longitude |
| `pickup_latitude` | float | Pickup location latitude |
| `dropoff_longitude` | float | Dropoff location longitude |
| `dropoff_latitude` | float | Dropoff location latitude |
| `passenger_count` | int | Number of passengers |

### Example Row

```csv

key,fare_amount,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count

2015-03-25 07:30:35.000000107,14.5,2015-03-25 07:30:35 UTC,-73.999619,40.734462,-73.988403,40.733444,1

```

## Data Characteristics

### Statistics

- **Fare Range**: $0 - $500
- **Passenger Range**: 1 - 8
- **Time Span**: 2009-2015 (mostly 2015)
- **Records**: ~55 million

### Quality Issues (Handled by preprocessing)

- **Missing Values**: Some records have NaN coordinates
- **Outliers**: Some fares exceed typical NYC prices
- **Duplicates**: May exist in raw data
- **Invalid Coordinates**: Out of NYC bounds

Our `taxi_fare.py` preprocessing handles all these issues.

## Troubleshooting

### Issue: Kaggle authentication fails

```

Error: Kaggle API not installed

Solution: pip install kaggle

```

```

Error: ~/.kaggle/kaggle.json not found

Solution: Download from https://www.kaggle.com/settings/account

```

### Issue: Dataset download is slow

**Solution:**
- Kaggle isn't always fast; patience required
- Alternative: Try Method C (manual download)
- Or use the synthetic data (`generate_synthetic_data.py`)

### Issue: Disk space insufficient

- Full dataset: ~2.6 GB
- After processing: ~500 MB
- Ensure you have 5 GB free space

**Solution if low on space:**
```bash

# Use only first 100K rows for training

python train.py --sample-size 100000

```

### Issue: File corruption during download

Try re-downloading:
```bash

rm data/train.csv

python download_dataset.py

```

## File Paths (Important)

The training script expects the dataset at:

```

data/nyc_taxi_fare.csv  ← This is the expected location

```

If your file has a different name:

```bash

# Rename it

mv data/train.csv data/nyc_taxi_fare.csv



# Or specify in training

python train.py --data data/train.csv

```

## Assignment Submission Note

**IMPORTANT**: For assignment submission, ensure:

1. βœ“ The dataset used is NYC Taxi Fare Prediction
2. βœ“ Source: Kaggle (https://www.kaggle.com/c/nyc-taxi-fare-prediction)
3. βœ“ Documentation of which dataset split was used
4. βœ“ Reproducible preprocessing

This ensures compliance with assignment requirements.

## Additional Resources

- **Kaggle Competition**: https://www.kaggle.com/c/nyc-taxi-fare-prediction
- **Kaggle API Documentation**: https://docs.kaggle.com/api
- **NYC Taxi Data Blog**: https://chriswhong.com/open-data/

## Quick Start Checklist

- [ ] Choose Option 1, 2, or 3 above
- [ ] Download and extract dataset
- [ ] Place at `data/nyc_taxi_fare.csv`
- [ ] Run: `python train.py`
- [ ] Check: `artifacts/taxi_fare_ann_model.joblib` created
- [ ] Success: Metrics displayed in console

---

**Last Updated:** May 7, 2026  
**Status:** βœ“ All options validated