From ea292ef11306fdb59aa3109b54b1f434f6af8e3c Mon Sep 17 00:00:00 2001 From: Philip Loche Date: Thu, 26 Oct 2023 09:59:23 +0200 Subject: [PATCH] minor fixes and cleanups in lode examples --- examples/lode_linear/lode_tutorial.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/lode_linear/lode_tutorial.py b/examples/lode_linear/lode_tutorial.py index d01e0c3c..4fc99143 100644 --- a/examples/lode_linear/lode_tutorial.py +++ b/examples/lode_linear/lode_tutorial.py @@ -43,7 +43,7 @@ # %% # -# Convert target properties to equistore format +# Convert target properties to metatensor format # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # If we want to train models using the @@ -197,8 +197,8 @@ # # .. code:: python # -# descriptor_co = AtomicComposition(per_structure=True).compute(**compute_args) co = -# descriptor_co.keys_to_properties(["species_center"]) +# descriptor_co = AtomicComposition(per_structure=True).compute(**compute_args) +# co = descriptor_co.keys_to_properties(["species_center"]) # # Stack all the features together for linear model # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -267,24 +267,26 @@ # %% # -# For doing the split we define two ``Labels`` instances +# For doing the split we define two ``Labels`` instances and combine them in a +# :py:class:`List`. samples_train = metatensor.Labels(["structure"], np.reshape(idx_train, (-1, 1))) samples_test = metatensor.Labels(["structure"], np.reshape(idx_test, (-1, 1))) +grouped_labels = [samples_train, samples_test] # %% # -# That we use as input to the :py:func:`equistore.slice()` function +# That we use as input to the :py:func:`metatensor.split()` function -X_sr_train = metatensor.slice(X_sr, axis="samples", labels=samples_train) -X_sr_test = metatensor.slice(X_sr, axis="samples", labels=samples_test) +X_sr_train, X_sr_test = metatensor.split( + X_sr, axis="samples", grouped_labels=grouped_labels) -X_lr_train = metatensor.slice(X_lr, axis="samples", labels=samples_train) -X_lr_test = metatensor.slice(X_lr, axis="samples", labels=samples_test) +X_lr_train, X_lr_test = metatensor.split( + X_lr, axis="samples", grouped_labels=grouped_labels) -y_train = metatensor.slice(y, axis="samples", labels=samples_train) -y_test = metatensor.slice(y, axis="samples", labels=samples_test) +y_train, grouped_labels = metatensor.split( + y, axis="samples", grouped_labels=grouped_labels) # %%