From b34e3efc07e01e767d5916b1b93064776975e99d Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Wed, 23 Sep 2020 14:57:00 +0200 Subject: [PATCH] Gracefully handle the single-object case in svm --- csrank/core/pairwise_svm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/csrank/core/pairwise_svm.py b/csrank/core/pairwise_svm.py index becd9696..c3f68acd 100644 --- a/csrank/core/pairwise_svm.py +++ b/csrank/core/pairwise_svm.py @@ -75,7 +75,6 @@ def fit(self, X, Y, **kwargs): """ self._pre_fit() _n_instances, self.n_objects_fit_, self.n_object_features_fit_ = X.shape - x_train, y_single = self._convert_instances_(X, Y) if self.use_logistic_regression: self.model_ = LogisticRegression( C=self.C, @@ -93,6 +92,10 @@ def fit(self, X, Y, **kwargs): ) logger.info("Linear SVC model ") + if self.n_objects_fit_ < 2: + # Nothing to learn, cannot create pairwise instances. + return self + x_train, y_single = self._convert_instances_(X, Y) if self.normalize: std_scalar = StandardScaler() x_train = std_scalar.fit_transform(x_train)