Close Menu
    Trending
    • Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025
    • AMD CEO Claims New AI Chips ‘Outperform’ Nvidia’s
    • How AI Agents “Talk” to Each Other
    • Creating Smart Forms with Auto-Complete and Validation using AI | by Seungchul Jeff Ha | Jun, 2025
    • Why Knowing Your Customer Drives Smarter Growth (and Higher Profits)
    • Stop Building AI Platforms | Towards Data Science
    • What If Your Portfolio Could Speak for You? | by Lusha Wang | Jun, 2025
    • High Paying, Six Figure Jobs For Recent Graduates: Report
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Supervised Learning with SCI-KIT. Most of things you need to cover in… | by Thidas Senavirathna | Feb, 2025
    Machine Learning

    Supervised Learning with SCI-KIT. Most of things you need to cover in… | by Thidas Senavirathna | Feb, 2025

    FinanceStarGateBy FinanceStarGateFebruary 21, 2025No Comments6 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Machine studying is the method whereby computer systems study to make selections from knowledge with out being explicitly programmed.

    • Supervised studying is a machine studying method the place the mannequin is skilled on labeled knowledge. The coaching knowledge contains input-output pairs, the place the output serves as a information for the mannequin to study and make predictions. This method is generally used for duties akin to classification and regression.
    • Unsupervised studying offers with unlabeled knowledge, which means the mannequin has no predefined output labels. As an alternative, it goals to uncover hidden patterns, relationships, or buildings inside the knowledge. Widespread purposes of unsupervised studying embody clustering, dimensionality discount, and anomaly detection.
    • Reinforcement studying is the place agent learns to make selections by interacting with an surroundings. The agent receives suggestions within the type of rewards or penalties primarily based on the actions it takes, which helps it study the optimum technique or coverage for attaining its objectives.
    • Classification is a method of predicting discrete outcomes or classes, akin to figuring out whether or not an electronic mail is spam or not.
    • Regression is a method of predicting steady numeric values, akin to estimating the worth of a home primarily based on its options.

    Classification will be divide into two essential classes

    • Binary classification is the place end result is simply has two outcomes. for instance spam or not. both it may be a spam or not a spam. solely two outcomes.
    • Multiclass classification is the place end result has many outcomes. for instance price 1 to 10 it may be 1 , 4 , 5 or some other between 10.

    The under code is solely offered that can assist you perceive the syntax. It’s not a working code. As you’ll be able to see, you’ll want to import a mannequin from the sklearn library, match it together with your labeled knowledge, add the knowledge you need to predict, after which show the predictions. It’s very simple. All you’ll want to do is discover the suitable mannequin on your particular job. Moreover, you must consider the accuracy of the mannequin and perceive the ideas of underfitting and overfitting, which shall be lined on the finish of this weblog.

    SCIKIT-learn Syntax

    # Import Mannequin from sklearn.module (In your case it discover the correct mannequin)
    # for instance you should use Kneighbour_classifier mannequin from sklearn.neighbour
    from sklearn.module import Mannequin
    # Initialize mannequin utilizing Mannequin
    mannequin = Mannequin()
    # Utilizing match methodology offering by sklearn.module Mannequin() match labeled knowledge
    # X symbolize options (prediction variable) inputs
    # y symbolize goal (dependent varible) end result
    mannequin.match(X,y)
    # Xnew symbolize data wanted to foretell
    Xnew = [[1,2],
    [4,12]]
    # Utilizing label knowledge it discovered within the match methodology. mannequin will predict output for X_new inputs
    mannequin.predict(X_new)

    k-Nearest Neighbors algorithm is a algorithm which is utilizing neighbour labeled knowledge to foretell end result of the observing unlabeled knowledge.

    Writer : thidas senavirathna
    # Import KNeighborsClassifier mannequin
    from sklearn.neighbors import KNeighborsClassifier

    # Substitute this with precise DataFrame creation or import
    import pandas as pd
    import numpy as np

    # Instance DataFrame
    # account_length = 10 ; customer support calls = 1 ; churn = 0 ;
    # As you seen churn is the dependent varible (end result)
    knowledge = {
    "account_length": [10, 20, 30, 40, 50, 60],
    "customer_service_calls": [1, 2, 3, 4, 5, 6],
    "churn": [0, 1, 0, 1, 0, 1] # 0: No churn, 1: Churn
    }
    churn_df = pd.DataFrame(knowledge)

    # Outline the goal and options
    y = churn_df["churn"].values
    X = churn_df[["account_length", "customer_service_calls"]].values

    # Create a KNN classifier with 6 neighbors
    knn = KNeighborsClassifier(n_neighbors=6)

    # Match the classifier to the info
    knn.match(X, y)

    # Observing knowledge (knowledge that should predict)
    X_new = np.array([[12, 40], [1, 5]])

    # Predict the labels for the X_new
    y_pred = knn.predict(X_new)

    # Print the predictions
    print("Predictions: {}".format(y_pred))

    In machine studying accuracy is an important issue that we can’t ignore.

    When we’re going to examine mannequin accuracy First, we should always break up knowledge set into two completely different knowledge units. Coaching knowledge and Take a look at Knowledge. Then we match Coaching knowledge set into the mannequin and calculate accuracy utilizing check knowledge units.

    The parameter okay within the KNN algorithm determines the variety of nearest neighbors used to categorise an information level. It considerably impacts the complexity and accuracy of the mannequin.

    Decrease Okay will lead mannequin into Underfitting and Larger Okay will lead mannequin into overfitting

    Undefitting- mannequin is just too easy to seize the underlying patterns within the knowledge. Carry out badly on coaching knowledge and even worse on check knowledge.

    Overfitting — mannequin is just too complicated and begins to memorize the coaching knowledge. Carry out properly in coaching knowledge however fails on check knowledge.

    # Import required modules
    from sklearn.model_selection import train_test_split
    from sklearn.neighbors import KNeighborsClassifier
    import numpy as np
    import matplotlib.pyplot as plt

    # Separate options (X) and goal (y)
    X = churn_df.drop("churn", axis=1).values # Drop the goal column 'churn' and preserve solely options
    y = churn_df["churn"].values # Goal variable

    # Cut up the info into coaching and check units
    # test_size=0.2 means 20% of the info is for testing, and 80% is for coaching
    # random_state ensures reproducibility of the break up
    # stratify=y ensures the break up maintains the identical proportion of goal labels in each units
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)

    # Instantiate the KNN classifier with 5 neighbors
    knn = KNeighborsClassifier(n_neighbors=5)

    # Match the KNN mannequin to the coaching knowledge
    knn.match(X_train, y_train)

    # Calculate and print the accuracy of the mannequin on the check knowledge
    # This evaluates the proportion of right predictions on the check set
    print(f"Take a look at Accuracy with okay=5: {knn.rating(X_test, y_test)}")

    # Create an array of neighbor values to check (1 by 12)
    neighbors = np.arange(1, 13) # Neighbor values from 1 to 12
    train_accuracies = {} # Dictionary to retailer coaching accuracies
    test_accuracies = {} # Dictionary to retailer testing accuracies

    # Loop by every worth of neighbors
    for neighbor in neighbors:
    # Instantiate a KNN mannequin with the present variety of neighbors
    knn = KNeighborsClassifier(n_neighbors=neighbor)

    # Match the KNN mannequin to the coaching knowledge
    knn.match(X_train, y_train)

    # Calculate and retailer the accuracy on the coaching knowledge
    train_accuracies[neighbor] = knn.rating(X_train, y_train)

    # Calculate and retailer the accuracy on the check knowledge
    test_accuracies[neighbor] = knn.rating(X_test, y_test)

    # Print neighbors and corresponding accuracies for verification
    print("Neighbors:", neighbors)
    print("Coaching Accuracies:", train_accuracies)
    print("Testing Accuracies:", test_accuracies)

    # Add a title to the plot
    plt.title("KNN: Various Variety of Neighbors")

    # Plot coaching accuracies
    plt.plot(record(train_accuracies.keys()), record(train_accuracies.values()), label="Coaching Accuracy", marker='o')

    # Plot check accuracies
    plt.plot(record(test_accuracies.keys()), record(test_accuracies.values()), label="Testing Accuracy", marker='o')

    # Add legend to distinguish between coaching and testing accuracy
    plt.legend()

    # Add labels to the axes
    plt.xlabel("Variety of Neighbors")
    plt.ylabel("Accuracy")

    # Show the plot
    plt.present()



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleCameo Brings Workers Back to the Office With $10,000 Raise
    Next Article Reinforcement Learning with PDEs | Towards Data Science
    FinanceStarGate

    Related Posts

    Machine Learning

    Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025

    June 14, 2025
    Machine Learning

    Creating Smart Forms with Auto-Complete and Validation using AI | by Seungchul Jeff Ha | Jun, 2025

    June 14, 2025
    Machine Learning

    What If Your Portfolio Could Speak for You? | by Lusha Wang | Jun, 2025

    June 14, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    AI in Social Research and Polling

    April 2, 2025

    Why AI Startup Anysphere Is the Fastest-Growing Startup Ever

    June 7, 2025

    Think Out Loud: Rethinking AI with Reinforcement Learning | by Hammad Abbasi | Feb, 2025

    February 1, 2025

    OpenAI Says It Will Stay Under Nonprofit Control

    May 6, 2025

    VC Compliance Is Boring But Necessary — Here’s Why

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

    AI ML Courses in Hyderabad | Best Artificial Intelligence | by Kalyanvisualpath | Apr, 2025

    April 19, 2025

    Analisis Segmentasi Konsumen Berbasis Data | by Allysa Febriana | Apr, 2025

    April 13, 2025

    Your Competitors Are Winning with PR — You Just Don’t See It Yet

    June 6, 2025
    Our Picks

    The Method of Moments Estimator for Gaussian Mixture Models

    February 8, 2025

    The Great (Brain) Heist: How TikTok Hijacks Your Attention — The Algorithm Behind the Screen | by Builescu Daniel | Feb, 2025

    February 24, 2025

    3 Game-Changing Business Insights from My 25-Year Journey

    April 20, 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.