Close Menu
    Trending
    • Cuba’s Energy Crisis: A Systemic Breakdown
    • AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000
    • 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
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»What is K-Nearest Neighbors (KNN)? | by Raajeev H Dave (AI Man) | Jan, 2025
    Machine Learning

    What is K-Nearest Neighbors (KNN)? | by Raajeev H Dave (AI Man) | Jan, 2025

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


    from sklearn.neighbors import KNeighborsClassifier
    import numpy as np
    # Information: Options = [Size, Weight]
    X = np.array([[7, 150], [6, 120], [8, 160], [5, 110], [6, 130]])
    # Labels: 0 = Apple, 1 = Banana
    y = np.array([0, 1, 0, 1, 1])
    # Mannequin: KNN with 3 neighbors
    knn = KNeighborsClassifier(n_neighbors=3)
    knn.match(X, y)
    # Predict for a brand new fruit
    new_fruit = np.array([[7.5, 155]]) # New fruit: Measurement=7.5 cm, Weight=155 g
    prediction = knn.predict(new_fruit)
    print("Prediction:", "Apple" if prediction[0] == 0 else "Banana")
    # Information: Options = [Study Hours, Sleep Hours]
    X = np.array([[6, 8], [5, 6], [8, 8], [4, 5], [3, 6]])
    # Labels: 1 = Go, 0 = Fail
    y = np.array([1, 0, 1, 0, 0])
    # Mannequin: KNN with 3 neighbors
    knn = KNeighborsClassifier(n_neighbors=3)
    knn.match(X, y)
    # Predict for a brand new pupil
    new_student = np.array([[6, 7]]) # New pupil: Research=6 hours, Sleep=7 hours
    prediction = knn.predict(new_student)
    print("Prediction:", "Go" if prediction[0] == 1 else "Fail")
    1. KNN is Easy: It simply checks which information factors (neighbors) are closest to the brand new level.
    2. Makes use of Distances: The concept of “closeness” is predicated on the gap between information factors.
    3. Flexibility: Can be utilized for classification (e.g., go/fail) or regression (e.g., predicting home costs).

    KNN is a real-life-inspired algorithm that mimics how we make selections by asking our neighbors or checking comparable examples. From classifying fruits to diagnosing ailments or predicting grades, KNN is a superb place to begin for understanding machine studying! 😊



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleMeet the Candidates Running for 2026 IEEE President-Elect
    Next Article Want to Build a Digital Business? Here’s the Framework You Need to Succeed.
    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

    Cuba’s Energy Crisis: A Systemic Breakdown

    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

    What is MERN Stack: Everything You Need to Know?

    January 16, 2025

    Bridging Music and Mind: Cognitive Psychology in Magenta’s Creative Process | by Anwinkbiju | Mar, 2025

    March 23, 2025

    California housing market shift: Buyers are gaining power

    April 27, 2025
    Our Picks

    Cuba’s Energy Crisis: A Systemic Breakdown

    July 1, 2025

    AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000

    July 1, 2025

    STOP Building Useless ML Projects – What Actually Works

    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.