{"action":"created","issue":{"url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/67","repository_url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python","labels_url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/67/comments","events_url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/67/events","html_url":"https://github.com/amueller/introduction_to_ml_with_python/issues/67","id":282550528,"node_id":"MDU6SXNzdWUyODI1NTA1Mjg=","number":67,"title":"Problem/bug with MLPClassifier using neural network (P. 110, third release)","user":{"login":"Dreaddune","id":34585076,"node_id":"MDQ6VXNlcjM0NTg1MDc2","avatar_url":"https://avatars2.githubusercontent.com/u/34585076?v=4","gravatar_id":"","url":"https://api.github.com/users/Dreaddune","html_url":"https://github.com/Dreaddune","followers_url":"https://api.github.com/users/Dreaddune/followers","following_url":"https://api.github.com/users/Dreaddune/following{/other_user}","gists_url":"https://api.github.com/users/Dreaddune/gists{/gist_id}","starred_url":"https://api.github.com/users/Dreaddune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dreaddune/subscriptions","organizations_url":"https://api.github.com/users/Dreaddune/orgs","repos_url":"https://api.github.com/users/Dreaddune/repos","events_url":"https://api.github.com/users/Dreaddune/events{/privacy}","received_events_url":"https://api.github.com/users/Dreaddune/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-12-15T21:18:27Z","updated_at":"2018-11-24T22:04:12Z","closed_at":null,"author_association":"NONE","body":"Hello\r\nI've gotten to the neural network part of supervised machine learning, and there is a slight problem with the classification, using MLPClassifier and mglearn.plots.plot_2d_seperator. On page 110, it says\r\n```\r\nX, y = make_moons(n_samples=100, noise=.25, random_state=3)\r\nX_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)\r\n\r\nmlp = MLPClassifier(solver='lbfgs', random_state=0).fit(X_train, y_train)\r\nmglearn.plots.plot_2d_separator(mlp, X_train, fill=True, alpha=.3)\r\nmglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train)\r\n```\r\nand using the plot_2d_seperator, it gives me an error:\r\n```\r\nTraceback (most recent call last):\r\n  File \"D:\\Program Files\\...\\mglearn\\plot_2d_separator.py\", line 86, in plot_2d_separator\r\n    decision_values = classifier.decision_function(X_grid)\r\nAttributeError: 'MLPClassifier' object has no attribute 'decision_function'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"D:/Program Files/.../chap2_16.py\", line 22, in <module>\r\n    mglearn.plots.plot_2d_separator(mlp, X_train, fill=True, alpha=.3)\r\n  File \"D:\\Program Files\\...\\mglearn\\plot_2d_separator.py\", line 92, in plot_2d_separator\r\n    decision_values = classifier.predict_proba(X_grid)[:, 1]\r\n  File \"C:\\Users\\...\\sklearn\\neural_network\\multilayer_perceptron.py\", line 1050, in predict_proba\r\n    y_pred = self._predict(X)\r\n  File \"C:\\Users\\...\\sklearn\\neural_network\\multilayer_perceptron.py\", line 678, in _predict\r\n    self._forward_pass(activations)\r\n  File \"C:\\Users\\...\\sklearn\\neural_network\\multilayer_perceptron.py\", line 105, in _forward_pass\r\n    self.coefs_[i])\r\n  File \"C:\\Users\\...\\sklearn\\utils\\extmath.py\", line 140, in safe_sparse_dot\r\n    return np.dot(a, b)\r\nMemoryError\r\n```\r\n\r\nThis can be fixed by setting hidden_layer_sizes=53 in MLPClassifier. Using more hidden layers, the error shows again."},"comment":{"url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/comments/441398663","html_url":"https://github.com/amueller/introduction_to_ml_with_python/issues/67#issuecomment-441398663","issue_url":"https://api.github.com/repos/amueller/introduction_to_ml_with_python/issues/67","id":441398663,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MTM5ODY2Mw==","user":{"login":"behreth","id":43671386,"node_id":"MDQ6VXNlcjQzNjcxMzg2","avatar_url":"https://avatars2.githubusercontent.com/u/43671386?v=4","gravatar_id":"","url":"https://api.github.com/users/behreth","html_url":"https://github.com/behreth","followers_url":"https://api.github.com/users/behreth/followers","following_url":"https://api.github.com/users/behreth/following{/other_user}","gists_url":"https://api.github.com/users/behreth/gists{/gist_id}","starred_url":"https://api.github.com/users/behreth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/behreth/subscriptions","organizations_url":"https://api.github.com/users/behreth/orgs","repos_url":"https://api.github.com/users/behreth/repos","events_url":"https://api.github.com/users/behreth/events{/privacy}","received_events_url":"https://api.github.com/users/behreth/received_events","type":"User","site_admin":false},"created_at":"2018-11-24T22:04:12Z","updated_at":"2018-11-24T22:04:12Z","author_association":"NONE","body":"I stumbled over the same problem looking at the sklearn.neural_network.MLPClassifier there is no decision_function() - only a predict_proba() function.\r\nIn many code snippets (even in your own @amueller I find the following code:\r\n\r\n    if hasattr(clf, \"decision_function\"):\r\n            Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])\r\n        else:\r\n            Z = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]\r\n\r\n... ie depending on the classifier .... so should that distinction be in the mglearn package.\r\n"}}
{"actor":{"display_login":"behreth"}}