Skip to content
Snippets Groups Projects
Commit d2e352c6 authored by Dominique Benielli's avatar Dominique Benielli
Browse files

add usecase examples

parent c80f65e8
Branches
Tags
No related merge requests found
Pipeline #4160 failed
Showing
with 427 additions and 0 deletions
:orphan:
.. _sphx_glr_tutorial_auto_examples_usecase_sg_execution_times:
Computation times
=================
**01:09.574** total execution time for **tutorial_auto_examples_usecase** files:
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorial_auto_examples_usecase_plot_usecase_exampleMVML.py` (``plot_usecase_exampleMVML.py``) | 00:39.921 | 0.0 MB |
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorial_auto_examples_usecase_plot_usecase_exampleMKL.py` (``plot_usecase_exampleMKL.py``) | 00:12.697 | 0.0 MB |
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorial_auto_examples_usecase_plot_usecase_exampleMuCuBo.py` (``plot_usecase_exampleMuCuBo.py``) | 00:11.436 | 0.0 MB |
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorial_auto_examples_usecase_plot_usecase_exampleMumBo.py` (``plot_usecase_exampleMumBo.py``) | 00:05.520 | 0.0 MB |
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_tutorial_auto_examples_usecase_usecase_function.py` (``usecase_function.py``) | 00:00.000 | 0.0 MB |
+------------------------------------------------------------------------------------------------------------------+-----------+--------+
%% Cell type:code id: tags:
``` python
%matplotlib inline
```
%% Cell type:markdown id: tags:
\n# Use Case Function module\n\n\nFunction plot_subplot
%% Cell type:code id: tags:
``` python
import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib._color_data as mcd\n\n\ndef plot_subplot(X, Y, Y_pred, vue, subplot, title):\n cn = mcd.CSS4_COLORS\n classes = np.unique(Y)\n n_classes = len(np.unique(Y))\n axs = plt.subplot(subplot[0],subplot[1],subplot[2])\n axs.set_title(title)\n #plt.scatter(X._extract_view(vue), X._extract_view(vue), s=40, c='gray',\n # edgecolors=(0, 0, 0))\n for index, k in zip(range(n_classes), cn.keys()):\n Y_class, = np.where(Y==classes[index])\n Y_class_pred = np.intersect1d(np.where(Y_pred==classes[index])[0], np.where(Y_pred==Y)[0])\n plt.scatter(X._extract_view(vue)[Y_class],\n X._extract_view(vue)[Y_class],\n s=40, c=cn[k], edgecolors='blue', linewidths=2, label="class real class: "+str(index)) #\n plt.scatter(X._extract_view(vue)[Y_class_pred],\n X._extract_view(vue)[Y_class_pred],\n s=160, edgecolors='orange', linewidths=2, label="class prediction: "+str(index))\n\n\nif __name__ == '__main__':\n pass
```
# -*- coding: utf-8 -*-
"""
========================
Use Case Function module
========================
Function plot_subplot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib._color_data as mcd
def plot_subplot(X, Y, Y_pred, vue, subplot, title):
cn = mcd.CSS4_COLORS
classes = np.unique(Y)
n_classes = len(np.unique(Y))
axs = plt.subplot(subplot[0],subplot[1],subplot[2])
axs.set_title(title)
#plt.scatter(X._extract_view(vue), X._extract_view(vue), s=40, c='gray',
# edgecolors=(0, 0, 0))
for index, k in zip(range(n_classes), cn.keys()):
Y_class, = np.where(Y==classes[index])
Y_class_pred = np.intersect1d(np.where(Y_pred==classes[index])[0], np.where(Y_pred==Y)[0])
plt.scatter(X._extract_view(vue)[Y_class],
X._extract_view(vue)[Y_class],
s=40, c=cn[k], edgecolors='blue', linewidths=2, label="class real class: "+str(index)) #
plt.scatter(X._extract_view(vue)[Y_class_pred],
X._extract_view(vue)[Y_class_pred],
s=160, edgecolors='orange', linewidths=2, label="class prediction: "+str(index))
if __name__ == '__main__':
pass
\ No newline at end of file
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here <sphx_glr_download_tutorial_auto_examples_usecase_usecase_function.py>` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_tutorial_auto_examples_usecase_usecase_function.py:
========================
Use Case Function module
========================
Function plot_subplot
.. code-block:: default
import numpy as np
import matplotlib.pyplot as plt
import matplotlib._color_data as mcd
def plot_subplot(X, Y, Y_pred, vue, subplot, title):
cn = mcd.CSS4_COLORS
classes = np.unique(Y)
n_classes = len(np.unique(Y))
axs = plt.subplot(subplot[0],subplot[1],subplot[2])
axs.set_title(title)
#plt.scatter(X._extract_view(vue), X._extract_view(vue), s=40, c='gray',
# edgecolors=(0, 0, 0))
for index, k in zip(range(n_classes), cn.keys()):
Y_class, = np.where(Y==classes[index])
Y_class_pred = np.intersect1d(np.where(Y_pred==classes[index])[0], np.where(Y_pred==Y)[0])
plt.scatter(X._extract_view(vue)[Y_class],
X._extract_view(vue)[Y_class],
s=40, c=cn[k], edgecolors='blue', linewidths=2, label="class real class: "+str(index)) #
plt.scatter(X._extract_view(vue)[Y_class_pred],
X._extract_view(vue)[Y_class_pred],
s=160, edgecolors='orange', linewidths=2, label="class prediction: "+str(index))
if __name__ == '__main__':
pass
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.000 seconds)
.. _sphx_glr_download_tutorial_auto_examples_usecase_usecase_function.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download
:download:`Download Python source code: usecase_function.py <usecase_function.py>`
.. container:: sphx-glr-download
:download:`Download Jupyter notebook: usecase_function.ipynb <usecase_function.ipynb>`
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
File added
...@@ -14,3 +14,4 @@ total execution time for **tutorial_auto_examples** files: ...@@ -14,3 +14,4 @@ total execution time for **tutorial_auto_examples** files:
auto_examples/mumbo/sg_execution_times auto_examples/mumbo/sg_execution_times
auto_examples/cumbo/sg_execution_times auto_examples/cumbo/sg_execution_times
auto_examples/mvml/sg_execution_times auto_examples/mvml/sg_execution_times
auto_examples/usecase/sg_execution_times
# -*- coding: utf-8 -*-
"""
============
Use Case MKL
============
Use case for all classifier of multimodallearn MKL
multi class digit from sklearn, multivue
- vue 0 digit data (color of sklearn)
- vue 1 gradiant of image in first direction
- vue 2 gradiant of image in second direction
"""
from __future__ import absolute_import
import numpy as np
import matplotlib.pyplot as plt
from sklearn.multiclass import OneVsOneClassifier
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from multimodal.datasets.base import load_dict, save_dict
from multimodal.tests.data.get_dataset_path import get_dataset_path
from multimodal.datasets.data_sample import MultiModalArray
from multimodal.kernels.mvml import MVML
from multimodal.kernels.lpMKL import MKL
from usecase_function import plot_subplot
if __name__ == '__main__':
# file = get_dataset_path("digit_histogram.npy")
file = get_dataset_path("digit_col_grad.npy")
y = np.load(get_dataset_path("digit_y.npy"))
base_estimator = DecisionTreeClassifier(max_depth=4)
dic_digit = load_dict(file)
XX =MultiModalArray(dic_digit)
X_train, X_test, y_train, y_test = train_test_split(XX, y)
est4 = OneVsOneClassifier(MKL(lmbda=0.1, nystrom_param=0.2)).fit(X_train, y_train)
y_pred4 = est4.predict(X_test)
y_pred44 = est4.predict(X_train)
print("result of MKL on digit with oneversone")
result4 = np.mean(y_pred4.ravel() == y_test.ravel()) * 100
print(result4)
fig = plt.figure(figsize=(12., 11.))
fig.suptitle("MKL : result" + str(result4), fontsize=16)
plot_subplot(X_train, y_train, y_pred44 ,0, (4, 1, 1), "train vue 0" )
plot_subplot(X_test, y_test,y_pred4 , 0, (4, 1, 2), "test vue 0" )
plot_subplot(X_test, y_test, y_pred4,1, (4, 1, 3), "test vue 1" )
plot_subplot(X_test, y_test,y_pred4, 2, (4, 1, 4), "test vue 2" )
# plt.legend()
plt.show()
# -*- coding: utf-8 -*-
"""
================
Use Case of MVML
================
Use case for all classifier of multimodallearn MVML
multi class digit from sklearn, multivue
- vue 0 digit data (color of sklearn)
- vue 1 gradiant of image in first direction
- vue 2 gradiant of image in second direction
"""
from __future__ import absolute_import
import numpy as np
import matplotlib.pyplot as plt
from sklearn.multiclass import OneVsOneClassifier
from sklearn.model_selection import train_test_split
from multimodal.datasets.base import load_dict, save_dict
from multimodal.tests.data.get_dataset_path import get_dataset_path
from multimodal.datasets.data_sample import MultiModalArray
from multimodal.kernels.mvml import MVML
from usecase_function import plot_subplot
if __name__ == '__main__':
# file = get_dataset_path("digit_histogram.npy")
file = get_dataset_path("digit_col_grad.npy")
y = np.load(get_dataset_path("digit_y.npy"))
dic_digit = load_dict(file)
XX =MultiModalArray(dic_digit)
X_train, X_test, y_train, y_test = train_test_split(XX, y)
est1 = OneVsOneClassifier(MVML(lmbda=0.1, eta=1, nystrom_param=0.2)).fit(X_train, y_train)
y_pred1 = est1.predict(X_test)
y_pred11 = est1.predict(X_train)
print("result of MVML on digit with oneversone")
result1 = np.mean(y_pred1.ravel() == y_test.ravel()) * 100
print(result1)
fig = plt.figure(figsize=(12., 11.))
fig.suptitle("MVML: result" + str(result1), fontsize=16)
plot_subplot(X_train, y_train, y_pred11
, 0, (4, 1, 1), "train vue 0" )
plot_subplot(X_test, y_test,y_pred1, 0, (4, 1, 2), "test vue 0" )
plot_subplot(X_test, y_test, y_pred1, 1, (4, 1, 3), "test vue 1" )
plot_subplot(X_test, y_test,y_pred1, 2, (4, 1, 4), "test vue 2" )
#plt.legend()
plt.show()
# -*- coding: utf-8 -*-
"""
================
Use Case MuCumBo
================
Use case for all classifier of multimodallearn MuCumBo
multi class digit from sklearn, multivue
- vue 0 digit data (color of sklearn)
- vue 1 gradiant of image in first direction
- vue 2 gradiant of image in second direction
"""
from __future__ import absolute_import
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from multimodal.datasets.base import load_dict, save_dict
from multimodal.tests.data.get_dataset_path import get_dataset_path
from multimodal.datasets.data_sample import MultiModalArray
from multimodal.boosting.cumbo import MuCumboClassifier
from usecase_function import plot_subplot
if __name__ == '__main__':
# file = get_dataset_path("digit_histogram.npy")
file = get_dataset_path("digit_col_grad.npy")
y = np.load(get_dataset_path("digit_y.npy"))
base_estimator = DecisionTreeClassifier(max_depth=4)
dic_digit = load_dict(file)
XX =MultiModalArray(dic_digit)
X_train, X_test, y_train, y_test = train_test_split(XX, y)
est3 = MuCumboClassifier(base_estimator=base_estimator).fit(X_train, y_train)
y_pred3 = est3.predict(X_test)
y_pred33 = est3.predict(X_train)
print("result of MuCumboClassifier on digit ")
result3 = np.mean(y_pred3.ravel() == y_test.ravel()) * 100
print(result3)
fig = plt.figure(figsize=(12., 11.))
fig.suptitle("MuCumbo: result" + str(result3), fontsize=16)
plot_subplot(X_train, y_train, y_pred33 ,0, (4, 1, 1), "train vue 0" )
plot_subplot(X_test, y_test,y_pred3 , 0, (4, 1, 2), "test vue 0" )
plot_subplot(X_test, y_test, y_pred3,1, (4, 1, 3), "test vue 1" )
plot_subplot(X_test, y_test,y_pred3, 2, (4, 1, 4), "test vue 2" )
# plt.legend()
plt.show()
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
==============
Use Case MumBo
==============
Use case for all classifier of multimodallearn MumBo
multi class digit from sklearn, multivue
- vue 0 digit data (color of sklearn)
- vue 1 gradiant of image in first direction
- vue 2 gradiant of image in second direction
"""
from __future__ import absolute_import
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from multimodal.datasets.base import load_dict, save_dict
from multimodal.tests.data.get_dataset_path import get_dataset_path
from multimodal.datasets.data_sample import MultiModalArray
from multimodal.boosting.mumbo import MumboClassifier
from usecase_function import plot_subplot
if __name__ == '__main__':
# file = get_dataset_path("digit_histogram.npy")
file = get_dataset_path("digit_col_grad.npy")
y = np.load(get_dataset_path("digit_y.npy"))
base_estimator = DecisionTreeClassifier(max_depth=4)
dic_digit = load_dict(file)
XX =MultiModalArray(dic_digit)
X_train, X_test, y_train, y_test = train_test_split(XX, y)
est2 = MumboClassifier(base_estimator=base_estimator).fit(X_train, y_train)
y_pred2 = est2.predict(X_test)
y_pred22 = est2.predict(X_train)
print("result of MumboClassifier on digit ")
result2 = np.mean(y_pred2.ravel() == y_test.ravel()) * 100
print(result2)
fig = plt.figure(figsize=(12., 11.))
fig.suptitle("Mumbo: result" + str(result2), fontsize=16)
plot_subplot(X_train, y_train, y_pred22 , 0, (4, 1, 1), "train vue 0" )
plot_subplot(X_test, y_test,y_pred2, 0, (4, 1, 2), "test vue 0" )
plot_subplot(X_test, y_test, y_pred2, 1, (4, 1, 3), "test vue 1" )
plot_subplot(X_test, y_test,y_pred2, 2, (4, 1, 4), "test vue 2" )
# plt.legend()
plt.show()
# -*- coding: utf-8 -*-
"""
========================
Use Case Function module
========================
Function plot_subplot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib._color_data as mcd
def plot_subplot(X, Y, Y_pred, vue, subplot, title):
cn = mcd.CSS4_COLORS
classes = np.unique(Y)
n_classes = len(np.unique(Y))
axs = plt.subplot(subplot[0],subplot[1],subplot[2])
axs.set_title(title)
#plt.scatter(X._extract_view(vue), X._extract_view(vue), s=40, c='gray',
# edgecolors=(0, 0, 0))
for index, k in zip(range(n_classes), cn.keys()):
Y_class, = np.where(Y==classes[index])
Y_class_pred = np.intersect1d(np.where(Y_pred==classes[index])[0], np.where(Y_pred==Y)[0])
plt.scatter(X._extract_view(vue)[Y_class],
X._extract_view(vue)[Y_class],
s=40, c=cn[k], edgecolors='blue', linewidths=2, label="class real class: "+str(index)) #
plt.scatter(X._extract_view(vue)[Y_class_pred],
X._extract_view(vue)[Y_class_pred],
s=160, edgecolors='orange', linewidths=2, label="class prediction: "+str(index))
if __name__ == '__main__':
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment