Close Menu
    Trending
    • Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025
    • Qantas data breach to impact 6 million airline customers
    • He Went From $471K in Debt to Teaching Others How to Succeed
    • An Introduction to Remote Model Context Protocol Servers
    • Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025
    • AI Knowledge Bases vs. Traditional Support: Who Wins in 2025?
    • Why Your Finance Team Needs an AI Strategy, Now
    • How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1
    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

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025
    Machine Learning

    Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025

    July 2, 2025
    Machine Learning

    From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025

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

    Top Posts

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 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

    Hailey Bieber’s Rhode Sells to E.l.f. for $1B

    May 28, 2025

    “If Only…”: How Counterfactual Explanations Make Machine Learning Understandable | by Let’s code | Apr, 2025

    April 20, 2025

    Pornhub and three other porn sites face EU child safety probe

    May 27, 2025
    Our Picks

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025

    Qantas data breach to impact 6 million airline customers

    July 2, 2025

    He Went From $471K in Debt to Teaching Others How to Succeed

    July 2, 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.