Close Menu
    Trending
    • 3D Printer Breaks Kickstarter Record, Raises Over $46M
    • People are using AI to ‘sit’ with them while they trip on psychedelics
    • Reinforcement Learning in the Age of Modern AI | by @pramodchandrayan | Jul, 2025
    • How This Man Grew His Beverage Side Hustle From $1k a Month to 7 Figures
    • Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025
    • How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins
    • Become a Better Data Scientist with These Prompt Engineering Tips and Tricks
    • Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Day 29: Support Vector Machines — Concepts and Use-Cases | by Ian Clemence | Apr, 2025
    Machine Learning

    Day 29: Support Vector Machines — Concepts and Use-Cases | by Ian Clemence | Apr, 2025

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


    Let’s implement a primary SVM classifier utilizing scikit-learn with a well known dataset. We’ll use the Iris dataset for example, which, though not a spam detection drawback, will illustrate the SVM mechanics.

    Step 1: Import Libraries and Load Information

    import numpy as np
    import pandas as pd
    from sklearn import datasets
    from sklearn.model_selection import train_test_split
    from sklearn.svm import SVC
    from sklearn.metrics import classification_report, confusion_matrix
    import matplotlib.pyplot as plt
    import seaborn as sns

    # Load the Iris dataset
    iris = datasets.load_iris()
    X = iris.information[:, :2] # We'll use solely the primary two options for simple visualization
    y = iris.goal

    # Break up the information into coaching and testing units (80% prepare, 20% check)
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

    Step 2: Practice the SVM Mannequin

    We’ll use the Assist Vector Classifier (SVC) with a linear kernel for simplicity.

    # Initialize the SVM mannequin with a linear kernel
    svm_model = SVC(kernel='linear', C=1.0, random_state=42)

    # Practice the mannequin
    svm_model.match(X_train, y_train)

    Step 3: Make Predictions and Consider the Mannequin

    # Make predictions on the check set
    y_pred = svm_model.predict(X_test)

    # Consider the mannequin
    conf_matrix = confusion_matrix(y_test, y_pred)
    class_report = classification_report(y_test, y_pred, target_names=iris.target_names)

    print("Confusion Matrix:")
    print(conf_matrix)
    print("nClassification Report:")
    print(class_report)

    Step 4: Visualizing the Choice Boundaries

    For a clearer understanding, let’s visualize the choice boundaries for our SVM mannequin utilizing the 2 options from the Iris dataset.

    # Create a mesh to plot the choice boundaries
    x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),
    np.arange(y_min, y_max, 0.02))

    # Predict classifications for every level within the mesh
    Z = svm_model.predict(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.form)

    # Plotting
    plt.determine(figsize=(10, 6))
    plt.contourf(xx, yy, Z, alpha=0.3, cmap=plt.cm.coolwarm)
    plt.scatter(X[:, 0], X[:, 1], c=y, edgecolors='okay', cmap=plt.cm.coolwarm)
    plt.xlabel(iris.feature_names[0])
    plt.ylabel(iris.feature_names[1])
    plt.title('SVM Choice Boundaries (Iris Dataset)')
    plt.present()

    This visualization exhibits how the SVM classifier partitions the characteristic area with a choice boundary. The totally different colours point out the areas the place the mannequin predicts totally different iris species.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleDigital Archivists: Protecting Public Data from Erasure
    Next Article AI in Social Research and Polling
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

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

    July 1, 2025
    Machine Learning

    Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025

    July 1, 2025
    Machine Learning

    Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025

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

    Top Posts

    3D Printer Breaks Kickstarter Record, Raises Over $46M

    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

    Building an Android Smart Gallery App for Image Organization & Search: Transitioning from Classification to Embedding Models | by D41 | Mar, 2025

    March 25, 2025

    Why AI hardware needs to be open

    June 18, 2025

    The Next Frontier in LLM Accuracy | by Mariya Mansurova | Jan, 2025

    January 4, 2025
    Our Picks

    3D Printer Breaks Kickstarter Record, Raises Over $46M

    July 1, 2025

    People are using AI to ‘sit’ with them while they trip on psychedelics

    July 1, 2025

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

    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.