{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fdbab969",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn import ensemble as sk_ensemble\n",
"from sklearn import model_selection as sk_model_selection\n",
"from sklearn import utils as sk_utils\n",
"\n",
"import model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "feccb798",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>smiles</th>\n",
" <th>binary_classification_preference_idx</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>CN(C)C</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>CCOC(=O)C(C)=O</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>CCC/C=C\\CO</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>NCCCCCN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>CC/C=C\\CCO</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" smiles binary_classification_preference_idx\n",
"0 CN(C)C 1\n",
"1 CCOC(=O)C(C)=O 0\n",
"2 CCC/C=C\\CO 0\n",
"3 NCCCCCN 1\n",
"4 CC/C=C\\CCO 0"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data_csv = './data/a_MacWilliam_et_al/data.csv'\n",
"data_df = pd.read_csv(data_csv)\n",
"data_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "7f0eee41",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((58, 256), (58,))"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = model.get_embs(data_df['smiles'])\n",
"y = data_df['binary_classification_preference_idx'].values\n",
"x.shape, y.shape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "28194e54",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9349999999999999"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x, y = sk_utils.shuffle(x, y)\n",
"\n",
"model = sk_ensemble.RandomForestClassifier()\n",
"cv_auroc = sk_model_selection.cross_val_score(model, x, y, cv=10, scoring='roc_auc')\n",
"np.average(cv_auroc)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}