Close Menu
    Trending
    • What comes next for AI copyright lawsuits?
    • Why PDF Extraction Still Feels LikeHack
    • GenAI Will Fuel People’s Jobs, Not Replace Them. Here’s Why
    • Millions of websites to get ‘game-changing’ AI bot blocker
    • I Worked Through Labor, My Wedding and Burnout — For What?
    • Cloudflare will now block AI bots from crawling its clients’ websites by default
    • 🚗 Predicting Car Purchase Amounts with Neural Networks in Keras (with Code & Dataset) | by Smruti Ranjan Nayak | Jul, 2025
    • Futurwise: Unlock 25% Off Futurwise Today
    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

    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
    Machine Learning

    Reinforcement Learning in the Age of Modern AI | by @pramodchandrayan | Jul, 2025

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

    Top Posts

    What comes next for AI copyright lawsuits?

    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

    NVIDIA’s Jetson Orin Nano Super: A Palm-Sized AI Powerhouse | by Cogni Down Under | Dec, 2024

    December 19, 2024

    Nine Pico PIO Wats with Rust (Part 2)

    March 14, 2025

    Defeating Fraudsters at the Finish Line: The Power of AI in Gaming Transactions

    December 20, 2024
    Our Picks

    What comes next for AI copyright lawsuits?

    July 1, 2025

    Why PDF Extraction Still Feels LikeHack

    July 1, 2025

    GenAI Will Fuel People’s Jobs, Not Replace Them. Here’s Why

    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.