Close Menu
    Trending
    • Detecting Malicious URLs Using LSTM and Google’s BERT Models
    • Designing Pareto-optimal GenAI workflows with syftr
    • Detrás de DigiDomTek:. Cómo una tragedia personal en el Caribe… | by Benjamin R Miller | May, 2025
    • How to Build an AI-Driven Company Culture
    • The AI Hype Index: College students are hooked on ChatGPT
    • Building Real-World AI Apps with Google’s Gemini & Imagen | by Vipin Kumar | May, 2025
    • Stop Losing $500+ a Month — The Mistake Starts With a Missed Call
    • How to improve AP and invoice tasks
    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

    Detrás de DigiDomTek:. Cómo una tragedia personal en el Caribe… | by Benjamin R Miller | May, 2025

    May 28, 2025
    Machine Learning

    Building Real-World AI Apps with Google’s Gemini & Imagen | by Vipin Kumar | May, 2025

    May 28, 2025
    Machine Learning

    XGBoost, LightGBM or CatBoost? The Ultimate Test for Credit Scoring Models | by Pape | May, 2025

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

    Top Posts

    This $300,000 Problem is Sabotaging Your Team’s Productivity

    May 27, 2025

    How I Would Learn To Code (If I Could Start Over)

    April 4, 2025

    My Hands-On Journey with Google Cloud’s Vertex AI: Building Real-World GenAI Applications with Gemini & Imagen | by Sathvikambekar | Apr, 2025

    April 23, 2025

    Reactions to President Trump’s Joint Address to Congress

    March 6, 2025

    Early retirement could cut pension income nearly in half

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

    Tax season starts Monday. Here’s what you need to know

    February 20, 2025

    Making higher education more accessible to students in Pakistan | MIT News

    March 28, 2025

    Together AI Cloud Raises $305M Series B

    February 20, 2025
    Our Picks

    Why it’s so hard to use AI to diagnose cancer

    February 2, 2025

    The Automation Trap: Why Low-Code AI Models Fail When You Scale

    May 17, 2025

    Four Chinese AI startups to watch beyond DeepSeek

    February 4, 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.