I Built an ML Prediction System with AI
How I used Claude to build a machine learning pipeline, then turned its outputs into an application using mockups, requirements, and AI coding agents.
Back in 2023, I spent nine months in a data science bootcamp learning Python, data analysis, machine learning, and deep learning. And if I rewind to 2019, I remember attending startup events, pitching my ideas with a piece of scratch paper, hoping to find a founding team of a Hustler, Hacker, and Hipster (raise your hand if you’re familiar with these terms!).
But now, things look completely different.
I can research a problem, define what I want to build, open a code editor, connect an AI coding agent, provide instructions and mockups, and… taraaa! A working application prototype in just a couple of days.
For this project, I used Claude to build a machine learning pipeline, then designed the UI/UX and worked with AI coding agents to turn its outputs into an interactive application.
Curious about the result? Check out the Crop Yield Prediction System demo on my portfolio.
Now, let’s see how I built it!
1. Define the Problem I Want to Tackle
I wanted to explore one question:
How far can AI coding agents take us in building an end-to-end machine learning system?
1.1 Define the Dataset: Crop Yield
So, why crop yield prediction?
First, a public dataset was available on Kaggle.
Second, it was a regression problem with understandable variables such as rainfall, temperature, irrigation, fertilizer usage, and crop characteristics.
It was a practical case study for experimenting with an ML workflow.
1.2 What Am I Trying to Build?
My goal wasn’t to create a production-ready agricultural forecasting system. I wanted to see how much development work AI could handle while keeping the results traceable and verifiable.
I divided the project into two parts:
- ML pipeline: Data inspection, cleaning, feature engineering, model training, evaluation, and analytical artifacts.
- Web application: An interface for exploring data, comparing models, reviewing results, and understanding workflow progress.
The challenge was connecting the two without losing the evidence behind the results.
2. How Do I Tell an AI Coding Agent What to Build?
Normally, I’d begin an ML project by exploring the data and writing Python scripts myself.
This time, I started with CLAUDE.md.
2.1 Defining the Workflow With CLAUDE.md
For those unfamiliar with Claude Code, CLAUDE.md is a Markdown file that provides project instructions and context to the coding agent.
Its objective was to build an auditable workflow for crop yield analysis, prediction, model explanation, and scenario evaluation.
Instead of writing every Python function, I defined the expected workflow, engineering rules, evaluation metrics, and required outputs.
Some important instructions included:
- Use Python for numerical calculations and never invent results.
- Preserve raw data and document cleaning decisions.
- Evaluate multiple models using consistent data splits.
- Record artifacts with run identifiers and input hashes.
- Require independent review before approving a model.
The specification described 12 intended stages, from dataset inspection to final reporting.
<button data-code="# Crop Yield Machine
## Objective
Build and operate an auditable data-science workflow that analyzes crop-yield
data, predicts crop yield, explains the model, evaluates climate scenarios,
and produces cautious recommendations.
## Core workflow
For a complete analysis:
1. Inspect the dataset.
2. Validate the schema and data quality.
3. Clean the data without silently deleting records.
4. Perform exploratory data analysis.
5. Engineer features: define the prediction target, assign feature roles,
assess leakage, and emit the preprocessing specification.
6. Split data without leakage.
7. Train baseline and tree-based regression models.
8. Compare models using holdout metrics.
9. Independently review the selected model.
10. Explain the model using supported feature-importance methods.
11. Run clearly defined what-if scenarios.
12. Generate a final Markdown report.
## General rules
– Python performs all numerical calculations.
– Never invent statistics, metrics, columns, or results.
– Read generated JSON artifacts rather than estimating results.
– Preserve the raw source file.
– Write processed data only under data/processed/.
– Write generated artifacts only under outputs/.
– Do not silently remove invalid records.
– Record excluded rows and the reason for exclusion.
– Separate observed findings from model predictions.
– Separate model predictions from recommendations.
– Do not make causal claims from correlations or feature importance.
– Label synthetic datasets clearly.
– Every run must produce a run manifest.
– Every JSON artifact must carry an envelope: artifact_type,
artifact_schema_version, created_at, run_id, and inputs.
– The inputs field records every artifact consumed, as
[{"path": …, "sha256": …}], using project-relative paths.
– A stage must stop when an upstream artifact is missing, malformed, or when a
declared input hash no longer matches the file on disk.
– Determinism means identical analytical content for identical input and
configuration. Envelope timestamps and run identifiers are expected to differ
between runs; the analytical payload must not.
– Canonical artifact paths never change and are never replaced by symlinks.
– At the end of every run, successful or failed, archive the run's artifacts to
outputs/runs// by copying them. Reference the raw and processed
datasets by path and SHA-256 instead of copying them.
– Preprocessing is defined once, declaratively, in preprocessing_pipeline.json.
Training builds its pipeline from that specification and never reimplements it.
– Feature engineering emits both leakage variants and does not choose between
them.
– A model must not be accepted without an independent review.
– An unreviewed model must never occupy outputs/models/best_model.joblib. A
model is promoted to that path only after review returns APPROVED or
APPROVED_WITH_LIMITATIONS. Until then model_metadata.json must record
selection_status = "PROVISIONAL_UNREVIEWED" and promotion_allowed = false.
– Generate one holdout split and one cross-validation sample per run, and reuse
both across every model and feature variant so comparisons differ only by
model and variant.
– Record split and sample membership as SHA-256 hashes rather than storing index
arrays inside artifacts.
– train_test_overlap_count must be zero.
– Cross-validation metrics computed on a sample must be labelled sample_based.
– model_comparison.csv is aggregated only from validated experiment artifacts;
no stage recomputes a metric that an experiment already recorded.
– Write each experiment directory atomically: build it under a temporary name,
validate every file, then rename. A failed experiment keeps a failure
experiment.json and must not leave a metrics.json.
– Do not install new packages without user approval.
– Do not access external services unless explicitly requested.
## Minimum models
Always include:
– DummyRegressor baseline
– LinearRegression
– RandomForestRegressor
– HistGradientBoostingRegressor
Additional models may be added only when justified.
## Required evaluation metrics
– MAE
– RMSE
– R²
– Cross-validation mean and standard deviation
## Required artifacts
– outputs/run_metadata/dataset_profile.json
– outputs/run_metadata/data_quality_report.json
– outputs/run_metadata/cleaning_report.json
– outputs/run_metadata/eda_summary.json
– outputs/run_metadata/feature_metadata.json
– outputs/run_metadata/selected_features.json
– outputs/run_metadata/preprocessing_pipeline.json
– outputs/run_metadata/model_comparison.csv
– outputs/run_metadata/model_review.json
– outputs/run_metadata/scenario_results.csv
– outputs/run_metadata/run_manifest.json
– outputs/reports/crop_yield_analysis.md
– outputs/runs// (archived copy of the run)
Per-experiment records live under
outputs/experiments///, holding experiment.json,
metrics.json, model.joblib, and any plots.” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
# Crop Yield Machine
## Objective
Build and operate an auditable data-science workflow that analyzes crop-yield
data, predicts crop yield, explains the model, evaluates climate scenarios,
and produces cautious recommendations.
## Core workflow
For a complete analysis:
1. Inspect the dataset.
2. Validate the schema and data quality.
3. Clean the data without silently deleting records.
4. Perform exploratory data analysis.
5. Engineer features: define the prediction target, assign feature roles,
assess leakage, and emit the preprocessing specification.
6. Split data without leakage.
7. Train baseline and tree-based regression models.
8. Compare models using holdout metrics.
9. Independently review the selected model.
10. Explain the model using supported feature-importance methods.
11. Run clearly defined what-if scenarios.
12. Generate a final Markdown report.
## General rules
- Python performs all numerical calculations.
- Never invent statistics, metrics, columns, or results.
- Read generated JSON artifacts rather than estimating results.
- Preserve the raw source file.
- Write processed data only under data/processed/.
- Write generated artifacts only under outputs/.
- Do not silently remove invalid records.
- Record excluded rows and the reason for exclusion.
- Separate observed findings from model predictions.
- Separate model predictions from recommendations.
- Do not make causal claims from correlations or feature importance.
- Label synthetic datasets clearly.
- Every run must produce a run manifest.
- Every JSON artifact must carry an envelope: artifact_type,
artifact_schema_version, created_at, run_id, and inputs.
- The inputs field records every artifact consumed, as
[{"path": ..., "sha256": ...}], using project-relative paths.
- A stage must stop when an upstream artifact is missing, malformed, or when a
declared input hash no longer matches the file on disk.
- Determinism means identical analytical content for identical input and
configuration. Envelope timestamps and run identifiers are expected to differ
between runs; the analytical payload must not.
- Canonical artifact paths never change and are never replaced by symlinks.
- At the end of every run, successful or failed, archive the run's artifacts to
outputs/runs/<run_id>/ by copying them. Reference the raw and processed
datasets by path and SHA-256 instead of copying them.
- Preprocessing is defined once, declaratively, in preprocessing_pipeline.json.
Training builds its pipeline from that specification and never reimplements it.
- Feature engineering emits both leakage variants and does not choose between
them.
- A model must not be accepted without an independent review.
- An unreviewed model must never occupy outputs/models/best_model.joblib. A
model is promoted to that path only after review returns APPROVED or
APPROVED_WITH_LIMITATIONS. Until then model_metadata.json must record
selection_status = "PROVISIONAL_UNREVIEWED" and promotion_allowed = false.
- Generate one holdout split and one cross-validation sample per run, and reuse
both across every model and feature variant so comparisons differ only by
model and variant.
- Record split and sample membership as SHA-256 hashes rather than storing index
arrays inside artifacts.
- train_test_overlap_count must be zero.
- Cross-validation metrics computed on a sample must be labelled sample_based.
- model_comparison.csv is aggregated only from validated experiment artifacts;
no stage recomputes a metric that an experiment already recorded.
- Write each experiment directory atomically: build it under a temporary name,
validate every file, then rename. A failed experiment keeps a failure
experiment.json and must not leave a metrics.json.
- Do not install new packages without user approval.
- Do not access external services unless explicitly requested.
## Minimum models
Always include:
- DummyRegressor baseline
- LinearRegression
- RandomForestRegressor
- HistGradientBoostingRegressor
Additional models may be added only when justified.
## Required evaluation metrics
- MAE
- RMSE
- R²
- Cross-validation mean and standard deviation
## Required artifacts
- outputs/run_metadata/dataset_profile.json
- outputs/run_metadata/data_quality_report.json
- outputs/run_metadata/cleaning_report.json
- outputs/run_metadata/eda_summary.json
- outputs/run_metadata/feature_metadata.json
- outputs/run_metadata/selected_features.json
- outputs/run_metadata/preprocessing_pipeline.json
- outputs/run_metadata/model_comparison.csv
- outputs/run_metadata/model_review.json
- outputs/run_metadata/scenario_results.csv
- outputs/run_metadata/run_manifest.json
- outputs/reports/crop_yield_analysis.md
- outputs/runs/<run_id>/ (archived copy of the run)
Per-experiment records live under
outputs/experiments/<run_id>/<experiment_id>/, holding experiment.json,
metrics.json, model.joblib, and any plots.
# Crop Yield Machine
## Objective
Build and operate an auditable data-science workflow that analyzes crop-yield
data, predicts crop yield, explains the model, evaluates climate scenarios,
and produces cautious recommendations.
## Core workflow
For a complete analysis:
1. Inspect the dataset.
2. Validate the schema and data quality.
3. Clean the data without silently deleting records.
4. Perform exploratory data analysis.
5. Engineer features: define the prediction target, assign feature roles,
assess leakage, and emit the preprocessing specification.
6. Split data without leakage.
7. Train baseline and tree-based regression models.
8. Compare models using holdout metrics.
9. Independently review the selected model.
10. Explain the model using supported feature-importance methods.
11. Run clearly defined what-if scenarios.
12. Generate a final Markdown report.
## General rules
- Python performs all numerical calculations.
- Never invent statistics, metrics, columns, or results.
- Read generated JSON artifacts rather than estimating results.
- Preserve the raw source file.
- Write processed data only under data/processed/.
- Write generated artifacts only under outputs/.
- Do not silently remove invalid records.
- Record excluded rows and the reason for exclusion.
- Separate observed findings from model predictions.
- Separate model predictions from recommendations.
- Do not make causal claims from correlations or feature importance.
- Label synthetic datasets clearly.
- Every run must produce a run manifest.
- Every JSON artifact must carry an envelope: artifact_type,
artifact_schema_version, created_at, run_id, and inputs.
- The inputs field records every artifact consumed, as
[{"path": ..., "sha256": ...}], using project-relative paths.
- A stage must stop when an upstream artifact is missing, malformed, or when a
declared input hash no longer matches the file on disk.
- Determinism means identical analytical content for identical input and
configuration. Envelope timestamps and run identifiers are expected to differ
between runs; the analytical payload must not.
- Canonical artifact paths never change and are never replaced by symlinks.
- At the end of every run, successful or failed, archive the run's artifacts to
outputs/runs/<run_id>/ by copying them. Reference the raw and processed
datasets by path and SHA-256 instead of copying them.
- Preprocessing is defined once, declaratively, in preprocessing_pipeline.json.
Training builds its pipeline from that specification and never reimplements it.
- Feature engineering emits both leakage variants and does not choose between
them.
- A model must not be accepted without an independent review.
- An unreviewed model must never occupy outputs/models/best_model.joblib. A
model is promoted to that path only after review returns APPROVED or
APPROVED_WITH_LIMITATIONS. Until then model_metadata.json must record
selection_status = "PROVISIONAL_UNREVIEWED" and promotion_allowed = false.
- Generate one holdout split and one cross-validation sample per run, and reuse
both across every model and feature variant so comparisons differ only by
model and variant.
- Record split and sample membership as SHA-256 hashes rather than storing index
arrays inside artifacts.
- train_test_overlap_count must be zero.
- Cross-validation metrics computed on a sample must be labelled sample_based.
- model_comparison.csv is aggregated only from validated experiment artifacts;
no stage recomputes a metric that an experiment already recorded.
- Write each experiment directory atomically: build it under a temporary name,
validate every file, then rename. A failed experiment keeps a failure
experiment.json and must not leave a metrics.json.
- Do not install new packages without user approval.
- Do not access external services unless explicitly requested.
## Minimum models
Always include:
- DummyRegressor baseline
- LinearRegression
- RandomForestRegressor
- HistGradientBoostingRegressor
Additional models may be added only when justified.
## Required evaluation metrics
- MAE
- RMSE
- R²
- Cross-validation mean and standard deviation
## Required artifacts
- outputs/run_metadata/dataset_profile.json
- outputs/run_metadata/data_quality_report.json
- outputs/run_metadata/cleaning_report.json
- outputs/run_metadata/eda_summary.json
- outputs/run_metadata/feature_metadata.json
- outputs/run_metadata/selected_features.json
- outputs/run_metadata/preprocessing_pipeline.json
- outputs/run_metadata/model_comparison.csv
- outputs/run_metadata/model_review.json
- outputs/run_metadata/scenario_results.csv
- outputs/run_metadata/run_manifest.json
- outputs/reports/crop_yield_analysis.md
- outputs/runs/<run_id>/ (archived copy of the run)
Per-experiment records live under
outputs/experiments/<run_id>/<experiment_id>/, holding experiment.json,
metrics.json, model.joblib, and any plots.
The question was whether Claude could turn these instructions into a working ML pipeline.
3. Here’s What Claude Built
3.1 Project Structure and Architecture
Claude generated Python modules for data processing, feature engineering, model training, evaluation, and experiment tracking, along with tests and structured outputs.
According to the engineering report, the system followed three layers:
- Orchestration: Coordinates execution, run tracking, and archiving.
- Specialized AI agents: Six defined roles covering data inspection, analysis, feature engineering, ML development, model review, and agricultural advice.
- Deterministic Python computation: Uses pandas, NumPy, and scikit-learn for numerical processing.
Not all defined agent roles were fully implemented in the documented run.
The architecture followed one principle:
Agents decide → Python computes → Artifacts are the contract.
I liked this separation because it made the workflow easier to inspect and trace.
3.2 Data Processing and Feature Engineering
The pipeline processed a dataset containing 1,000,000 records and 10 columns, with Yield_tons_per_hectare as the prediction target.
The dataset was assessed as likely synthetic, which limited how its results could be interpreted.
a. Data Inspection and Cleaning
The pipeline generated data quality reports and preserved all one million records, adding quality flags rather than silently deleting observations.
b. Feature Engineering
One interesting decision involved Days_to_Harvest.
Would we actually know the number of days until harvest when predicting crop yield?
If that information wasn’t available at prediction time, using it could introduce data leakage.
The pipeline therefore created two variants:
- Variant A: Excluded
Days_to_Harvest. - Variant B: Included
Days_to_Harvest.
Both were retained for model comparison.
3.3 Model Training and Evaluation
Claude compared four regression algorithms: DummyRegressor, LinearRegression, RandomForestRegressor, and HistGradientBoostingRegressor.
Each was tested with both feature variants, resulting in eight experiments, using a shared 80/20 train-test split and sample-based cross-validation.
Interestingly, LinearRegression achieved the lowest MAE among the Variant A models, approximately 0.3995 tonnes per hectare.
The engineering report attributed this largely to the near-linear relationships in the synthetic dataset.
However, the best-performing model wasn’t automatically an approved model.
LinearRegression with Variant A was selected provisionally, but independent model review was not implemented in the documented run.
Its status remained PROVISIONAL_UNREVIEWED, with model promotion disabled.
3.4 Generated Artifacts and Documentation
Claude also generated JSON and CSV artifacts documenting the ML workflow.
These files contained data quality findings, feature specifications, model comparisons, and execution metadata.
Each JSON artifact followed a standard structure with information such as its schema version, run identifier, timestamp, and input references.
The pipeline didn’t just generate results. It generated evidence explaining where those results came from.
This became particularly useful when designing the application.
For example, data quality reports could inform a Data Readiness screen, while model evaluation artifacts could support a Model Comparison dashboard.
Now, how could I turn these technical outputs into an application people could actually use?
4. From ML Pipeline to Product Design
A collection of Python scripts and JSON files isn’t exactly the most user-friendly experience.
I wanted to turn the workflow into an interactive web application.
This was where my experience as a System Analyst became particularly useful.
Before asking an AI coding agent to build the interface, I needed to define the user journey, requirements, and expected behavior.
4.1 Defining the Application Workflow
I organized the application around seven stages:
- Agent Instructions and Dataset
- Data Preparation and EDA
- Data Readiness
- Model Training and Evaluation
- Model Review
- Prediction Setup and Execution
- Scenario Analysis and Export
I also included areas for exploring historical workflow runs and detailed data and model insights.
The challenge was making the workflow understandable without overcrowding individual screens.
4.2 When AI-Generated UI Didn’t Meet My Expectations
Initially, I tried using AI to generate the interface.
But the result wasn’t quite what I had in mind.
Instead of repeatedly asking the coding agent to redesign it, I decided to create the UI/UX mockups myself.
If you know any tools or AI prompts for creating UI/UX mockups for specific use cases, please share them in the comments! 🙂
I then provided the mockups to the coding agent, along with explanations of each screen’s functionality.
Instead of simply asking it to “Build a modern ML prediction dashboard,” I could specify the components, navigation, interactions, and information each screen needed.
Three inputs guided development:
Mockups showed the intended experience. Requirements defined the expected behavior. Artifacts provided evidence of what the ML pipeline had produced.
4.3 From Mockups to a Working Application
I worked with AI coding agents incrementally, implementing individual screens and workflows, reviewing the results, and requesting changes when needed.
The result was an interactive application organized around three main areas: Workflow Management, Data & Model Insights, and Prediction System. You can explore the Crop Yield Prediction System demo on my portfolio.
Here’s a closer look at how each part works. I organized it into three main areas:
- Workflow Management: This area includes two menus:
- Workflow Builder: Presents the seven-stage ML workflow, from dataset preparation and model training to review, prediction, and scenario analysis.
- Workflow Runs: Lets users inspect recorded executions and their associated outputs.
2. Data & Model Insights: this area helps users understand the data and model behind the prediction system:
- Data Dictionary: Explains the dataset’s variables.
- Exploratory Data Analysis: Presents data distributions and relationships.
- Data Readiness: Shows data quality findings and readiness considerations.
- Model Comparison & Selection: Compares model performance and identifies the provisional candidate.
- Model Review: Before trying the prediction experience, users can visit Model Review to inspect the candidate model and simulate an approval decision. Once it is approved, users can proceed to prediction system.
However, this is a browser-only demonstration. A simulated approval does not change the actual model authorization, which remains blocked until the required review and evidence are completed.
3. Prediction System: Users can enter crop and environmental information, such as rainfall, temperature, irrigation, and fertilizer usage, to generate a crop yield prediction.
The application also provides:
- Prediction Results: Displays the predicted yield and compares the selected inputs with a reference scenario.
- What-if Analysis: Lets users explore how changes in rainfall, temperature, fertilizer, or irrigation affect predicted yield while keeping other inputs unchanged.
- Prediction Report: Generates a downloadable PDF summarizing the scenario, prediction results, what-if analysis, and key insights.
The goal was to make the ML workflow more accessible while remaining transparent about what had been implemented, demonstrated, and independently verified.
This experience reminded me that AI-assisted development isn’t just about generating code quickly. It’s about making sure the implementation matches the requirements and what the system actually supports.
4.4 Testing, Verification, and Deployment
Before deployment, I needed to verify the application build, navigation, and artifact references.
The production build and workflow checks passed, and all 53 artifact references resolved. Missing or unverified sources remained explicitly disclosed.
Separately, the engineering report documented 112 passing tests and five skipped tests, covering areas such as preprocessing, artifact contracts, leakage safeguards, and reproducibility.
However, the report also identified limitations, including the likely synthetic dataset and incomplete model review and explainability functionality.
Eventually, I deployed the application as a portfolio prototype, while keeping those limitations visible.
Passing tests and a successful deployment don’t automatically mean a system is ready for real-world use.
How Much Did It Cost?
One thing I almost forgot to mention: the cost!
During this experiment, I spent $30 in Claude credits.
5. What I Learned From Building With AI
This project left me with four lessons.
5.1 Clear Requirements Matter More Than Long Prompts
My CLAUDE.md defined the workflow, constraints, and expected outputs.
But even clear instructions required me to review whether the results matched my intentions.
5.2 Technical Knowledge Still Matters
I didn’t write every Python script, but my data science background helped me understand decisions about leakage, preprocessing, and model evaluation.
AI made implementation faster, but technical knowledge helped me evaluate the results.
5.3 Product Design Is More Than a Functional Interface
The first AI-generated UI didn’t meet my expectations, so I created the mockups myself.
This reminded me that functional screens aren’t necessarily good user experiences. Navigation, information hierarchy, and interactions still require thoughtful decisions.
5.4 Human Verification Remains Essential
Artifacts and automated tests helped document what the system had accomplished.
But they couldn’t establish that the model was approved or the application was suitable for real-world use.
AI can automate implementation and parts of verification, but human judgment remains essential.
What’s Next?
Building this project made me curious about another question:
How can we make AI coding agents more reliable for complex, long-running development tasks?
That’s what I plan to explore in my next article, focusing on requirements engineering, context management, and harness engineering.
Because building with AI isn’t just about writing better prompts. It’s also about creating the right environment for agents to work effectively.


