Prerequisite: Classifying data using SVM
In Linear SVM, the two classes were linearly separable, i.e a single straight line is able to classify both the classes. But imagine if you have three classes, obviously they will not be linearly separable. Therefore, Non-linear SVM’s come handy while handling these kinds of data where classes are not linearly separable.
We will be discussing a Non-Linear Kernel, the RBF kernel, (Radial Basis Function Kernel). So, what this kernel basically does is that it tries to transform the given data into almost linearly separable data.
Let’s consider the example of the IRIS dataset plotted with only 2 of the 4 features (Petal length and Petal Width).
Following is the scatter plot of the same:
It’s quite obvious that these classes are not linearly separable. Following is the contour plot of the non-linear SVM which has successfully classified the IRIS dataset using RBF kernel.
The above figure shows the classification of the three classes of the IRIS dataset.
- From sklearn, we imported the SVM library.
- We created 3 non-linear SVM’s (RBF kernel based).
- Each SVM was fed with 1 class kept positive and other 2 as negative. Say, SVM1 had labels corresponding to class 1 only else all were made 0. Same for SVM2 and SVM3 respectively.
- Plot the contour plot of each SVM.
- Plot the data points.
Below is the Python implementation for the same.
- Multitape Nondeterministic Turing Machine simulator
- Python | sympy RGS method
- Python | sympy Partition() method
- Python | sympy Relational() method
- Python | sympy from_rgs() method
- Difference Between Go and Python Programming Language
- Python | sympy.StrictGreaterThan() method
- Python | sympy.LessThan() method
- Python | sympy.StrictLessThan() method
- Python | sympy.GreaterThan() method
- Python OpenCV | cv2.circle() method
- Python OpenCV | cv2.rectangle() method
- Python | sys.getswitchinterval() method
- Python | sys.setswitchinterval() method
- Python | Get the first key in dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.