An Introduction to Support Vector Machine- Supervised Machine Learning

An Introduction to Support Vector Machine- Supervised Machine Learning

An Introduction to Support Vector Machine- Supervised Machine Learning

Support Vector Machine

Support Vector Machine (SVM) is a supervised machine learning algorithm used for regression, classification, and outlier detection problems. It is widely used for classification problems, known as Support Vector Classifier (SVC), and for regression problems, known as Support Vector Regression (SVR). The term “vectors” refers to the data points that help in creating the boundary between classes. These boundaries are defined near the extreme data points, which are called support vectors.

SVM uses a hyperplane that acts as a boundary to separate data points from one class to another. This hyperplane is based on the features of the data. If there are two features, the hyperplane is a straight line; if there are three features, the plane would be 2D.

Types of SVM:

  1. Linear SVM: Used when the data is linearly separable by a straight line.
  2. Non-Linear SVM: Used when the data is not linearly separable.

Key Terms:

  • Hyperplane: The line or plane that acts as a separator between different classes.
  • Support Vectors: The data points that are closest to the hyperplane and influence its position.
  • Margins: The distance between the support vectors and the hyperplane.
# importing the libraries
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC, SVR
from sklearn.metrics import accuracy_score, mean_squared_error

# import the dataset
df = pd.read_csv("dataset.csv")

# Separating X - Features and y - Target
X = df.drop("target", axis=1)
y = df["target"]

# Train and Test Split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# SVC model
svc_model = SVC()
svc_model.fit(X_train, y_train)
y_pred_svc = svc_model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred_svc)
print(f"The Accuracy for SVC is: {accuracy}")

# SVR model
svr_model = SVR()
svr_model.fit(X_train, y_train)
y_pred_svr = svr_model.predict(X_test)
mse = mean_squared_error(y_test, y_pred_svr)
print(f"The Mean Squared Error for SVR is: {mse}")

Ready to dive deeper into the world of Data Science? Join me as we explore essential topics like Exploratory Data Analysis (EDA), Data Visualization, and building powerful Machine Learning models. Subscribe to my blog for the latest tutorials, insights, and practical tips.

Follow: X | Facebook | Instagram | Linkedin




Getting Info...

About the Author

Hey! It's Saadat Khalid Awan, a Freelance Content Writer | Copywriter | Blogger, and Data Scientist. I'm very enthusiastic about writing. I enjoy the writing process because words have a magical power that can do wonders.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.