Close Menu
    Trending
    • STOP Building Useless ML Projects – What Actually Works
    • Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025
    • The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z
    • Musk’s X appoints ‘king of virality’ in bid to boost growth
    • Why Entrepreneurs Should Stop Obsessing Over Growth
    • Implementing IBCS rules in Power BI
    • What comes next for AI copyright lawsuits?
    • Why PDF Extraction Still Feels LikeHack
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Day 01 — Linear Regression. CONCEPT | by Ime Eti-mfon | Jan, 2025
    Machine Learning

    Day 01 — Linear Regression. CONCEPT | by Ime Eti-mfon | Jan, 2025

    Team_AIBS NewsBy Team_AIBS NewsJanuary 20, 2025No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    30 Days of Knowledge Science Sequence

    • Idea: Predict steady values
    • Implementation: Atypical Least Squares
    • Analysis: R-squared, RMSE

    CONCEPT

    Linear regression is a statistical methodology employed to mannequin the connection between a dependent variable (goal) and a number of unbiased variables (options). The intention is to establish the linear equation that the majority precisely predicts the goal variable primarily based on the characteristic variables.

    The equation of a easy linear regression mannequin is:

    [y = mx + c]

    the place:

    • {y} is the expected worth
    • {x} is the unbiased variable
    • {m} is the slope of the road (co-efficient)
    • {c} is the y-intercept

    IMPLEMENTATION

    Let’s think about an instance utilizing Python and its libraries.

    Instance

    Suppose we’ve got a dataset with home costs and their corresponding dimension (in sq. ft):

    # Import essential libraries

    import numpy as np
    import pandas as pd
    from sklearn.model_selection import train_test_split
    from sklearn.linear_model import LinearRegression
    from sklearn.metrics import mean_squared_error, r2_score
    import matplotlib.pyplot as plt

    import warnings # To take away warnings from my output
    warnings.simplefilter(motion = 'ignore')

    # Instance Knowledge

    knowledge = {
    'Measurement': [1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400],
    'Worth': [300000, 320000, 340000, 360000, 380000, 400000, 420000, 440000, 460000, 480000]
    }
    df = pd.DataFrame(knowledge)
    df

    # Defining Unbiased variable (characteristic) and Dependent variable (goal)

    X = df[['Size']]
    y = df['Price']

    # Splitting the info into coaching and testing units

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)

    # Creating and coaching the linear regression mannequin

    mannequin = LinearRegression()
    mannequin.match(X_train, y_train)

    # Making predictions

    y_pred = mannequin.predict(X_test)

    # Evaluating the mannequin

    mse = mean_squared_error(y_test, y_pred)
    r2 = r2_score(y_test, y_pred)
    print(f'Imply Squared Error: {mse}')
    print(f'R-squared: {r2}')

    # Plotting the outcomes

    plt.scatter(X, y, shade = 'blue') # Authentic knowledge factors
    plt.plot(X_test, y_pred, shade = 'purple', linewidth = 2). # Regression line
    plt.xlabel('Measurement (sq ft)')
    plt.ylabel('Worth ($)')
    plt.title('Linear Regression: Home Costs vs Measurement')
    plt.present()

    # Predicting with new values
    # Right here, we need to predict the value of a home when given the scale

    X_new = np.array([[3600]])
    y_pred = mannequin.predict(X_new)
    print(f'Predicted worth for X = 3600: {y_pred[0]:.0f}')

    EXPLANATION OF THE CODE

    1. Libraries: We import essential libraries like numpy, pandas, sklearn, and matplotlib.
    2. Knowledge Preparation: We create a DataFrame containing the scale and worth of homes.
    3. Characteristic and Goal: We separate the characteristic (Measurement) and the goal (Worth).
    4. Prepare-Take a look at-Cut up: We break up the info into coaching and testing units.
    5. Mannequin Coaching: We create and practice a LinearRegression mannequin utilizing the coaching knowledge.
    6. Predictions: We use the educated mannequin to foretell home costs for the take a look at set.
    7. Analysis: We consider the mannequin utilizing Imply Squared Error (MSE) and R-squared (R²)metrics.
    8. Visualization: We plot the unique knowledge factors and the regression line to visualise the mannequin’s efficiency.

    EVALUATION METRICS

    • Imply Squared Error (MSE): Measures the common squared distinction between the precise and predicted values. Decrease values point out higher efficiency.
    • R-squared (R²): Represents the proportion of the variance within the dependent variable that’s predictable from the unbiased variable(s). Values nearer to 1 point out a greater match.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleTikTok Ban Behind Fire Set at a Mall With Congressman’s Office, Police Say
    Next Article How a course for law students uses art museums to teach them how to present arguments
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025

    July 1, 2025
    Machine Learning

    Why PDF Extraction Still Feels LikeHack

    July 1, 2025
    Machine Learning

    🚗 Predicting Car Purchase Amounts with Neural Networks in Keras (with Code & Dataset) | by Smruti Ranjan Nayak | Jul, 2025

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    How Cross-Chain DApps Handle Gas Optimization

    March 3, 2025

    Adding Training Noise To Improve Detections In Transformers

    April 29, 2025

    S.E.C. Sues Elon Musk Over Twitter-Related Securities Violations

    January 15, 2025
    Our Picks

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025

    Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025

    July 1, 2025

    The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.