Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Machine Learning Python #8: Support Vector Machine & Kernel Trick”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, an SVM with an RBF kernel that successfully separates circular-shaped data, something that a straight line cannot do. We also see how the parameters C and gamma change the shape of the decision boundary, then use SVM to recognize handwritten digits. Let's get started. Hello, welcome to episode 8 of the Machine Learning with Python series. Support Vector Machine, or SVM, is a classification algorithm that finds a separating line with the widest distance to the closest data points from both classes. That distance is called the margin. Its main strength is the kernel trick, a clever way to separate data that cannot be separated by a straight line.
We create a file called svm.py. First, data for two groups that are easy to separate, created with make blobs. We train SVC with a linear kernel. To draw the decision boundary, we create a function called gambar that calculates the decision function across all grid points. The solid line is the decision boundary, the two dashed lines are the margin edges, and the points that are circled are the support vectors, the closest data that determine the position of the line.
Now the challenge, data shaped like a circle inside another circle, created with make circular class. There is no straight line that can separate them. We compare the linear kernel with the RBF kernel. The linear kernel fails, accuracy is around half, same as guessing. The RBF kernel successfully separates everything perfectly. The kernel trick seems to lift the data to a higher dimension. Where the two circles can be separated by a flat plane.
The RBF kernel has two important parameters. C controls how hard the model punishes errors, a large C makes the boundary follow every point. Gamma controls how far the influence of one point reaches, a large gamma makes the boundary twist and turn. We plot four combinations on the make months data. Look at the combination with large gamma and large C. The boundary forms small islands, indicating overfitting.
Finally, SVM on real data. Create a .py file The digits dataset contains 1797 handwritten images of digits, each 8x8 pixels in size. We train SVC with an RBF kernel and achieve accuracy above 99%. Then we display 10 test images along with the model's predictions, and almost all are correct.
Done! We have learned about margins and support vectors, linear and RBF kernels, the effect of C and gamma, and SVM for recognizing digits. Remember, SVM is distance-based, so always perform feature scaling. In the next episode, we learn about ensemble learning, bagging, boosting, XGBoost, and lightGBM. Want to master machine learning and data science? Cerdas Inovasi Digital offers Python, machine learning, and AI courses from scratch, model prediction services, data analysis, and AI application development for business and research, as well as selling complete source code of this tutorial. Want to master the entire series, from machine learning basics to deploying models to the web? All 18 episodes, complete with step-by-step PDF guides, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or pay once Rp999.000 for lifetime access. Want a single class? Buy a single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com Contact us via WhatsApp, or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode. Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →