<jupyter_start><jupyter_text>Generating materials descriptors – ExercisesIn these exercises, we'll load a cleaned dataframe, decorate it with multiple descriptors, and prepare it to be used for machine learning.Before starting, we need to use matminer's `load_dataframe_from_json()` function to load a cleaned version of the `elastic_tensor_2015` dataset. We will use this dataset for all the exercises.<jupyter_code>import os
from matminer.utils.io import load_dataframe_from_json

df = load_dataframe_from_json(os.path.join("resources", "elastic_tensor_2015_cleaned.json"))
df.head()<jupyter_output><empty_output><jupyter_text>Exercise 1: Convert formulas to pymatgen CompositionsUse matminer's `StrToComposition` conversion featurizer to first convert the `formula` column of the dataframe to pymatgen `Composition`s. This is necessary because matminer's Composition featurizers need pymatgen compositions as input.<jupyter_code>from matminer.featurizers.conversions import StrToComposition

stc = StrToComposition()

# Complete exercise below

df = stc.featurize_dataframe(df, "formula")
df.head()<jupyter_output><empty_output><jupyter_text>Exercise 2: Add composition featuresNow add `ElementFraction` features by featurizing the `composition` column.<jupyter_code>from matminer.featurizers.composition.element import ElementFraction

ep = ElementFraction()

# Complete exercise below

df = ep.featurize_dataframe(df, "composition")
df.head()<jupyter_output><empty_output><jupyter_text>Exercise 3: Add structure featuresFinally, structure features using the `DensityFeatures` featurizer on the `structure` column.<jupyter_code>from matminer.featurizers.structure.order import DensityFeatures

de = DensityFeatures()

# Complete exercise below

df = de.featurize_dataframe(df, "structure")
df.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07746863066012002, 'fraction_numerical': 0.006001091107474086, 'mean_word_length': 7.990196078431373, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '336421', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 571, 'n_tokens_neox': 543, 'n_words': 157, 'path': 'workshop/lessons/08_ml_matminer/unit-2-exercises-answers.ipynb', 'repo_name': 'arepstein/workshop', 'size': '1833'}