Close Menu
    Trending
    • Salesforce Is Cutting Back on Hiring Engineers Thanks to AI
    • A Bird’s Eye View of Linear Algebra: The Basics
    • How I Make Money in Data Science (Beyond My 9–5) | by Tushar Mahuri | LearnAIforproft.com | May, 2025
    • Best and Worst States for Retirement? Here’s the Ranking
    • GAIA: The LLM Agent Benchmark Everyone’s Talking About
    • Podcasts for ML people into bioinformatics | by dalloliogm | May, 2025
    • Report: NVIDIA and AMD Devising Export Rules-Compliant Chips for China AI Market
    • College Professors Turn Back to Blue Books to Combat ChatGPT
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Logistic Regression Explained Simply | Medium
    Machine Learning

    Logistic Regression Explained Simply | Medium

    FinanceStarGateBy FinanceStarGateMay 27, 2025No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Paco Sun

    Let’s say you’re making an attempt to foretell whether or not a person will click on on an advert. You’ve obtained options like time of day and the person’s final 10 interactions. You hearth up your favorite regression mannequin and… maintain up. What are we even predicting right here?

    Confusion is comprehensible, as a result of it’s not a steady worth however a sure or no. Click on or no click on.

    Now you may say, “Why not simply use linear regression and around the output?” That’s cheap, however breaks down quick. Linear regression doesn’t know its output ought to be between 0 and 1. As an alternative, it would say one thing like 1.3 or -0.7, and the way are we purported to take care of that?

    As well as, linear regression treats variations between predictions as symmetric. Nevertheless, predicting 0.01 when the true label is 0 is very completely different from predicting 0.49 in classification.

    That is the place logistic regression enters. It takes the construction of a linear mannequin, however wraps the output in a sigmoid operate that squashes predictions into a spread between 0 and 1.

    Primarily, logistic regression is a seemingly easy operate with a memorable form: the sigmoid. That is what transforms uncooked output into one thing significant, which is a likelihood.

    A linear mannequin computes a weighted sum of the inputs:

    This z right here is only a quantity. We would like a likelihood, which by definition ought to be within the vary [0, 1]. That’s the place the sigmoid steps in:

    This operate type of squeezes any actual quantity into the [0, 1] interval. When z is giant and optimistic, σ(z) is near 1; when z is giant however damaging, it approaches 0. And when z = 0? Sigmoid output 0.5, which sits proper on the choice boundary.

    For instance, say we plug z = 4.2 into the sigmoid, we get σ(z) ≈ 0.985 — in plain phrases, meaning there’s a 98.5% probability of sophistication 1.

    Logistic regression not solely says what class, but in addition tells you ways confidently it’s.

    import numpy as np
    import matplotlib.pyplot as plt

    z = np.linspace(-10, 10, 100)
    sigmoid = 1 / (1 + np.exp(-z))

    plt.plot(z, sigmoid)
    plt.title("Sigmoid Operate")
    plt.xlabel("z")
    plt.ylabel("σ(z)")
    plt.grid(True)
    plt.present()

    Output:

    Up to now, we’ve seen how the sigmoid operate turns any quantity right into a likelihood. The following query is:

    How does logistic regression really decide?

    We all know that the expected likelihood is steady between 0 and 1. However finally, we now have to resolve: class 0 or 1?

    The usual rule is simple:

    • If σ(z) ≥ 0.5, predict class 1
    • If σ(z) ≤ 0.5, predict class 0

    And because the sigmoid is 0.5 when z = 0, the boundary occurs precisely when:

    That is the equation of a hyperplane, which is a straight line in 2D, and a flat aircraft in 3D. For this reason logistic regression is taken into account a linear classifier, as a result of the dividing boundary between courses is all the time linear.

    from sklearn.datasets import make_classification
    from sklearn.linear_model import LogisticRegression
    import matplotlib.pyplot as plt
    import numpy as np

    # Artificial dataset
    X, y = make_classification(n_features=2, n_redundant=0, n_informative=2,
    n_clusters_per_class=1, n_samples=100, random_state=1)

    # Match logistic regression
    mannequin = LogisticRegression().match(X, y)

    # plot
    x_min, x_max = X[:, 0].min(), X[:, 0].max()
    y_min, y_max = X[:, 1].min(), X[:, 1].max()
    xx, yy = np.meshgrid(np.linspace(x_min, x_max, 200),
    np.linspace(y_min, y_max, 200))
    grid = np.c_[xx.ravel(), yy.ravel()]
    probs = mannequin.predict_proba(grid)[:, 1].reshape(xx.form)

    plt.contourf(xx, yy, probs, 25, cmap="RdBu", alpha=0.8)
    plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='ok')
    plt.title("Logistic Regression Resolution Boundary")
    plt.xlabel("Function 1")
    plt.ylabel("Function 2")
    plt.present()

    Output:

    Up till now, we’ve seen what logistic regression does: map inputs to chances, then make choices. However how does it study the perfect weights?

    The reply is in most probability estimation (MLE). Logistic regression finds the parameters w and b that make the noticed outcomes as possible as attainable beneath the mannequin.

    Let’s first outline the likelihood for a single knowledge level:

    This equation defines the likelihood {that a} single knowledge level belongs to class 1, the place the sigmoid operate transforms the linear mixture of options right into a likelihood between 0 and 1.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous Article3 Things I’ve Learned About Hiring and Firing After 35 Years in Business
    Next Article Understanding Matrices | Part 1: Matrix-Vector Multiplication
    FinanceStarGate

    Related Posts

    Machine Learning

    How I Make Money in Data Science (Beyond My 9–5) | by Tushar Mahuri | LearnAIforproft.com | May, 2025

    May 30, 2025
    Machine Learning

    Podcasts for ML people into bioinformatics | by dalloliogm | May, 2025

    May 29, 2025
    Machine Learning

    Aliens, Friends, Hello…. IntentSim[on]: Ah, Field Architect! Let… | by Marcelo Mezquia | May, 2025

    May 29, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    5 Lucrative Careers in AI & Machine Learning | by AKHIL GOUD | Apr, 2025

    April 16, 2025

    Starbucks Cuts the Number of Drinks Allowed in Mobile Orders

    February 7, 2025

    News Bytes 20250505: Japan’s Rapidus 2nm Chips, $7T Data Center Forecast, NVIDIA and Trade Restrictions, ‘Godfather of AI’ Issues Warning

    May 5, 2025

    A new AI translation system for headphones clones multiple voices simultaneously

    May 9, 2025

    Podcasts for ML people into bioinformatics | by dalloliogm | May, 2025

    May 29, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    The Turing Test at 75: Alan Turing’s Visionary Framework for Machine Intelligence | by Saif Ali | Apr, 2025

    April 6, 2025

    How to Ensure Your AI Solution Does What You Expect iI to Do

    April 29, 2025

    TSMC to Invest $100B in 3 New U.S. Fabs, Packaging, R&D

    March 5, 2025
    Our Picks

    Is a Simple Model always Worse than a Complex Model? | by Yoshimasa | Mar, 2025

    March 17, 2025

    The Secrets to Success for Alexander’s Patisserie

    May 13, 2025

    How to Develop a Robust Risk Management System for Your Business

    March 26, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

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