-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
SVC.coef_ and NuSVC.coef_ don't work as documented #9196
Copy link
Copy link
Closed
Labels
DocumentationEasyWell-defined and straightforward way to resolveWell-defined and straightforward way to resolvegood first issueEasy with clear instructions to resolveEasy with clear instructions to resolvehelp wanted
Description
Description
SVC.coef_ and NuSVC.coef_ have a shape (n_class * (n_class-1) / 2, n_features) instead of documented (n_class-1, n_features).
Steps/Code to Reproduce
from sklearn.datasets import make_classification
from sklearn import svm
X, y = make_classification(n_classes=4, n_clusters_per_class=1)
clf = svm.SVC(kernel='linear')
clf.fit(X, y)
print(clf.coef_.shape) # prints (6, 20), not (3, 20) as documentedExpected Results
According to docs shape should be (3, 20).
Actual Results
Shape is (6, 20).
By the way, documented dimension is inconsistent with other coef_ parameters of linear classifiers in muticlass case (e.g. with LinearSVC) - other classifiers use (n_classes, n_features) instead of (n_classes-1, n_features) in multiclass case.
Maybe that's the reason problem was not obvious - with n_classes=2 dimension is (1, n_features) in both formulas; with n_classes=3 dimension is (3, n_features) which is not correct according to docs, but match expected coef_ shapes of other linear classifiers.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DocumentationEasyWell-defined and straightforward way to resolveWell-defined and straightforward way to resolvegood first issueEasy with clear instructions to resolveEasy with clear instructions to resolvehelp wanted