• Predicting City Profits Using Linear Regression in Python

     


    📍 Introduction

    Have you ever wondered how businesses can predict their profits based on the population of a city? Using Supervised Learning, specifically Linear Regression, we can build a simple yet powerful model that learns from past data and makes predictions for future inputs. 🚀

    In this blog, I’ll walk you through a project where a Linear Regression model was trained on a dataset of city populations and their corresponding profits. The goal? To predict future profits for a business by simply inputting the population of a new city.


    📂 Dataset

    The dataset consists of 100 samples, each containing:

    • Population (in 10,000s)

    • Profit (in $10,000s)

    Here’s a glimpse of the data:

    PopulationProfit
    4.3711.35
    9.5617.45
    7.5914.43

    This data follows a linear trend with some noise — perfect for a supervised learning task.


    🔧 Model Training

    Using Python, NumPy, and a bit of linear algebra, I trained a Linear Regression model with the following steps:

    1. Data Loading: The CSV file is loaded using pandas.

    2. Model Initialization: Parameters w (weight) and b (bias) are initialized.

    3. Cost Function: The Mean Squared Error (MSE) is calculated to evaluate predictions.

    4. Gradient Descent: The parameters are updated iteratively to minimize the cost.

    5. Prediction: Once trained, the model predicts profits based on new population values.


    💻 Try It Yourself

    You can view the full source code, dataset, training logic, and prediction demo here:

    👉 🔗 GitHub Repository: Machine Learning Profit-Population Model

    Feel free to clone the repo, run the notebook, and experiment with your own population values.


    📈 Sample Prediction

    python
    population = 7.5 # in 10,000s predicted_profit = w * population + b print(f"Predicted profit: ${predicted_profit * 10000:.2f}")

    When entering a population of 75,000, the model might predict a profit of around $125,000, depending on the final trained weights.


    📚 Conclusion

    This project is a classic example of Supervised Learning — training a model on labeled data to predict outcomes. It demonstrates how a simple linear model can help businesses make data-driven decisions.

    If you're a beginner in machine learning or data science, this is a perfect project to understand the fundamentals of:

    • Data preprocessing

    • Gradient descent

    • Cost function optimization

    • Real-world applications of ML


    💬 Got questions or want to collaborate? Drop a comment on GitHub or connect with me on LinkedIn!

    Happy Learning! 🤖💡

  • 0 Comments:

    Post a Comment

    GET A FREE QUOTE NOW

    Have questions about fees or need personalized assistance? Feel free to visit my LinkedIn profile for more details and inquiries!

    Powered by Blogger.
    ADDRESS

    CB-1279, Street no 8, Chour Chowk, Rawalpindi, Pakistan

    EMAIL

    adnanxn34101@gmail.com

    MOBILE PHONE

    +92346-802913-8
    +92317-052974-0