{
"cells": [
{
"cell_type": "markdown",
"id": "d841f273",
"metadata": {},
"source": [
"# AutoML for Classification Model Screening\n",
"\n",
"The following are the steps for using AutoML for a classification task:\n",
"\n",
"\n",
"1. Provide an input pandas dataframe consisting of two columns:
\n",
" * SMILES strings
\n",
" * target class values
\n",
"\n",
"\n",
"2. If featurization = True, Molecules are represented as:
\n",
" * Coulomb matrix
\n",
" * RDKit Morgan (ECFP6 1024-bit) fingerprints
\n",
" * MACCs keys
\n",
" * RDKit hashed topological torsion
\n",
" * RDKit molecular descriptors (all)
\n",
" * Mordred molecular descriptors
\n",
" \n",
" If featurization=False, a feature set must be provided by the user.\n",
"\n",
"\n",
"3. Screens through various classifier models:
\n",
" * Single-core (runs regardless of multi_core value):\n",
" * [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html)
\n",
" * [DecisionTreeClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html)
\n",
" * [SVC](https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html)
\n",
" * [KNeighboursClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html)
\n",
" * Multi-core(set multi_core=True):\n",
" * [RandomForestClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html)
\n",
" * [ChemML_MLP](https://hachmannlab.github.io/chemml/ipython_notebooks/ml_model.html) (if n_datapoints>500)
\n",
" * (optional) [XGBClassifier](https://xgboost.readthedocs.io/en/latest/python/python_api.html)
\n",
" * (optional) [LightGBM](https://lightgbm.readthedocs.io/en/stable/)\n",
"\n",
"Yields 'n-best' models, with optimized hyperparamters.\n",
"\n",
"The output_dir argument specifies a folder that will be created wherever the code is run from, containing the following directory tree:\n",
"\n",
"
<output_dir>/" ] }, { "cell_type": "markdown", "id": "2a2ea142", "metadata": {}, "source": [ "## Load your data \n", "\n", "We are using ChemML's in-built dataset to demonstrate the minimum requirements to run AutoML." ] }, { "cell_type": "code", "execution_count": 1, "id": "3186feee", "metadata": { "scrolled": true }, "outputs": [], "source": [ "import pandas as pd\n", "from chemml.datasets import load_organic_density" ] }, { "cell_type": "code", "execution_count": 2, "id": "56240d5a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
|-- output.log
|-- scores.csv
|-- best_model/
| |-- model.pkl # most non-MLP models
| |-- model_chemml_model.json # MLP case (plus possible extra model files)
| |-- scaler.pkl # present when scaler exists for chosen feature_key
| |-- feature_order.json
| |-- metadata.json
|-- .model_screener_artifacts/
| |-- <run_key_1>/
| |-- model.pkl # or MLP artifact files
| |-- <run_key_2>/
...
| \n", " | smiles | \n", "density_Kg/m3 | \n", "
|---|---|---|
| 361 | \n", "c1scc(n1)c1ncc(s1)c1c(ccc2c1cccc2)c1cncs1 | \n", "1328.35 | \n", "
| 73 | \n", "S1CC(SC(C1)C1CCCC1)c1cocc1c1ccccc1 | \n", "1143.80 | \n", "
| 374 | \n", "N1CNC(NC1)c1sccc1C1(CSCCS1)c1cccs1 | \n", "1351.33 | \n", "
| 155 | \n", "c1nc(c(s1)c1nsnc1)c1csc(n1)c1cccs1 | \n", "1466.57 | \n", "
| 104 | \n", "Oc1ccc2c(c1c1cocc1)c(ccc2)c1ccccn1 | \n", "1207.67 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 248 | \n", "Oc1ncc(c(c1)C)c1cnccn1 | \n", "1195.16 | \n", "
| 145 | \n", "Sc1cc2ccccc2c(c1)c1cnccc1c1cnccn1 | \n", "1213.41 | \n", "
| 92 | \n", "c1sc(c(c1)c1ncccc1c1nsnc1)c1ccc2c(c1)cccc2 | \n", "1264.16 | \n", "
| 152 | \n", "N1CNC(NC1)(N1CNC(NC1)c1cncs1)c1cccc2c1cccc2 | \n", "1270.40 | \n", "
| 367 | \n", "C1CSC(CS1)C1(CSC(CS1)c1ccc2c(c1)cccc2)c1cnccn1 | \n", "1268.28 | \n", "
200 rows × 2 columns
\n", "| \n", " | Model | \n", "Accuracy | \n", "Recall | \n", "Precision | \n", "F1-score | \n", "time(seconds) | \n", "parameters | \n", "Feature | \n", "run_key | \n", "
|---|---|---|---|---|---|---|---|---|---|
| 27 | \n", "LogisticRegression | \n", "0.8 | \n", "0.793651 | \n", "0.844444 | \n", "0.797587 | \n", "9.955029 | \n", "[{'C': 0.1, 'class_weight': None, 'dual': Fals... | \n", "mord_descriptors | \n", "LogisticRegression_mord_descriptors_324dd7b551... | \n", "
| 26 | \n", "KNeighborsClassifier | \n", "0.75 | \n", "0.746032 | \n", "0.811111 | \n", "0.758371 | \n", "6.259871 | \n", "[{'algorithm': 'auto', 'leaf_size': 30, 'metri... | \n", "mord_descriptors | \n", "KNeighborsClassifier_mord_descriptors_1e7fa7c1... | \n", "
| 24 | \n", "DecisionTreeClassifier | \n", "0.7 | \n", "0.690476 | \n", "0.763889 | \n", "0.694444 | \n", "3.405225 | \n", "[{'ccp_alpha': 0.0, 'class_weight': None, 'cri... | \n", "mord_descriptors | \n", "DecisionTreeClassifier_mord_descriptors_6a4d98... | \n", "
| 19 | \n", "LogisticRegression | \n", "0.65 | \n", "0.642857 | \n", "0.662963 | \n", "0.646562 | \n", "7.150034 | \n", "[{'C': 42.16315789473685, 'class_weight': None... | \n", "hashedatompair_radius3 | \n", "LogisticRegression_hashedatompair_radius3_c444... | \n", "
| 17 | \n", "SVC | \n", "0.6 | \n", "0.595238 | \n", "0.604762 | \n", "0.597691 | \n", "2.851144 | \n", "[{'C': 0.0037926901907322525, 'break_ties': Fa... | \n", "hashedatompair_radius3 | \n", "SVC_hashedatompair_radius3_ef5a1fb731b9493682d... | \n", "
| 15 | \n", "KNeighborsClassifier | \n", "0.55 | \n", "0.563492 | \n", "0.541667 | \n", "0.545788 | \n", "5.889152 | \n", "[{'algorithm': 'auto', 'leaf_size': 30, 'metri... | \n", "hashedtopologicaltorsion_radius3 | \n", "KNeighborsClassifier_hashedtopologicaltorsion_... | \n", "
| 16 | \n", "DecisionTreeClassifier | \n", "0.5 | \n", "0.507937 | \n", "0.541667 | \n", "0.505628 | \n", "1.434301 | \n", "[{'ccp_alpha': 0.0, 'class_weight': None, 'cri... | \n", "hashedatompair_radius3 | \n", "DecisionTreeClassifier_hashedatompair_radius3_... | \n", "
LogisticRegression(C=0.1, solver='sag')In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.