pystruct / pystruct

Simple structured learning framework for python
http://pystruct.github.io
BSD 2-Clause "Simplified" License
665 stars 174 forks source link

UnboundLocalError when fitting example with only one label #112

Open christian-rauch opened 10 years ago

christian-rauch commented 10 years ago

When fitting a data set with only one label (all entries in y are equal), the following error is raised:

UnboundLocalError: local variable 'objective' referenced before assignment

backtrace:

Training 1-slack dual structural SVM
iteration 0
no additional constraints
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
[..]

/usr/local/lib/python2.7/dist-packages/pystruct/learners/one_slack_ssvm.pyc in fit(self, X, Y, constraints, warm_start, initialize)
    520         primal_objective = self._objective(X, Y)
    521         self.primal_objective_curve_.append(primal_objective)
--> 522         self.objective_curve_.append(objective)
    523         self.cached_constraint_.append(False)
    524 

It is reasonable that the model cannot be fit to this kind of labeled data but this situation should be caught and a more meaningful error should be raised.

amueller commented 10 years ago

Thanks for the report.