{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/11444","repository_url":"https://api.github.com/repos/scikit-learn/scikit-learn","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/11444/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/11444/comments","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/11444/events","html_url":"https://github.com/scikit-learn/scikit-learn/issues/11444","id":338639429,"node_id":"MDU6SXNzdWUzMzg2Mzk0Mjk=","number":11444,"title":"AttributeError: 'LogisticRegression' object has no attribute 'classes_' ","user":{"login":"Yuchen-Peng","id":27086146,"node_id":"MDQ6VXNlcjI3MDg2MTQ2","avatar_url":"https://avatars1.githubusercontent.com/u/27086146?v=4","gravatar_id":"","url":"https://api.github.com/users/Yuchen-Peng","html_url":"https://github.com/Yuchen-Peng","followers_url":"https://api.github.com/users/Yuchen-Peng/followers","following_url":"https://api.github.com/users/Yuchen-Peng/following{/other_user}","gists_url":"https://api.github.com/users/Yuchen-Peng/gists{/gist_id}","starred_url":"https://api.github.com/users/Yuchen-Peng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yuchen-Peng/subscriptions","organizations_url":"https://api.github.com/users/Yuchen-Peng/orgs","repos_url":"https://api.github.com/users/Yuchen-Peng/repos","events_url":"https://api.github.com/users/Yuchen-Peng/events{/privacy}","received_events_url":"https://api.github.com/users/Yuchen-Peng/received_events","type":"User","site_admin":false},"labels":[{"id":12995770,"node_id":"MDU6TGFiZWwxMjk5NTc3MA==","url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels/Documentation","name":"Documentation","color":"0b02e1","default":false},{"id":12995769,"node_id":"MDU6TGFiZWwxMjk5NTc2OQ==","url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels/Easy","name":"Easy","color":"02d7e1","default":false},{"id":723599497,"node_id":"MDU6TGFiZWw3MjM1OTk0OTc=","url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels/help%20wanted","name":"help wanted","color":"33aa3f","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-05T16:13:04Z","updated_at":"2018-07-05T20:31:06Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nIf your issue is a usage question, submit it here instead:\r\n- StackOverflow with the scikit-learn tag: http://stackoverflow.com/questions/tagged/scikit-learn\r\n- Mailing List: https://mail.python.org/mailman/listinfo/scikit-learn\r\nFor more information, see User Questions: http://scikit-learn.org/stable/support.html#user-questions\r\n-->\r\n\r\n<!-- Instructions For Filing a Bug: https://github.com/scikit-learn/scikit-learn/blob/master/CONTRIBUTING.md#filing-bugs -->\r\n\r\n#### Description\r\n<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluate_every > 0-->\r\n\r\nI'm creating a logistic regression Python model from existing parameters for production. This is done by creating a `LogisticRegression` object and manually specifying the model coefficients. When I try to use this model object and the `predict()` method to predict an np matrix, I got the error message\r\n\r\n```python\r\nAttributeError: 'LogisticRegression' object has no attribute 'classes_'\r\n```\r\nOn the other hand, the `predict_proba()` works fine.\r\n\r\n#### Steps/Code to Reproduce\r\n\r\nExample:\r\n```python\r\nfrom sklearn.linear_model import LogisticRegression\r\nimport numpy as np\r\nimport pickle\r\nimport pandas as pd\r\n\r\n# initialize model coefficience and intercepts\r\nlogreg = LogisticRegression()\r\n# also tried import sklearn.linear_model as lm, logreg = lm.LogisticRegression(), same error\r\nlogreg.intercept_ = 1\r\nlogreg.coef_ = np.array([0.5,2]).reshape((1,-1))\r\nX = np.array([[1,1],[2,2]])\r\nlogreg.predict(X)\r\n```\r\n\r\n#### Expected Results\r\nIt should return the label predicted.\r\n\r\n#### Actual Results\r\n```python\r\nAttributeError: 'LogisticRegression' object has no attribute 'classes_' \r\n```\r\n#### Versions\r\n<!--\r\nPlease run the following snippet and paste the output below.\r\nimport platform; print(platform.platform())\r\nimport sys; print(\"Python\", sys.version)\r\nimport numpy; print(\"NumPy\", numpy.__version__)\r\nimport scipy; print(\"SciPy\", scipy.__version__)\r\nimport sklearn; print(\"Scikit-Learn\", sklearn.__version__)\r\n-->\r\n\r\nDarwin-17.6.0-x86_64-i386-64bit\r\nPython 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) \r\n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]\r\nNumPy 1.14.0\r\nSciPy 1.0.0\r\nScikit-Learn 0.19.1\r\n\r\n<!-- Thanks for contributing! -->\r\n"},"comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/402843839","html_url":"https://github.com/scikit-learn/scikit-learn/issues/11444#issuecomment-402843839","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/11444","id":402843839,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjg0MzgzOQ==","user":{"login":"Yuchen-Peng","id":27086146,"node_id":"MDQ6VXNlcjI3MDg2MTQ2","avatar_url":"https://avatars1.githubusercontent.com/u/27086146?v=4","gravatar_id":"","url":"https://api.github.com/users/Yuchen-Peng","html_url":"https://github.com/Yuchen-Peng","followers_url":"https://api.github.com/users/Yuchen-Peng/followers","following_url":"https://api.github.com/users/Yuchen-Peng/following{/other_user}","gists_url":"https://api.github.com/users/Yuchen-Peng/gists{/gist_id}","starred_url":"https://api.github.com/users/Yuchen-Peng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yuchen-Peng/subscriptions","organizations_url":"https://api.github.com/users/Yuchen-Peng/orgs","repos_url":"https://api.github.com/users/Yuchen-Peng/repos","events_url":"https://api.github.com/users/Yuchen-Peng/events{/privacy}","received_events_url":"https://api.github.com/users/Yuchen-Peng/received_events","type":"User","site_admin":false},"created_at":"2018-07-05T20:31:06Z","updated_at":"2018-07-05T20:31:06Z","author_association":"NONE","body":"> The usual way would be fit the estimator, serialize it (e.g. with joblib pickle) then unserialize and predict.\r\n\r\nThe model was built in the past using other programming language. We are simply implementing the model in production, so it doesn't make sense to retrieve the build dataset.\r\n\r\n > In this case the `classes_` attributes would also need to be set.\r\n\r\nCould you be more specific on how to set the `classes_` attribute? The 'LogisticRegression' object has no attribute 'classes_', and I don't know where it comes from."}}
{"actor":{"display_login":"Yuchen-Peng"}}