Skip to content

SVC.coef_ and NuSVC.coef_ don't work as documented #9196

@kmike

Description

@kmike

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 documented

Expected 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions