Build an ML Pipeline for Short-Term Rental Prices in NYC
Build a reusable rental-price pipeline in the Udacity Workspace using bundled data,
MLflow, Hydra and scikit-learn. Normal project execution uses local files and
preinstalled software. No external account, API key, hosted repository or tracking
service is required.
This is a starter, not a completed model. Implement the marked cleaning, validation,
preprocessing, model assembly, fitting/export, MAE logging and stage-integration
TODOs. They deliberately raise NotImplementedError until completed. Infrastructure
for paths, isolated runs, tracking, comparison and evaluation is supplied.
Setup
Udacity Workspace (recommended)
The starter, both datasets and the pinned Python 3.12 environment are already
provided. Normal Workspace use requires no fork, clone, venv or package installation.
Open Terminal > New Terminal and use Bash. If an initially presented terminal
reports Run 'conda init' before 'conda activate', open a new Bash terminal and retry;
do not reinstall packages or run conda init for this project.
From the Workspace project root, activate the prepared environment and configure
local tracking before any MLflow command:
cd /workspace/cd16201-starter-code
conda activate cd16201
export MLFLOW_DISABLE_TELEMETRY=true
export MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING=false
export MLFLOW_SERVER_ENABLE_JOB_EXECUTION=false
mkdir -p artifacts/mlflow
export MLFLOW_TRACKING_URI="sqlite:///$(pwd)/artifacts/mlflow/mlflow.db"
The terminal's python should be /opt/conda/envs/cd16201/bin/python. In this
Workspace, the tracking URI resolves to
sqlite:////workspace/cd16201-starter-code/artifacts/mlflow/mlflow.db.
Repeat the activation and four exports in each new terminal, including terminals
used for EDA or the required MLflow UI activity. MLflow reads the telemetry setting
during import, before the outer CLI starts the pipeline.
Check the supplied ingestion step before implementing the learner TODOs:
mlflow run . --env-manager=local -P steps=download
This reads the bundled sample1.csv and prints a new run directory under
artifacts/runs/, containing raw.csv and manifest.json. Local tracking records
are stored under artifacts/mlflow/. This smoke check verifies the supplied download
step; it does not train a model or complete the learner implementation.
For notebooks in the Workspace editor, select Python (CD16201). The notebook's
sys.executable should be /opt/conda/envs/cd16201/bin/python. The prepared course
kernel supplies the same four MLflow settings; verify them before importing MLflow.
Exports in a terminal do not change an already-running notebook kernel.
Always pass --env-manager=local to mlflow run. Nested stage calls use the same
preinstalled environment. Runtime configuration is in config.yaml; supply overrides
through hydra_options. Avoid changing package versions during the exercise.
Optional local Linux environment preparation
Use this section only when preparing your own environment outside the Udacity
Workspace. With Python 3.12 installed, run from your local project root:
python3.12 -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip==26.2
python -m pip install -r requirements.txt
python -m pip check
Then run the four exports and the mkdir command from the Workspace setup above
from your own project root, followed by the same download smoke command. Keep your
local environment active instead of using the Workspace-specific Conda activation.
Select this environment's interpreter for local notebooks and set the same MLflow
variables in the kernel before importing MLflow.
Dependency installation can use network access during preparation; subsequent pipeline
runs use the installed environment. requirements.txt is the canonical pinned set.
Optional ydata-profiling is omitted because its current release still imports
pkg_resources, which is absent from the patched setuptools version. Use pandas
and Matplotlib for EDA in this environment.
The prepared Workspace Conda environment has been verified. The optional Conda files
refer to the same pinned set, but their provisioning recipe has not been validated.
Explore and implement
Both datasets are provided under components/get_data/data/. In the Workspace
editor, create and save src/eda/eda.ipynb using Python (CD16201) as described
above. Alternatively, with your environment active and all four MLflow variables
set, start JupyterLab from the project root:
mlflow run src/eda --env-manager=local
Use the intended environment's notebook kernel and save src/eda/eda.ipynb.
Examine sample1.csv, investigate its columns,
price distribution, missing values and dates, and explain your cleaning decisions.
Notebook paths should be relative to the project; from src/eda/, bundled data is at
../../components/get_data/data/sample1.csv. Use pandas and Matplotlib for profiling. Do not
store credentials or external download dependencies in the notebook.
Open only notebooks and model artifacts from sources you trust; executing notebooks
and loading serialized models can run code.
Complete src/basic_cleaning/run.py for parameterized price/date cleaning. The
scaffold supplies CSV reading/writing. Complete the row-count and price-range checks
in src/data_check/test_data.py; preserve the supplied schema, neighborhood,
geographic and reference-distribution checks. Complete the designated training
functions in src/train_random_forest/run.py. Finally, complete the five indicated stage-parameter functions in main.py using
the contracts below. The supplied dispatcher invokes them with env_manager="local".
Do not replace the supplied feature transformations or change the held-out split
while comparing models. No Cookiecutter generation is required.
Establish the baseline and split
After implementing cleaning and its integration, run only ingestion and cleaning:
mlflow run . --env-manager=local -P steps="download,basic_cleaning"
Each invocation prints a new run directory. Set R to that exact project-relative
path, then initialize the reference once:
R=artifacts/runs/<cleaning-run-id>
python -m components.init_reference --project_root . --source "$R/clean.csv" --source_run "$R"
mlflow run . --env-manager=local -P steps="data_check,data_split" -P hydra_options="main.source_run=$R"
The reference is a fixed snapshot. Missing references stop validation; existing
references cannot be overwritten by initialization or later cleaning. The second
command sequence creates a new run containing validation evidence and the split.
Set S to this new run directory for all three training experiments below. Partial
runs require an explicit source; they never search for the newest artifact. A failed
validation exits nonzero and prevents downstream splitting and training.
Once the TODOs and reference are ready, a full default run is:
mlflow run . --env-manager=local
This runs ingestion through training. It does not select a model or evaluate the
held-out test set. An untouched starter is expected to stop at its first TODO.
For direct component commands and output filenames, see the interface contract below.
Compare three configurations and evaluate
Use three distinct hyperparameter configurations with the same split and validation
partition. For example, vary the tree count while retaining the configured seed:
S=artifacts/runs/<validated-split-run-id>
mlflow run . --env-manager=local -P steps=train_random_forest -P hydra_options="main.source_run=$S modeling.random_forest.n_estimators=50"
mlflow run . --env-manager=local -P steps=train_random_forest -P hydra_options="main.source_run=$S modeling.random_forest.n_estimators=100"
mlflow run . --env-manager=local -P steps=train_random_forest -P hydra_options="main.source_run=$S modeling.random_forest.n_estimators=150"
Inspect the runs in the local MLflow UI (required)
Use the MLflow UI to inspect and compare your three completed training runs before
selecting a model. It reads the same project-local tracking store as training; no
external account or hosted tracking service is required.
In the Udacity Workspace, prepare the embedded preview first:
- Open the editor's Ports panel, choose Forward a Port, and enter
5000.
- Copy only the hostname from that row's Forwarded Address: the part after
https:// and before the next /. Do not include the protocol or
/proxy/5000/ path. Each Workspace has its own hostname.
- Open a second Bash terminal. Replace
your-workspace-hostname below with the
hostname you copied, then run:
cd /workspace/cd16201-starter-code
conda activate cd16201
export MLFLOW_DISABLE_TELEMETRY=true
export MLFLOW_ENABLE_SYSTEM_METRICS_LOGGING=false
export MLFLOW_SERVER_ENABLE_JOB_EXECUTION=false
mkdir -p artifacts/mlflow
export MLFLOW_TRACKING_URI="sqlite:///$(pwd)/artifacts/mlflow/mlflow.db"
WORKSPACE_HOST="your-workspace-hostname"
python -m mlflow ui --backend-store-uri "$MLFLOW_TRACKING_URI" --host 127.0.0.1 --port 5000 --allowed-hosts "$WORKSPACE_HOST,127.0.0.1:5000,localhost:5000" --cors-allowed-origins "https://$WORKSPACE_HOST"
Keep the terminal running and wait for server startup to complete. Right-click
the port 5000 row and choose Preview in Editor. This opens MLflow in the
Workspace's embedded Simple Browser, inside the course page. If the preview
opened before startup finished, refresh it. If MLflow reports an invalid Host
header, check the copied hostname, stop the server with Ctrl+C, and rerun the
command with the corrected value. Keep the host and origin lists specific to your
Workspace and the listed loopback addresses.
Outside the Workspace, use your prepared local environment in a second terminal
at the same project root and repeat the four tracking exports from setup. Start
the UI with:
python -m mlflow ui --backend-store-uri "$MLFLOW_TRACKING_URI" --host 127.0.0.1 --port 5000
Open http://127.0.0.1:5000 in a browser on that same machine. The Workspace
hostname and preview options above apply only to the Workspace route.
In MLflow, open Model training → Experiments → nyc_airbnb → Runs:
- Select the checkboxes for your three training runs and choose Compare.
Compare their hyperparameters and validation
mae and r2. Confirm matching
split_id, val_size, random_seed and stratify_by values.
- Open a training run, choose Artifacts, and select feature_importance.png.
Inspect the rendered plot and explain which features contribute most to the
model. Match it to that run's local
training/feature_importance.png.
The UI's pipeline_run_id tag identifies artifacts/runs/<run_id>/. That run's
manifest records the corresponding MLflow ID at
stages.train_random_forest.details.mlflow_run_id; the two IDs are different.
Check the manifest's exact split metadata path as well as the split ID, because
comparison requires the same split artifact and validation partition. Use these
links to distinguish training records from outer MLflow project runs.
Compare, select and evaluate
Set A, B and C to the three printed pipeline run directories. Compare
validation metrics, then explicitly select the minimum validation MAE:
A=artifacts/runs/<first-training-run-id>
B=artifacts/runs/<second-training-run-id>
C=artifacts/runs/<third-training-run-id>
python -m components.compare_runs --project_root . --runs "$A" "$B" "$C"
python -m components.compare_runs --project_root . --runs "$A" "$B" "$C" --select
mlflow run . --env-manager=local -P steps=test_regression_model
Inspect artifacts/comparison.csv, artifacts/selected_model.json, the selected
run's training/ files and the evaluation run's evaluation/metrics.json. Match
the comparison's pipeline run IDs, parameters and validation metrics to the UI
records and each run's training/parameters.json and training/metrics.json. Test
data is reserved for this final evaluation and cannot determine model selection. New
training runs leave the selection unchanged. The evaluator verifies the selected
model belongs to the recorded run and uses its matching held-out dataset.
UI inspection is required learning work. It does not change the explicit local
selection or replace JSON, CSV, plots, model files and manifests as review evidence.
The tracking database does not need to be submitted or relied on after relocation.
Local versions and new data
After completing and verifying your initial learner implementation, commit it in
your own local learner repository and create tag 1.0.0 using git tag 1.0.0.
If your learner copy has no Git history, initialize a local repository and commit the
starter source before recording these versions. Include the intended
hyperparameters in config.yaml. No remote push or hosted release is required.
Replay that exact tagged code against the second bundled sample:
python -m components.version_run --project_root . --version 1.0.0 --sample sample2.csv
The initial version should fail the supplied geographical-boundary validation and
stop before training. Inspect the recorded failure and add the required geographic
cleaning to your learner implementation. Verify it, commit the update locally and
create tag 1.0.1 using git tag 1.0.1, then run:
python -m components.version_run --project_root . --version 1.0.1 --sample sample2.csv
The helper executes existing tags in temporary isolated checkouts without changing
your working tree or fetching remote code. It records the exact commit, configuration,
input/reference checksums, exit status and run manifests under artifacts/versions/
and artifacts/runs/. The source bundle preserves the local markers for replay.
Keep both failed-initial and successful-updated evidence. Do not move an existing tag
to another revision. Keep the fixed reference from the original sample.
Prepare the submission
Workspace is the recommended submission route. Save your work in the project
directory and use the course's Workspace submission option. This route does not
require a ZIP, GitHub account, hosted repository, public URL or remote push.