Learn predictive AI with C# and ML.NET by predicting house sale prices using the Ames Housing dataset.
This project is part of the AInDotNet Predictive AI Lab Series. The goal is not simply to train a machine-learning model. The goal is to demonstrate how a developer can work through a predictive AI problem systematically:
Profile → Baseline → Hypothesis → Experiment → Compare → Improve
This exercise demonstrates how to:
- profile a real-world dataset before training a model
- understand numeric and categorical features
- identify missing data
- examine numeric feature correlation with the target
- build a baseline ML.NET regression model
- add features incrementally
- measure whether those features improve the model
- add categorical business context
- use ML.NET AutoML to compare regression approaches
- evaluate R², RMSE, MAE, and individual prediction errors
- analyze model performance across price ranges
- save the trained model
- use the model to predict the price of a hypothetical house
The larger lesson is that predictive AI is not just about choosing an algorithm.
Good results usually come from understanding the data, selecting useful features, adding business context, measuring changes, and improving the model methodically.
The strongest improvement did not come from immediately choosing a more sophisticated algorithm. It came from progressively adding better information to the model. This lab shows why data understanding and feature engineering are central to predictive AI.
Given what we know about a house, what is it likely to sell for?
This is a regression problem because the target is a continuous numeric value:
SalePrice
This project uses the Ames Housing dataset, which contains:
- 2,930 houses
- 82 columns
- historical sale prices
- structural characteristics
- neighborhood information
- zoning
- quality ratings
- garage and basement information
- many other housing attributes
The target column is:
SalePrice
Example sale-price distribution:
Minimum: $12,789
Maximum: $755,000
Average: $180,796
Median: $160,000
Before training a model, the application analyzes the dataset.
For numeric candidate features it calculates:
- minimum
- maximum
- average
- median
- missing values
For categorical candidate features it reports:
- number of unique values
- missing values
- most common values
This helps give meaning to the raw columns before they become machine-learning features.
The application calculates Pearson correlation between numeric candidate features and SalePrice.
Example:
Overall Qual 0.799
Gr Liv Area 0.707
Garage Cars 0.648
Garage Area 0.640
Total Bsmt SF 0.632
1st Flr SF 0.622
Correlation helps identify numeric features that appear to contain useful predictive signal.
Correlation is not the same as feature importance. A weakly correlated feature may still help through nonlinear relationships or interactions with other features. Categorical features such as neighborhood are not evaluated by this numeric correlation calculation.
Trainer:
SDCA Regression
Results:
R²: 0.825
RMSE: $34,675
MAE: $23,463
The purpose of the baseline is not to produce the best possible model. It gives us something to compare future experiments against.
Results:
R²: 0.850
RMSE: $32,055
MAE: $21,248
Compared with Run A:
R²: 0.825 -> 0.850
RMSE: $34,675 -> $32,055
MAE: $23,463 -> $21,248
Adding more useful numeric information improved the model, but the improvement was modest.
The model now includes features such as:
- Neighborhood
- MS Zoning
- House Style
- Building Type
- Exterior Quality
- Kitchen Quality
- Basement Quality
- Garage Quality
- Foundation
Results:
R²: 0.892
RMSE: $27,165
MAE: $17,852
Adding categorical business context produced a larger improvement than simply adding more numeric measurements.
In one representative run, AutoML selected:
LightGbmRegression
Results:
R²: 0.917
RMSE: $23,935
MAE: $16,275
Algorithm selection matters, but much of the improvement had already come from better features and better business context.
Run Description R² RMSE MAE
-----------------------------------------------------------------------------
A Basic numeric features 0.825 $34,675 $23,463
B Expanded numeric features 0.850 $32,055 $21,248
C Numeric + categorical features 0.892 $27,165 $17,852
D Full features + AutoML 0.917 $23,935 $16,275
Baseline to best model:
R² improvement: +0.092
RMSE reduction: $10,740
MAE reduction: $7,188
Aggregate metrics are useful, but they can hide important failure patterns.
This project also analyzes:
- sample predictions
- best prediction
- worst prediction
- overprediction vs underprediction
- median absolute error
- average percentage error
- error by sale-price range
A model can look good overall while still performing poorly on an important segment of the data.
- Understand the data before training a model.
- Correlation can help identify potentially useful numeric features.
- More features do not automatically produce a much better model.
- Categorical and business-context features can be extremely valuable.
- Feature engineering can matter as much as algorithm selection.
- AutoML is useful for comparing trainers and tuning hyperparameters.
- Aggregate metrics can hide important model weaknesses.
- Predictive AI development should be iterative and evidence-driven.
The workflow demonstrated by this lab is:
Profile
↓
Baseline
↓
Hypothesis
↓
Experiment
↓
Compare
↓
Improve
After training the winning model, the application creates a prediction for a hypothetical house.
Example input:
Living Area: 2,200 sq ft
Bedrooms: 3
Bathrooms: 2
Garage: 2 cars
Year Built: 2005
Overall Quality: 8/10
Neighborhood: CollgCr
Example prediction:
Predicted Price: approximately $269,000
The exact value can vary slightly depending on the AutoML experiment.
- Visual Studio 2026 or later
- .NET 10
- ML.NET
- ML.NET AutoML
Clone the repository:
git clone https://github.com/AI-n-DotNet/AInDotNet.MLNET.HousePrices.gitOpen the project in Visual Studio.
Make sure the Ames Housing dataset is available at:
Data/AmesHousing.csv
Then run the console application.
The program will:
- profile the dataset
- analyze candidate features
- calculate correlations
- train Run A
- train Run B
- train Run C
- run AutoML
- compare all experiments
- save the winning model
- predict the sale price of a hypothetical house
Once you have the project running, try changing one thing at a time.
Ideas:
- remove
OverallQual - remove
Neighborhood - add another categorical feature
- add another numeric feature
- change the train/test ratio
- increase the AutoML training time
- try another regression trainer manually
- analyze a different price range
- inspect the worst 20 predictions
- build a deliberately weaker model and explain why it performs worse
Change one major variable at a time so you can understand what caused the result.
This repository is part of a larger series of hands-on C# and ML.NET exercises designed to teach predictive AI fundamentals.
Other labs include:
- Taxi Fare Prediction
- Customer Churn Prediction
- Fraud Detection
- Support Ticket Routing
- Text Classification
- Demand Forecasting
- Sales Anomaly Detection
- Recommendation Systems
- Predictive Maintenance
This project is licensed under the MIT License.
AInDotNet focuses on practical enterprise AI using C#, .NET, ML.NET, Microsoft Azure, SQL Server, and enterprise application architecture.
The goal is to demonstrate how AI capabilities can be incorporated into real business applications rather than treated as isolated demos.
For a write up on this exercise, see: Predict House Prices with C# and ML.NET: A Practical Predictive AI Lab https://aindotnet.com/2026/08/mlnet-predict-house-prices-csharp/
For more on Predictive AI & Forecasting, visit: https://aindotnet.com/forecasting/