Machine Learning: Train a Neural Network for Regression¶
1. Acquire Training Data¶
The data we use in this tutorial is taken from a recent model 3 of small molecule adsorption to transition metal nanoparticles. Specifically, we use DFT-calculated values for the adsorption energy of ·CH3, CO, and ·OH radicals to Ag, Au, and Cu nanoparticles ranging in size from 55 to 172 atoms.
This File contains the data we will use in this tutorial. A sample of the first 5 lines in the file can be found below:
2. Upload the Training Data¶
Then, when the browser's upload window appears, we navigate to where we downloaded the file in section 1, and select it for upload. If the upload was successful, the file will then be visible in the dropbox.
3. Copy the "Python ML Train Regression" Workflow from the Workflow Bank¶
Next, we select the
Bank Worfklows button in the left sidebar, which brings us to
the Bank Workflows Page. We then search for the "Python ML Train Regression" workflow owned
by the "Curators" account, and copy it to our account.
A diagram and detailed description of this workflow can be found here.
4. Create the ML Job¶
First, we will give the job a friendly name, such as "Python ML Tutorial" (see below). Then, we will click the Actions Button (the three vertical dots in the upper-right of the job designer), and choose "Select Workflow."
This will bring up the Select Workflow dialogue. We then search for "Python ML Train Regression" and select it.
5. Select the Dataset¶
The job designer changes now that our ML Training workflow is selected. The "Materials" tab has now been replaced with a "Dataset" tab. Just as the "Materials" tab shows a preview of the materials the job will use, the "Dataset" tab shows a preview of the dataset once it is selected.
To select a dataset, click the Actions Button (the three vertical dots in the upper-right of the job designer) and choose "Select Dataset." This will bring up a files explorer containing all files presently on the dropbox. Choose the training set we uploaded earlier, "data_to_train_with.csv."
A preview of the data then appears on the dataset tab, indicating that the data has successfully been loaded.
6. Configure the Workflow¶
We have now chosen our ML workflow and training set. Select the Workflows Tab, and we can see our training workflow.
We can see two subworkflows available:
Set Up the Job
Set Up the Job subworkflow contains instructions to copy in the training data.
A Word of Caution
Set Up the Job subworkflow is automatically configured during the training process. Modifying it can disrupt
creation of the Predict workflow, leading to inaccurate results, or a failure to generate a predict workflow.
Machine Learning subworkflow by clicking on it. The following workflow units should now be visible:
Setup Packages and Variables- Configures the job and downloads all required packages with
Data Input- Reads the training data from disk
Train Test Split- Splits the data into a training set and a testing set
Data Standardize- Scales the data such that it has mean 0 and standard deviation 1
Model Train and Predict- Handles model training, and prediction
Parity Plot- Draws a plot of model predictions versus training data, and saves it to the disk. This plot is shown on the Results tab.
We will begin by configuring our
Machine Learning subworkflow. To begin, select the "Important Settings" portion of the
workflow editor. Then, set
target_column_name to "PBE_BE_eV" to define the target column of the training set.
Then, go back to the "Overview" portion of the workflow editor. We can now demonstrate how a workflow unit's parameters can be changed.
Begin by selecting the
Model Train and Predict workflow unit, as below:
We can then scroll down and change the
hidden_layer_sizes argument from
(100,100) to make
our model contain two hidden layers of 100 neurons each. We also change
max_iter to 5000 to train for up to 5000
Then, close the dialogue. The workflow has now been configured, and we are ready to train.
7. Submit the Job¶
We can now run the job and wait for it to complete.
8. Analyze the Training Results¶
After a few minutes, the job will complete. We can then visit the job's results tab,
where we will see that two properties have been calculated. The first,
Machine Learning - Model Train and Predict is
the predict workflow that was generated by the machine learning job. The predict workflow can be used to leverage the
trained model for additional predictions on new data.
The second result visible is
Machine Learning - Parity Plot, which contains the predicted versus actual values for the
adsorption energies we trained the model on.
This tutorial is demonstrated in the following animation: