[ML L3] SVM Intro
A support vector machine (SVM) is a supervised machine learning model that uses classification algorithms for two-group classification problems. After giving an SVM model sets of labeled training data for each category, they’re able to categorize new text.
So you’re working on a text classification problem. You’re refining your training data, and maybe you’ve even tried stuff out using Naive Bayes. But now you’re feeling confident in your dataset, and want to take it one step further. Enter Support Vector Machines (SVM): a fast and dependable classification algorithm that performs very well with a limited amount of data.
How it works?
The basics of Support Vector Machines and how it works are best understood with a simple example. Let’s imagine we have two tags: red and blue, and our data has two features: x and y. We want a classifier that, given a pair of (x,y) coordinates, outputs if it’s either red or blue. We plot our already labeled training data on a plane:
A support vector machine takes these data points and outputs the hyperplane (which in two dimensions it’s simply a line) that best separates the tags. This line is the decision boundary: anything that falls to one side of it we will classify as blue, and anything that falls to the other as red.
But, what exactly is the best hyperplane? For SVM, it’s the one that maximizes the margins from both tags. In other words: the hyperplane (remember it’s a line in this case) whose distance to the nearest element of each tag is the largest.
None linear data?
Now this example was easy, since clearly the data was linearly separable — we could draw a straight line to separate red and blue. Sadly, usually things aren’t that simple. Take a look at this case:
We can introduce a new linear input param:
z = x^2 + y^2
That’s great! Note that since we are in three dimensions now, the hyperplane is a plane parallel to the x axis at a certain z (let’s say z = 1).
What’s left is mapping it back to two dimensions:
In other words, we convert a none linear dataset by introduct a new dimensions
from sklearn.svm import SVC clf = SVC(gamma='auto', kernel="rbf", C=10000.0) clf.fit(features_train, labels_train) accuracy = clf.score(features_test, labels_test) ## 1% data ##kernal="linear" accuracy=0.88 ##kernal="rbf" accuracy=0.61 ##kernal="rbf" C=10.0 accuracy=0.61 ##kernal="rbf" C=100.0 accuracy=0.61 ##kernal="rbf" C=1000.0 accuracy=0.82 ##kernal="rbf" C=10000.0 accuracy=0.89 ## 35% data ##kernal="rbf" C=10000.0 accuracy=0.96 ## 50% data ##kernal="rbf" C=10000.0 accuracy=0.987 ## 100% data ##kernal="rbf" C=10000.0 accuracy>0.99
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-06-26 [Functional Programming] Partten: When Object props satisfies function condition then do something
2019-06-26 [Algorithm] Martrix Spirals
2016-06-26 [Javascript] Ex: concatAll, map and filter