{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/416","repository_url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn","labels_url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/416/labels{/name}","comments_url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/416/comments","events_url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/416/events","html_url":"https://github.com/scikit-learn-contrib/imbalanced-learn/pull/416","id":309128749,"number":416,"title":"Added class-senstive-scaling","user":{"login":"BernhardSchlegel","id":5735721,"avatar_url":"https://avatars0.githubusercontent.com/u/5735721?v=4","gravatar_id":"","url":"https://api.github.com/users/BernhardSchlegel","html_url":"https://github.com/BernhardSchlegel","followers_url":"https://api.github.com/users/BernhardSchlegel/followers","following_url":"https://api.github.com/users/BernhardSchlegel/following{/other_user}","gists_url":"https://api.github.com/users/BernhardSchlegel/gists{/gist_id}","starred_url":"https://api.github.com/users/BernhardSchlegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BernhardSchlegel/subscriptions","organizations_url":"https://api.github.com/users/BernhardSchlegel/orgs","repos_url":"https://api.github.com/users/BernhardSchlegel/repos","events_url":"https://api.github.com/users/BernhardSchlegel/events{/privacy}","received_events_url":"https://api.github.com/users/BernhardSchlegel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-27T20:50:27Z","updated_at":"2018-03-28T07:13:49Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/pulls/416","html_url":"https://github.com/scikit-learn-contrib/imbalanced-learn/pull/416","diff_url":"https://github.com/scikit-learn-contrib/imbalanced-learn/pull/416.diff","patch_url":"https://github.com/scikit-learn-contrib/imbalanced-learn/pull/416.patch"},"body":"<!--\r\nThanks for contributing a pull request! Please ensure you have taken a look at\r\nthe contribution guidelines: https://github.com/scikit-learn-contrib/imbalanced-learn/blob/master/CONTRIBUTING.md#contributing-pull-requests\r\n-->\r\n#### What does this implement/fix? Explain your changes.\r\nThis implements a new technique called \"class senstive scaling\" that removes borderline noise by scaling samples to their corresponding class center. This computes insanely fast and eases the identification of a decision boundary and is a alternative to Tomek Link based concepts like CNN or OSS that supposedly reveal the decision boundary by removing noisy borderline samples. For details please refer:\r\n\r\nB. Schlegel, and B. Sick. \"Dealing with class imbalance the scalable way: Evaluation of various techniques based on classification grade and computational complexity.\" 2017 IEEE International Conference on Data Mining Workshops, 2017.\r\n\r\n#### Any other comments?\r\nThis is my first pull request! \r\n\r\nIf you want to have a simple visualization you can use the following snippet\r\n\r\n```\r\nimport numpy as np\r\nfrom sklearn.utils import shuffle\r\nfrom sklearn.model_selection import train_test_split\r\n\r\n# create sample dataset\r\nrng = np.random.RandomState(42)\r\nn_samples_1 = 50\r\nn_samples_2 = 5\r\nX_syn = np.r_[1.5 * rng.randn(n_samples_1, 2),\r\n              0.5 * rng.randn(n_samples_2, 2) + [2, 2]]\r\ny_syn = np.array([0] * (n_samples_1) + [1] * (n_samples_2))\r\nX_syn, y_syn = shuffle(X_syn, y_syn)\r\nX_syn_train, X_syn_test, y_syn_train, y_syn_test = train_test_split(X_syn, y_syn)\r\nidx_class_0_orig = y_syn == 0\r\n\r\n# apply CSS\r\nfrom imblearn.scaling import CSS\r\ncss = CSS(mode=\"linear\", target=\"both\", c=0.1, shuffle=True)\r\nX_train_res, y_train_res = css.fit_sample(X_syn, y_syn)\r\n\r\n# plot original dataset\r\nimport matplotlib.pyplot as plt\r\nfig = plt.figure(figsize=(14, 6))\r\nax = fig.add_subplot(1, 2, 1)\r\nimport matplotlib.pyplot as plt\r\nplt.scatter(X_syn[idx_class_0_orig, 0], X_syn[idx_class_0_orig, 1],\r\n            alpha=.8, label='Class #0')\r\nplt.scatter(X_syn[~idx_class_0_orig, 0], X_syn[~idx_class_0_orig, 1],\r\n            alpha=.8, label='Class #1')\r\nax.set_xlim([-5, 5])\r\nax.set_ylim([-5, 5])\r\nplt.yticks(range(-5, 6))\r\nplt.xticks(range(-5, 6))\r\n\r\nplt.title('Original dataset')\r\nplt.legend()\r\n\r\n# plot CSS dataset\r\nidx_class_0 = y_train_res == 0\r\nax = fig.add_subplot(1, 2, 2)\r\nplt.scatter(X_train_res[idx_class_0, 0], X_train_res[idx_class_0, 1],\r\n            alpha=.8, label='Class #0')\r\nplt.scatter(X_train_res[~idx_class_0, 0], X_train_res[~idx_class_0, 1],\r\n            alpha=.8, label='Class #1')\r\nax.set_xlim([-5, 5])\r\nax.set_ylim([-5, 5])\r\nplt.yticks(range(-5, 6))\r\nplt.xticks(range(-5, 6))\r\nplt.title('Scaling using CSS')\r\nplt.legend()\r\nplt.show()\r\n```\r\n\r\nThanks for the great library by the way !\r\n\r\n<!--\r\nPlease be aware that we are a loose team of volunteers so patience is\r\nnecessary; assistance handling other issues is very welcome. We value\r\nall user contributions, no matter how minor they are. If we are slow to\r\nreview, either the pull request needs some benchmarking, tinkering,\r\nconvincing, etc. or more likely the reviewers are simply busy. In either\r\ncase, we ask for your understanding during the review process.\r\n\r\nThanks for contributing!\r\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/comments/376785626","html_url":"https://github.com/scikit-learn-contrib/imbalanced-learn/pull/416#issuecomment-376785626","issue_url":"https://api.github.com/repos/scikit-learn-contrib/imbalanced-learn/issues/416","id":376785626,"user":{"login":"BernhardSchlegel","id":5735721,"avatar_url":"https://avatars0.githubusercontent.com/u/5735721?v=4","gravatar_id":"","url":"https://api.github.com/users/BernhardSchlegel","html_url":"https://github.com/BernhardSchlegel","followers_url":"https://api.github.com/users/BernhardSchlegel/followers","following_url":"https://api.github.com/users/BernhardSchlegel/following{/other_user}","gists_url":"https://api.github.com/users/BernhardSchlegel/gists{/gist_id}","starred_url":"https://api.github.com/users/BernhardSchlegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BernhardSchlegel/subscriptions","organizations_url":"https://api.github.com/users/BernhardSchlegel/orgs","repos_url":"https://api.github.com/users/BernhardSchlegel/repos","events_url":"https://api.github.com/users/BernhardSchlegel/events{/privacy}","received_events_url":"https://api.github.com/users/BernhardSchlegel/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T07:13:49Z","updated_at":"2018-03-28T07:13:49Z","author_association":"NONE","body":"Hey, thanks for the lightning fast response\r\n\r\nregarding [travis](https://travis-ci.org/scikit-learn-contrib/imbalanced-learn/jobs/359087209):\r\n\r\n1. I had a \", newline\" in my code-example, which is not allowed. Fixed that.\r\n1. Then there is a `TypeError: mean() got an unexpected keyword argument 'dtype'` error, but I don't call `mean()` anywhere in my code with more than the array `a` and the `axis` set.\r\n1. `assert_allclose(X_res, X_res_ova)` from `check_samplers_multiclass_ova` fails. But I think this is by design, since CSS is supposed to scale (=move points to the corresponding class center). How do we proceed here? This error comes up twice\r\n\r\nregarding [AppVeyor](https://ci.appveyor.com/project/glemaitre/imbalanced-learn/build/1.0.973), in addition:\r\n\r\n4. `NotImplementedError: subtracting a nonzero scalar from a sparse matrix is not supported`: I'll look into that, solution is not straightforward. Ignoring sparce matrices with a warning (\"CSS only supports dense feature matrices\"), implementing some sort of imputation or solving it algorithmically to support sparse matrices are possible solutions.\r\n\r\n@glemaitre How do think to tackle 3. (error by design)?\r\n\r\nthank you so much for your efforts!"}}
{"actor":{"display_login":"BernhardSchlegel"}}