Skip to content

Commit

Permalink
Gracefully handle the single-object case in svm
Browse files Browse the repository at this point in the history
  • Loading branch information
timokau committed Sep 25, 2020
1 parent a0ed20b commit b34e3ef
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion csrank/core/pairwise_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit b34e3ef

Please sign in to comment.