{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Modality Model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data Example" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
data_image_1agegendersubset
0[45.44638769171786, 4.135743395582088, 65.4992...66FTRAIN_VALIDATE
1[31.103975653537624, 22.742018582560704, 55.72...68FTRAIN_VALIDATE
2[13.763440850143434, 27.696897834132383, 9.673...30MTRAIN_VALIDATE
3[15.53920410329618, 15.91871234560287, 6.62250...22FTRAIN_VALIDATE
4[2.9411769417824285, 3.895413833469064, 14.256...18FTRAIN_VALIDATE
...............
495[31.417769500497954, 18.995660592781746, 22.10...64MTEST
496[43.17352410484374, 1.0359054168446515, 58.802...59FTEST
497[34.34416026557086, 5.521968600916665, 8.75701...66FTEST
498[13.252041660768269, 30.217646004227426, 10.73...66FTEST
499[42.12969225518131, 40.620030729772424, 25.058...53FTEST
\n", "

500 rows × 4 columns

\n", "
" ], "text/plain": [ " data_image_1 age gender \\\n", "0 [45.44638769171786, 4.135743395582088, 65.4992... 66 F \n", "1 [31.103975653537624, 22.742018582560704, 55.72... 68 F \n", "2 [13.763440850143434, 27.696897834132383, 9.673... 30 M \n", "3 [15.53920410329618, 15.91871234560287, 6.62250... 22 F \n", "4 [2.9411769417824285, 3.895413833469064, 14.256... 18 F \n", ".. ... ... ... \n", "495 [31.417769500497954, 18.995660592781746, 22.10... 64 M \n", "496 [43.17352410484374, 1.0359054168446515, 58.802... 59 F \n", "497 [34.34416026557086, 5.521968600916665, 8.75701... 66 F \n", "498 [13.252041660768269, 30.217646004227426, 10.73... 66 F \n", "499 [42.12969225518131, 40.620030729772424, 25.058... 53 F \n", "\n", " subset \n", "0 TRAIN_VALIDATE \n", "1 TRAIN_VALIDATE \n", "2 TRAIN_VALIDATE \n", "3 TRAIN_VALIDATE \n", "4 TRAIN_VALIDATE \n", ".. ... \n", "495 TEST \n", "496 TEST \n", "497 TEST \n", "498 TEST \n", "499 TEST \n", "\n", "[500 rows x 4 columns]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from models import ModalityPredictorPCA, MODELTYPE\n", "from generate_random_input import generate_single_image_input\n", "\n", "\n", "df = generate_single_image_input()\n", "df[\"subset\"] = [\"TRAIN_VALIDATE\"]*int(df.shape[0]/2) + [\"TEST\"]*int(df.shape[0]/2)\n", "\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Model" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/html": [ "
Pipeline(steps=[('preprocessor',\n",
       "                 ColumnTransformer(transformers=[('dimensionality_reduction',\n",
       "                                                  Pipeline(steps=[('flatten',\n",
       "                                                                   FlattenNestedArray()),\n",
       "                                                                  ('dimensionality_reduction',\n",
       "                                                                   PCA(n_components=2,\n",
       "                                                                       svd_solver='full')),\n",
       "                                                                  ('scaler_pre',\n",
       "                                                                   StandardScaler())]),\n",
       "                                                  'data_image_1'),\n",
       "                                                 ('gender_and_site_encoded',\n",
       "                                                  OneHotEncoder(handle_unknown='ignore'),\n",
       "                                                  ['gender'])])),\n",
       "                ('regressor', EMRVR())])
Please rerun this cell to show the HTML repr or trust the notebook.
" ], "text/plain": [ "Pipeline(steps=[('preprocessor',\n", " ColumnTransformer(transformers=[('dimensionality_reduction',\n", " Pipeline(steps=[('flatten',\n", " FlattenNestedArray()),\n", " ('dimensionality_reduction',\n", " PCA(n_components=2,\n", " svd_solver='full')),\n", " ('scaler_pre',\n", " StandardScaler())]),\n", " 'data_image_1'),\n", " ('gender_and_site_encoded',\n", " OneHotEncoder(handle_unknown='ignore'),\n", " ['gender'])])),\n", " ('regressor', EMRVR())])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn import set_config\n", "set_config(display=\"diagram\")\n", "\n", "number_components = 2\n", "predictor = ModalityPredictorPCA(df, \"data_image_1\", MODELTYPE.SINGLE_IMAGE, 5)\n", "\n", "model = predictor.get_single_modality_model(number_components, \"data_image_1\")\n", "model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }