{"action":"opened","issue":{"url":"https://api.github.com/repos/mblondel/lightning/issues/54","repository_url":"https://api.github.com/repos/mblondel/lightning","labels_url":"https://api.github.com/repos/mblondel/lightning/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/mblondel/lightning/issues/54/comments","events_url":"https://api.github.com/repos/mblondel/lightning/issues/54/events","html_url":"https://github.com/mblondel/lightning/issues/54","id":134620290,"number":54,"title":"Bug in predict_proba in SAGClassifier","user":{"login":"casotto","id":16337980,"avatar_url":"https://avatars.githubusercontent.com/u/16337980?v=3","gravatar_id":"","url":"https://api.github.com/users/casotto","html_url":"https://github.com/casotto","followers_url":"https://api.github.com/users/casotto/followers","following_url":"https://api.github.com/users/casotto/following{/other_user}","gists_url":"https://api.github.com/users/casotto/gists{/gist_id}","starred_url":"https://api.github.com/users/casotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/casotto/subscriptions","organizations_url":"https://api.github.com/users/casotto/orgs","repos_url":"https://api.github.com/users/casotto/repos","events_url":"https://api.github.com/users/casotto/events{/privacy}","received_events_url":"https://api.github.com/users/casotto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-18T16:00:08Z","updated_at":"2016-02-18T16:00:08Z","closed_at":null,"body":"Running predict_proba in `SAGClassifier` method gives the following error\r\n\r\n\r\n\t  File \"C:\\Users\\M.casotto\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\lightning\\impl\\base.py\", line 42, in predict_proba\r\n\t\tif len(self.classes_) != 2:\r\n\r\n\tAttributeError: 'StructuredSparsitySAGA' object has no attribute 'classes_'\r\n\t\r\nThe `self.classes_` member is defined inside the BaseClassifier method when \r\ncalling `_set_label_transformers` that encodes the reponse vector in a vector \r\nof 1/-1 (last value by default).\r\n\r\n    def _set_label_transformers(self, y, reencode=False, neg_label=-1):\r\n        if reencode:\r\n            self.label_encoder_ = LabelEncoder()\r\n            y = self.label_encoder_.fit_transform(y).astype(np.int32)\r\n        else:\r\n            y = y.astype(np.int32)\r\n\r\n        self.label_binarizer_ = LabelBinarizer(neg_label=neg_label,\r\n                                               pos_label=1)\r\n        self.label_binarizer_.fit(y)\r\n        self.classes_ = self.label_binarizer_.classes_.astype(np.int32)\r\n        n_classes = len(self.label_binarizer_.classes_)\r\n        n_vectors = 1 if n_classes <= 2 else n_classes\r\n\r\n        return y, n_classes, n_vectors\r\n        \r\n        \r\nUnfortunately in the inherited class `SAGClassifier`, when calling the `fit` \r\nmethod the reponse vector is casted to 1/-1 using `LabelBinarizer` instead\r\nof  `_set_label_transformers`, see for example\r\n\r\n\tclass SAGClassifier(BaseClassifier, _BaseSAG):\r\n\t\tdef fit(self, X, y):\r\n\t\t\tif not self.is_saga and self.penalty is not None:\r\n\t\t\t\traise ValueError('Penalties in SAGClassifier. Please use '\r\n\t\t\t\t\t\t\t\t 'SAGAClassifier instead.'\r\n\t\t\t\t\t\t\t\t '.')\r\n\t\t\tself.label_binarizer_ = LabelBinarizer(neg_label=-1, pos_label=1)\r\n\t\t\tY = np.asfortranarray(self.label_binarizer_.fit_transform(y),\r\n\t\t\t\t\t\t\t\t  dtype=np.float64)\r\n\t\t\treturn self._fit(X, Y)\r\n\r\n\r\nAs I am not able to compile the lightning package I cannot test compilation,\r\nbut changing the above code with \r\n\r\n\tclass SAGClassifier(BaseClassifier, _BaseSAG):\r\n\t\tdef fit(self, X, y):\r\n\t\t\tif not self.is_saga and self.penalty is not None:\r\n\t\t\t\traise ValueError('Penalties in SAGClassifier. Please use '\r\n\t\t\t\t\t\t\t\t 'SAGAClassifier instead.'\r\n\t\t\t\t\t\t\t\t '.')\r\n\t\t\t\r\n\t\t\ty_binned,___,___ = self._set_label_transformers(y, neg_label=-1)\r\n\t\t\tY = np.asfortranarray(y_binned,\r\n\t\t\t\t\t\t\t\t  dtype=np.float64)\r\n\t\t\treturn self._fit(X, Y)\r\n\r\nshould work fine"}}