Linear regression is a primary machine studying software usually used to foretell numbers. It’s easy and clear, nevertheless it wants the correct information to work nicely. On this challenge, I attempted to foretell home costs in Canada utilizing a dataset from Kaggle (Canadian House Prices for Top Cities). The outcomes weren’t nice, however I discovered lots about what linear regression can and may’t do. This text explains my steps, outcomes, and classes.
The dataset has details about homes in huge Canadian cities. It consists of:
- Value (what we need to predict)
- Variety of bedrooms and bogs
- Metropolis, province, inhabitants, and household earnings
- Location (latitude, longitude) and addresses
The dataset has 35,768 homes. However some information was unusual, like homes with 60+ bedrooms, so I wanted to scrub it.
To get the information prepared, I did these steps:
- Eliminated columns that don’t work for the mannequin:
Tackle
,Metropolis
,Latitude
,Longitude
.
2. Modified Province
into numbers (one-hot encoding) to make use of location.
3. Modified the Value
with a math trick (logarithm) as a result of costs have been very totally different (from 21,500 to 37,000,000).
4. Made numbers like Inhabitants
, Family_Income
, Bedrooms
, and Bogs
related in measurement utilizing a software (StandardScaler
).
5. Eliminated unusual homes with greater than 10 bedrooms or bogs (12 homes).
After cleansing, the dataset had 35,756 homes and 12 options.
I cut up the information: 80% to coach the mannequin and 20% to check it. I used linear regression on the modified costs, then turned predictions again to regular costs to test outcomes. The scores have been:
- R²: 0.2492 (how nicely the mannequin explains the information)
- RMSE: 964,286.98 (how huge the errors are)
The R² rating (0.2492) was low, so the mannequin didn’t clarify the costs nicely. The RMSE (964,286.98) confirmed huge errors in predictions. Linear regression didn’t work as a result of home costs depend upon many issues not within the dataset, like home measurement or neighborhood.
To make issues simpler, I made a smaller dataset with solely homes from Winnipeg (455 homes). I used simply two options: Bedrooms
and Bogs
. I didn’t change the costs this time as a result of they have been much less excessive (from 69,900 to 968,800).
I cut up the information once more: 80% for coaching, 20% for testing. I used linear regression. The scores have been:
- R²: 0.3786
- RMSE: 149,399.03
The R² rating (0.3786) was a bit higher, however nonetheless not good. The RMSE (149,399.03) confirmed the mannequin nonetheless made huge errors. Even with less complicated information, linear regression didn’t work nicely as a result of costs depend upon extra than simply bedrooms and bogs.
This challenge confirmed me what linear regression can’t do:
- Complicated Issues: Home costs depend upon many issues (measurement, age, location, financial system). Linear regression expects easy connections, however the information was too sophisticated.
- Dangerous Information: Unusual information (like 60+ bedrooms) and lacking essential options made the mannequin worse.
- Limits of the Software: Linear regression is robust for easy issues, nevertheless it wants the correct information. It received’t work on simply any dataset.
This challenge helped me perceive linear regression higher. It’s a superb software, however not for each downside. To make it work, you want clear information with the correct options and easy connections.