Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc resample bench #24

Merged
merged 23 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated docs and soup bagging
  • Loading branch information
plutasnyy committed Nov 26, 2019
commit c95c5b0e66efc34227ca07b5e6863bf0457f46a6
101 changes: 101 additions & 0 deletions benchmarks/resample/SOUPBagging.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"collapsed": true,
"pycharm": {
"is_executing": false
}
},
"outputs": [
{
"data": {
"text/plain": "array([[1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [0., 0., 0., 1., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [0., 0., 0., 1., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [0., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [0., 0., 0., 0., 1.],\n [0., 1., 0., 0., 0.],\n [0., 0., 0., 1., 0.],\n [1., 0., 0., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 0., 0., 1.],\n [1., 0., 0., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 0., 1., 0., 0.],\n [0., 1., 0., 0., 0.],\n [1., 0., 0., 0., 0.],\n [1., 0., 0., 0., 0.]])"
},
"metadata": {},
"output_type": "execute_result",
"execution_count": 71
}
],
"source": [
"import numpy as np\n",
"from sklearn.ensemble import BaggingClassifier\n",
"from sklearn.model_selection import train_test_split, ParameterGrid\n",
"from sklearn.neighbors import KNeighborsClassifier\n",
"from sklearn.utils import resample\n",
"from multi_imbalance.datasets import load_datasets\n",
"from multi_imbalance.resampling.SOUP import SOUP\n",
"\n",
"\n",
"datasets = load_datasets()['new_ecoli']\n",
"X, y = datasets.data, datasets.target \n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)\n",
"\n",
"n_classifiers = 30\n",
"n_samples = X_test.shape[0]\n",
"n_classes = np.unique(np.concatenate((y_train, y_test))).shape[0]\n",
"\n",
"results = np.zeros(shape=(n_classifiers, n_samples, n_classes))\n",
"decision_matrix = np.zeros(shape=(n_samples, n_classes))\n",
"\n",
"for i in range(n_classifiers):\n",
" x_sampled, y_sampled = resample(X_train, y_train, stratify=y_train)\n",
" x_resampled, y_resampled = SOUP().fit_transform(x_sampled, y_sampled)\n",
" clf = KNeighborsClassifier().fit(x_resampled, y_resampled)\n",
" results[i] = clf.predict_proba(X_test)\n",
"\n",
"weights_sum = np.sum(results, axis=0)\n",
"decisions_indices = np.argmax(weights_sum,axis=1)\n",
"decision_matrix[np.arange(n_samples),decisions_indices] = 1\n",
"\n",
"decision_matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
6 changes: 3 additions & 3 deletions benchmarks/spider/spider.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
},
"source": []
}
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
}
116 changes: 59 additions & 57 deletions examples/resampling/MDO.ipynb

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions examples/resampling/SOUP.ipynb

Large diffs are not rendered by default.