A Dynamic Risk Assessment System
Starter files for the A Dynamic Risk Assessment System project in Udacity's Chevron ML Model Scoring and Monitoring course (cd16204), adapted from the CD0583 project. Build a workflow that trains, deploys, evaluates, and monitors a model for corporate-client attrition risk.
This repository contains unfinished templates, not a completed solution. Python files have valid syntax; unimplemented operations raise NotImplementedError with the task and project step to complete. Successful syntax compilation or import does not mean the pipeline is implemented. Run imports from the project root because the templates read config.json there. The preinstalled software does not make the unfinished pipeline runnable.
Follow the CD16204 project classroom and its rubric for the full requirements and submission instructions. Classroom access requires enrollment. The starter repository is udacity/cd16204-starter-code; the supplied Workspace already contains the project files, so cloning or a GitHub account is not required.
Set up your environment
Udacity Workspace (recommended)
Use the supplied Workspace and its preinstalled Python 3.13 ml environment.
New terminals and the editor should use /opt/conda/envs/ml/bin/python.
From a Workspace terminal, check the project root and interpreter:
cd /workspace/cd16204-starter-code
pwd
python -c "import sys; print(sys.executable)"
The interpreter should be /opt/conda/envs/ml/bin/python. If a terminal is using
another existing environment, run conda activate ml and check again. Keep the
shared environment's installed versions. Do not install packages, create a venv,
or download missing project files. If required files or software are missing,
report the Workspace setup problem. Run every project command from this root;
the templates read config.json and resolve its paths relative to the current
working directory. Use the same root and ml environment in additional terminals.
Resume after a Workspace restart
Saved files under /workspace are different from running processes and installed
scheduler state. Jobs run only while Workspace is running; missed runs are not
promised to replay. Inactivity timeouts depend on Workspace settings.
Reconnect without Reset. Reload the classroom/editor, or use its
Reconnect/Reload Window controls. Use Workspace Refresh/Start when offered;
complete normal Udacity reauthorization if prompted. Report a persistent blank
editor rather than changing browser security settings or sharing session links.
Data Reset overwrites work with starter files. Download a backup first.
Check saved files and ml. In a fresh terminal:
cd /workspace/cd16204-starter-code
pwd
python -c "import sys; print(sys.executable)"
Expect /opt/conda/envs/ml/bin/python; use conda activate ml if needed.
Check source, configured artifacts and, after Step 5 setup, processedfiles.json.
Follow its recovery contract if missing/malformed; do not silently reseed it.
No installation or new environment is needed.
Check scheduling after Step 5. Run /etc/init.d/cron status and
crontab -l. If stopped, use /etc/init.d/cron start and recheck. Report missing
tools/startup failures; no sudo, installation or service cron start.
An empty crontab is normal before setup. Restore missing entries using Step 5
while preserving unrelated jobs; saved cronjob.txt alone is not registration.
Restore the completed API. Reuse the running project server, or start
python app.py in a separate terminal at the same root using ml. Keep
127.0.0.1:8000 available; do not start a duplicate server.
Catch up with the completed pipeline. Use the same overlap lock as cron.
If your entry uses the root-level .fullprocess.lock, run:
/usr/bin/flock -n .fullprocess.lock /opt/conda/envs/ml/bin/python fullprocess.py
Use your entry's actual lock path if different; if held, let that run finish.
No new paths means a normal stop. Repair failures before retrying, preserving
processing state. An unfinished starter still raises NotImplementedError.
Confirm resumed scheduling. With Workspace and API running, check
fullprocess.log for a fresh timestamped scheduled invocation/result. A log may
be absent before its first run. Older logs, manual catch-up or listing the entry
alone are insufficient; retain actual evidence and required saved project files.
Optional maintainer/reviewer setup
Outside the learner Workspace, obtain the CD16204 starter and run from its root.
Use Python 3.13 and an isolated environment:
python3.13 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python -m pip check
python scripts/software_smoke.py
Alternatively, use the optional VS Code devcontainer, which installs requirements
at creation. See Workspace software specification for
image requirements, optional extension policy and verification limits. Neither
optional setup is a learner installation requirement.
Repository layout
| File or directory |
Purpose |
ingestion.py |
Implement data ingestion and ingestion records. |
training.py |
Implement model training and model persistence. |
scoring.py |
Implement model scoring. |
deployment.py |
Implement deployment of the model and associated records. |
diagnostics.py |
Implement predictions, dataset statistics, missing-data checks, timing, and dependency diagnostics. |
reporting.py |
Implement model-performance reports. |
app.py |
Implement the Flask API endpoints. |
apicalls.py |
Implement API calls and save their combined responses. |
fullprocess.py |
Implement the new-data and model-drift automation workflow. |
wsgi.py |
Expose the Flask application to a WSGI server. |
config.json |
Configure input, output, test-data, and deployment paths. |
requirements.txt |
Pin the project's Python dependencies. |
dependency_reference.json |
Dated shared ml version snapshot for the offline diagnostics exercise. |
practicedata/ |
Supplied practice inputs: dataset1.csv and dataset2.csv. |
sourcedata/ |
Supplied source inputs: dataset3.csv and dataset4.csv. |
testdata/ |
Supplied evaluation input: testdata.csv. |
ingesteddata/ |
Destination for your ingestion outputs. |
practicemodels/ |
Destination for your practice model and score. |
models/ |
Destination for your later-stage model and score. |
production_deployment/ |
Destination for your deployed model and associated records. |
The five supplied CSV files contain fabricated corporate data. The four output directories initially contain only .gitkeep files; these preserve the directory structure and are not input data.
Configuration
The starter begins with practice paths:
| Setting |
Initial value |
input_folder_path |
practicedata |
output_folder_path |
ingesteddata |
test_data_path |
testdata |
output_model_path |
practicemodels |
prod_deployment_path |
production_deployment |
For the process-automation stage, follow the classroom instructions to switch input_folder_path to sourcedata and output_model_path to models. Keep the directory structure consistent when using a local environment or the Udacity Workspace.
All five values are relative to the project root. Use testdata/testdata.csv
for test-data scoring and reporting. Keep ingestion outputs (finaldata.csv,
ingestedfiles.txt) under ingesteddata/; model and score under the configured
model-output folder; and the deployed model, matching score and ingestion record
under production_deployment/. Save confusionmatrix.png, apireturns.txt,
their second-run counterparts and cronjob.txt at the project root.
Complete the project
- Data ingestion: combine the input CSV data and record which files were ingested.
- Training, scoring, and deployment: train and evaluate a model, then deploy it with its score and ingestion records.
- Diagnostics: implement prediction, data-quality, timing, and dependency checks.
- Reporting and API: generate a confusion-matrix report, implement the endpoints below, and save their combined responses.
- Process automation: stop if there is no new data. Otherwise, ingest and check for drift, retrain and redeploy only when needed, then generate reports using the current deployed model in either case. Configure the required cron job according to the classroom instructions.
These are implementation tasks, not features already provided by the templates. Generated models, scores, reports, API responses, and a completed cron job are intentionally absent from the starter.
After implementing each stage, make its script runnable from the project root.
In particular, training.py, scoring.py and deployment.py contain unfinished
functions and script entry-point placeholders; connecting those functions
to their inputs is part of your work. Replace the relevant NotImplementedError
markers with your own implementation. apicalls.py keeps its unfinished requests
inside main() so importing it does not make HTTP calls. Importing the project
modules does not run the pipeline or start a server; running app.py or optional
wsgi.py explicitly starts their supplied development server, whose unfinished
endpoints still raise NotImplementedError. The intended first-run sequence is:
python ingestion.py
python training.py
python scoring.py
python deployment.py
python diagnostics.py
These commands are for your completed scripts. Do not expect the starter to pass
them before implementing the exercises. Start the API and produce the first
reports as described below. After completing the automation stage and switching
the configuration to sourcedata/models, run python fullprocess.py with the
local API running. Retain the required ten-minute scheduling exercise from the
classroom; manual execution alone does not replace it.
Stage checkpoints
Use this map while implementing the project. The commands below apply to your
completed scripts, not the unfinished starter. Add script entry points where
needed. Run from /workspace/cd16204-starter-code with the existing ml
interpreter (/opt/conda/envs/ml/bin/python); use the same root/environment in
each terminal. All output paths below are relative to that root.
Keep input_folder_path=practicedata and output_model_path=practicemodels for
Steps 1–4. After the practice run and first reports succeed, initialize
ingesteddata/processedfiles.json from the practice ingestion record and folder.
Only then switch to input_folder_path=sourcedata and output_model_path=models
for Step 5. Keep the other configuration paths unchanged.
| Stage / prerequisites |
Run, result and check |
| 1. Ingestion — Practice CSVs and initial configuration. |
Run: python ingestion.py Result: ingesteddata/finaldata.csv and ingesteddata/ingestedfiles.txt. Check: Practice data has 26 unique rows; recorded filenames match the discovered CSVs. |
| 2. Train, score, deploy — Step 1 outputs and the supplied test CSV. |
Run: In order: python training.py, python scoring.py, python deployment.py. Result: practicemodels/trainedmodel.pkl and matching latestscore.txt; model, score and ingestion record copied to production_deployment/. Check: Saved model loads and predicts; saved F1 belongs to that model on test data; deployed copies match their sources. |
| 3. Diagnostics — Ingested data, deployed model and bundled offline dependency reference. |
Run: python diagnostics.py Result: Predictions, numeric statistics, all-column missing percentages, two timings in seconds and the dated offline dependency comparison; no separate diagnostic file is required. Check: Check results against their inputs, timing order (ingestion then training), and unchanged deployment. No package installation or registry query. |
| 4. API and first reports — Steps 1–3 implemented, deployed artifacts and test data. |
Run: Terminal 1: python app.py; keep it running. Terminal 2: python apicalls.py, then python reporting.py. Result: API at http://127.0.0.1:8000; root-level apireturns.txt and confusionmatrix.png. Check: All four valid endpoint requests return HTTP 200 with meaningful results; the matrix agrees with deployed-model test predictions. |