SVM/ Dual SVM math derivation, non-linear SVM, kernel function详细

本文深入探讨支持向量机(SVM),从线性SVM的概念、目标优化问题到软间隔与 hinge 损失函数,接着介绍非线性SVM如何通过核函数解决高维问题,如多项式、高斯和径向基函数(RBF)等常见核。最后,阐述SVM的双问题和Mercer定理的重要性。
摘要由CSDN通过智能技术生成

往期文章链接目录

Linear SVM

Idea

We want to find a hyper-plane w ⊤ x + b = 0 w^\top x + b = 0 wx+b=0 that maximizes the margin.

Set up

We first show that the vector w w w is orthogonal to this hyper-plane. Let x 1 x_1 x1, x 2 x_2 x2 be any element on the hyper-plane. So we have w ⊤ x 1 + b = 0 w^\top x_1 + b = 0 wx1+b=0 and w ⊤ x 2 + b = 0 w^\top x_2 + b = 0 wx2+b=0. Then w ⊤ ( x 1 − x 2 ) = 0 w^\top (x_1 - x_2) = 0 w(x1x2)=0, which implies w w w is orthogonal to the hyper-plane. Now, we set two dashed lines to w ⊤ x + b = 1 w^\top x + b = 1 wx+b=1 and w ⊤ x + b = − 1 w^\top x + b = -1 wx+b=1. In fact, “ 1 1 1” doesn’t matter and we can pick any value here. “ 1 1 1” is just the convention.

Now we pick any line parallel (orthogonal) to w w w (hyper-plane), then the line intersect two dashed line with point x ( + ) x^{(+)} x(+) and x ( − ) x^{(-)} x(). We want to maximize the margin

m a r g i n = ∣ ∣ x ( + ) − x ( − ) ∣ ∣ margin = || x^{(+)} - x^{(-)}|| margin=x(+)x()

Re-express margin

Since w w w is parallel to x ( + ) − x ( − ) x^{(+)} - x^{(-)} x(+)x(), we have x ( + ) − x ( − ) x^{(+)} - x^{(-)} x(+)x() = λ w \lambda w λw for some λ \lambda λ. Then

x ( + ) = λ w + x ( − ) x^{(+)} = \lambda w + x^{(-)} x(+)=λw+x()

Since w ⊤ x ( + ) + b = 1 w^\top x^{(+)} + b = 1 wx(+)

Sure, here are the steps to apply SVM model using Linear Kernel function: 1. Load the dataset and split it into training and testing sets. 2. Preprocess the data by scaling or normalizing the features. 3. Import the SVM module from scikit-learn. 4. Create an instance of the SVM model with the Linear Kernel function. 5. Train the model on the training set using the fit() method. 6. Predict the output for the testing set using the predict() method. 7. Evaluate the model's performance by computing metrics such as accuracy, precision, recall, and F1 score. Here's some sample code to illustrate the process: ```python from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.svm import SVC from sklearn.metrics import accuracy_score # Load the Iris dataset iris = datasets.load_iris() X = iris.data y = iris.target # Split the data into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Preprocess the data by scaling the features scaler = StandardScaler() X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test) # Create an SVM model with Linear Kernel function svm = SVC(kernel='linear') # Train the model on the training set svm.fit(X_train, y_train) # Predict the output for the testing set y_pred = svm.predict(X_test) # Evaluate the model's performance accuracy = accuracy_score(y_test, y_pred) print("Accuracy:", accuracy) ``` This code applies an SVM model with the Linear Kernel function to the Iris dataset, which is a multiclass classification problem. The code preprocesses the data by scaling the features using StandardScaler, trains the model on the training set using the fit() method, predicts the output for the testing set using the predict() method, and evaluates the model's performance using the accuracy_score() function.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值