#Prepare ORD data for training a machine learning model import math import pandas as pd import numpy as np import matplotlib.pyplot as plt from rdkit.Chem import AllChem from sklearn import model_selection, metrics from glob import glob from rdkit import Chem from molvs import Standardizer # Create new dataframe containing only columns to be used in modeling model_cols = ['inputs["catalyst"].components[0].identifiers[1].value', #Pd catalyst 'inputs["aryl halide"].components[0].identifiers[0].value', #Aryl Halide 'inputs["base"].components[0].identifiers[1].value', #Base 'inputs["additive"].components[0].identifiers[0].value', #Amine or solvent (in controls) 'outcomes[0].products[0].measurements[0].percentage.value' #% yield ] #Read data from sanitized data .csv file file_path = 'data/Sanitized_Ahneman_ORD_Data.csv' #Sanitized data sanitized_df = pd.read_csv(file_path) df = sanitized_df[model_cols] #Use sanitized data in the model with correct columns to use in the ML model # Check for NaN values print(f"number of NaN values: {df.isnull().sum().sum()}") # Show column counts print("Column Info") df.info() # Show dataset statistics for numerical fields print("Dataset Statistics for Numerical Fields:") df.describe() #One-Hot Encoding (OHE) # Convert reaction input labels to one-hot encoding input_cols = model_cols[:-1] # Assign names for each input prefix = ["Catalyst", "Aryl Halide", "Base", "Additives"] # Create one-hot encoded input dataset ohe_df = pd.get_dummies(df[input_cols], prefix=prefix) # Add yield column to ohe dataset ohe_df["yield"] = df[model_cols[-1]] / 100 #yield is the target variable the ML model will learn to optimize # View dataset print(ohe_df.shape) ohe_df.to_csv('data/Prepared_Data.csv', index=False)