Model to Predict Housing Sale Prices
Import the Data
Data Exploration and Preparation
Correlation
Linear Regression
Analysis
Results
Verify Model Against Data
1.
2.
3.
4.
5.
6.
1. Abstract
This project analyzes the relationship between housing features and sale prices using a multiple linear regression. By focusing on key variables like Overall Quality, Living Area, and Garage Area, I improved the model’s accuracy to 85%. Removing weaker predictors helped eliminate noise, making the model more reliable.
The analysis showed that Overall Quality (which correlation equalss 0.80) is the biggest factor influencing home prices, followed by living space (with a correlation of 0.74) and garage size (0.69).
Using the variables with the strongest correlation and preparing the missing data helped create a more accurate and practical evaluation model.
The project reinforced how important variable selection and data preparation are in predictive modeling. It also showed that linear regression is a solid, data-driven way to estimate home prices, making it a valuable tool for real estate analysis.
2. Introduction
To begin this project, I first analyzed the smallHouseData dataset to understand its structure and identify key variables. Since regression models work best with numerical data, I filtered out non-numeric columns and sorted the remaining ones by their correlation with the target variable, 'Sale Price.' From this, I selected the top eight most correlated features to build the model. To handle missing values, I created a loop that replaced NaNs with their respective column means, ensuring a cleaner dataset for training.
Once the data was prepared, I set the independent (X) and dependent (Y) variables, excluding 'Sale Price' from the independent variables. I then implemented a Linear Regression Model code provided by my senior Dr. Williams and evaluated its performance using the model.score function. This step allowed me to assess how well the model fit the data.
For visualization, I created a histogram comparing actual 'Sale Price' values (Y-axis) with the model’s predictions (X-axis). I adjusted the colors to improve readability and make trends easier to interpret.
To further analyze the relationship between each independent variable and the target variable, I generated individual scatter plots. Using a loop, I created subplots for all selected features, arranged them in a 3x3 grid for clarity, and labeled them with their respective correlation values. This helped in understanding how each variable influenced the final predictions.
By following these steps, I successfully built a predictive model and visualized its results, gaining insights into the relationships between different housing features and their impact on pricing.
3. The Data
3. 1 Import the Data
3. 2 Data Exploration and Preparation
The columns I included for this Model were: OverallQual, GrLivArea, GarageArea, GarageCars, YearBuilt, TotalBsmtSF, GarageYrBlt, FullBath.


Description:
This scatter plot visualizes the relationship between predicted and actual sale prices. The X-axis represents the predicted values, while the Y-axis represents the actual sale prices.
The data points show a strong upward trend, indicating a positive correlation between predictions and actual values. The orange points, representing predictions, form a well-aligned diagonal trend, suggesting that the model generally performs well. However, the pink points, representing actual values, exhibit more of a dispersion.
Notably, at higher price ranges (above 300,000), the pink points deviate further from the trend, indicating that the model may struggle with high-value predictions. This could also suggest that additional factors influencing actual sale prices were not fully captured by the predictive model or reported on the data, leading to increased variance in these estimates.
3. 3 Correlation
The correlation analysis of my dataset reveals that Overall Quality (OverallQual), Above-Ground Living Area (GrLivArea), and Garage Area (GarageArea) have the strongest relationships with Sale Price, with correlation coefficients of 0.86, 0.74, and 0.69, respectively.
This indicates that homes with better materials, larger living spaces, and bigger garages tend to sell for higher prices.
Moderate correlations were found with Year Built (0.66), Total Basement Square Footage (0.62), and Full Bathrooms (0.58). While these variables impact home prices, they are less predictive than overall quality and living area.
These findings further perpetrate the fact that Overall Quality and Living Area have the strongest influence and should be the ones considered for further analysis.
Also, for futher analysis, I would like to explore additional variables such as Lot Zone and Exterior Quality. Since we found out from this analysis that size, quality, and location are some of the strongest qualities that attract buyers.
After analizying the data I found that Lot Area had a weaker correlation (0.40) than expected, suggesting that overall home size matters more than lot location.
Exterior Quality showed a higher correlation (0.70), reinforcing that both interior and exterior materials play a key role in home evaluation.
4. Project Description
4. 1 Linear Regression
4. 2 Analysis
4. 3 Results
Description:
These eight scatter plots illustrate the correlation between various housing features and sale price. The three strongest predictors of sale price are Overall Quality (OverallQual), Above-Ground Living Area (GrLivArea), and Garage Area, as indicated by their higher correlation values. In contrast, features like Full Bath and Year Built have a weaker impact.
Based on the scatter plots of the 8 independent variables previously presented it was found that Overall Quality (Corr: 0.86) exhibits the strongest correlation with sale price, suggesting that material quality, finish, and renovations significantly influence home values, making it a key factor for return on investment.
Above-Ground Living Area (GrLivArea, Corr: 0.74) shows that larger homes tend to sell for higher prices, though the relationship is slightly more scattered than Overall Quality.
Garage Area (Corr: 0.69) also plays a notable role, indicating that larger garages contribute to higher home values.
Other factors, such as Total Basement Square Footage (TotalBsmtSF, Corr: 0.62) and Number of Full Bathrooms (FullBath, Corr: 0.58), show a moderate correlation with sale price. While houses with more bathrooms and basement space generally sell for more, the effect is weaker compared to living area or quality.
Year Built (Corr: 0.66) suggests that newer homes tend to be more expensive, but the correlation is not as strong as Overall Quality or Living Area. Some older homes still fetch high prices, likely due to renovations or desirable locations.
My analysis improves upon Dr. Williams’ by expanding the dataset to include six additional variables on top of the 2 he used in his model: Overall Quality, Living Area, Garage Area, Garagge Cars, Year Built, Total Basement Area, Garage Year Built, and Full Bath. All while utilizing all 100 rows instead of just 20.
While Dr. Williams analyzed a smaller dataset with general housing features, I focused on high-impact predictors to enhance accuracy. Additionally, I explored Exterior Quality and Lot Area, finding that Exterior Quality (0.70) has a stronger correlation with Sale Price than Lot Area (0.40), reinforcing the importance of material quality in home valuation.
By leveraging a broader dataset and stronger predictors, my analysis enhances model precision by prioritizing the most influential variables while reducing noise from weaker predictors. These insights provide a clearer, data-driven approach to real estate evaluation, improving decision-making in property assessments.
For this project I used the mathematical algorithm known as Linear Regression. Which is used to model the relationship between a dependent variable, in this case, Sale Price, and one or more independent variables, in this case, Overall Quality, Living Area, Garege Area, etc.
Linear Regression models assume a linear relationship between the varuables and minimizes the difference berween observed and predicted values.
It's mathematical foundation is based on the equation:
y=m1x1+m2x2+...+mnxn+b,
Where x1,x2,...,xn = data points of all the independent variables used to make the prediction
m1,m2,...,mn = the weights
b = the bias
To implement a multiple linear regression model in Python I used the scikit-learn library.
First I imported the library: from sklearn import linear_model
Then I defined the LinearRegression as an object: lr = linear_model.LinearRegression()
Then I fitted or trained the model to fit my data using .fit(X, Y) model = lr.fit(X, Y)
And lastly, I created predictions for Y(Sale Prices) based on the given X using the python method .predict(X) predictions = model.predict(X)
Overall, the analysis of the individual scatter plots reinforce that home quality, size, and garage space are among the most influential factors in determining sale price, while features like bathrooms and construction year have a lesser impact.
The original Regression Model was more accurate based on the analysis of 8 additional independent variables, with a score of 85% accuracy.
# Evaluate the model
print("Model Score:", model.score(X, Y))
# OUT
Model Score: 0.8506197652678169
The second Regression Model that used the Jtest.csv file performed slightly worse, with a ~83% accuracy.
# Evaluate the model for test data
print("Model Score:", test_model.score(X, Y))
# OUT
Model Score: 0.8354867150858349
4. 4 Verify the model against larger Test Data




5. Conclusion
Through all these analysis, I found that linear regression effectively models the relationship between housing features and sale prices. By expanding the dataset and prioritizing high-impact variables like Overall Quality, Living Area, and Garage Area, the predictive accuracy was improved.
Among the different approaches tested, using multiple linear regression with carefully selected features produced the best results. Like I mentioned before, the model had a satisfactory rate of 85% prediction accuracy.
Including variables with strong correlations like, Overall Quality at 0.80, significantly improved the model’s performance, while removing weaker predictors helped minimize noise.
Some of the most important things I learned were that: 1- Selection Matters: Not every variable is as productive as the others. A higher correlation with the target variable lead to better predictions. 2- Cleaning Data: Handling missing or NULL values helps a lot when it comes to reliability and processing of data.
Learning about all these processes and adding previous lessons we had made it so much easier for me to organize, clean, prepare, and filter data. Which ultimetaly lead me to a better model, analysis and results.
6. References
Dr. Williams, MIT x Pro, "Building a Model to Predict Housing Prices Project Walkthrough" Video Lesson, https://classroom.emeritus.org/courses/11384/pages/building-a-model-to-predict-housing-prices-project-walkthrough-14-39?module_item_id=2002639#
W3Schools, “Matplotlib Subplot. Last Updated 2025.02.19. https://www.w3schools.com/python/matplotlib_subplot.asp.
W3Schools, “Matplotlib Scatter”. Last Updated 2025.02.19. https://www.w3schools.com/python/matplotlib_scatter.asp.
Contact me
Email: espitiablr@gmail.com