'Sklearn Support vector machine LinearSVC
I was wondering why with 2 classes, LinearSVC(X, Y).fit.coef_ gives a 1*2 array with 2 values (understable because I just want a line) and with 3 classes I have 3 3*2 array with 6 values, 4 classes 4*2 array etc. It feels like It gives one too much line and when I draw the classifier I have a strange line in the middle.
Also, it looks like LinearSVC(dual=False) by default, however when I specify dual=False instead of nothing, I have another result.
Could you explain to me how it works?
Code:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
import random as rd
clf2=LinearSVC()
X=PenguinData[['Culmen Length (mm)','Culmen Depth (mm)']]
mod2=clf2.fit(X, PenguinData["value_species"])
x_min, x_max = X['Culmen Length (mm)'].min() - 1, X['Culmen Length (mm)'].max() + 1
y_min, y_max = X['Culmen Depth (mm)'].min() - 1, X['Culmen Depth (mm)'].max() + 1
line = np.linspace(x_min, x_max)
for coef, intercept in zip(mod2.coef_, mod2.intercept_):
plt.plot(line, -(line * coef[0] + intercept) / coef[1])
plt.ylim(y_min, y_max)
plt.xlim(x_min, x_max)
plt.scatter(X['Culmen Length (mm)'], X['Culmen Depth (mm)'], c=PenguinData['value_species'], cmap=plt.cm.coolwarm)
plt.show()
print(mod2.coef_)
With Nothing specified:
With dual=False specified:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


