.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/training_and_testing/plot_using_external_data.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_training_and_testing_plot_using_external_data.py: Using External Test Data ======================================================================== Let's learn how to use external test data with Fusilli! Some guidance can also be found in the :ref:`Data Loading ` section of the documentation. The extra step that we need to take is to provide the paths to the test data files to the functions that create evaluation figures: :class:`~.fusilli.eval.RealsVsPreds.from_new_data`, :class:`~.fusilli.eval.ConfusionMatrix.from_new_data`, :class:`~.fusilli.eval.ModelComparison.from_new_data`. .. note:: It is not possible to use external test data with graph-based fusion models. We'll rush through the first few steps of the training and testing process, as they are covered in more detail in the other example notebooks. .. GENERATED FROM PYTHON SOURCE LINES 18-94 .. code-block:: Python import matplotlib.pyplot as plt from tqdm.auto import tqdm import os from fusilli.data import prepare_fusion_data from fusilli.eval import RealsVsPreds from fusilli.train import train_and_save_models from fusilli.utils.model_chooser import import_chosen_fusion_models # sphinx_gallery_thumbnail_number = -1 model_conditions = { "class_name": ["ConcatTabularFeatureMaps"], } fusion_models = import_chosen_fusion_models(model_conditions) # Regression task prediction_task = "regression" # Set the batch size batch_size = 48 # Setting output directories output_paths = { "losses": "loss_logs/external_data", "checkpoints": "checkpoints/external_data", "figures": "figures/external_data", } for dir in output_paths.values(): os.makedirs(dir, exist_ok=True) # Clearing the loss logs directory (only for the example notebooks) for dir in os.listdir(output_paths["losses"]): # remove files for file in os.listdir(os.path.join(output_paths["losses"], dir)): os.remove(os.path.join(output_paths["losses"], dir, file)) # remove dir os.rmdir(os.path.join(output_paths["losses"], dir)) data_paths = { "tabular1": "../../_static/mnist_data/mnist1_regression.csv", "tabular2": "../../_static/mnist_data/mnist2_regression.csv", "image": "", } external_data_paths = { "tabular1": "../../_static/mnist_data/mnist1_regression_test.csv", "tabular2": "../../_static/mnist_data/mnist2_regression_test.csv", "image": "", } fusion_model = fusion_models[0] print("Method name:", fusion_model.method_name) print("Modality type:", fusion_model.modality_type) print("Fusion type:", fusion_model.fusion_type) # Create the data module dm = prepare_fusion_data(prediction_task=prediction_task, fusion_model=fusion_model, data_paths=data_paths, output_paths=output_paths, batch_size=batch_size, ) # train and test trained_model = train_and_save_models( data_module=dm, fusion_model=fusion_model, enable_checkpointing=True, show_loss_plot=True, ) .. image-sg:: /auto_examples/training_and_testing/images/sphx_glr_plot_using_external_data_001.png :alt: Loss Curves for ConcatTabularFeatureMaps :srcset: /auto_examples/training_and_testing/images/sphx_glr_plot_using_external_data_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Imported methods: ['Concatenating tabular feature maps'] Method name: Concatenating tabular feature maps Modality type: tabular_tabular Fusion type: operation Training: | | 0/? [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_using_external_data.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_using_external_data.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_