Instructions to use Delower/dpp4-pic50-extra-trees with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Delower/dpp4-pic50-extra-trees with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Delower/dpp4-pic50-extra-trees", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download infer.py from Delower/dpp4-pic50-extra-trees: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/Delower/dpp4-pic50-extra-trees/resolve/main/infer.py
- Command line
-
hf download hf://Delower/dpp4-pic50-extra-trees/infer.py
-
curl -L -o infer.py https://huggingface.co/Delower/dpp4-pic50-extra-trees/resolve/main/infer.py
1.99 kB
| """Inference helper for models uploaded by hf_upload_universal.py. | |
| Usage: | |
| from infer import predict_smiles | |
| predict_smiles(model, ["CCO", "CC(=O)O"]) | |
| The model was trained on the features listed in config.json | |
| (e.g. Morgan fingerprint 1024 + physicochemical descriptors). | |
| This model is a sklearn Pipeline (ColumnTransformer + | |
| ExtraTreesRegressor). LazyPredict pipelines select columns by STRING | |
| name, so features must be passed as a pandas DataFrame with columns | |
| feature_0..feature_1029. | |
| Feature order: Morgan fingerprint 1024 (radius 2) first, then 6 physchem | |
| descriptors in this order: MolWt, MolLogP, TPSA, NumHDonors, | |
| NumHAcceptors, NumRotatableBonds. | |
| Unpickling model.pkl requires lazypredict (see requirements.txt). | |
| """ | |
| import pickle | |
| import numpy as np | |
| import pandas as pd | |
| from rdkit import Chem | |
| from rdkit.Chem import AllChem, Descriptors | |
| def featurize(smiles_list, features): | |
| rows = [] | |
| for smi in smiles_list: | |
| mol = Chem.MolFromSmiles(smi) | |
| if mol is None: | |
| raise ValueError(f"Invalid SMILES: {smi}") | |
| parts = [] | |
| if "morgan1024" in features: | |
| fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2, nBits=1024) | |
| parts.append(np.asarray(fp, dtype=float)) | |
| if "physchem" in features: | |
| parts.append(np.array([ | |
| Descriptors.MolWt(mol), Descriptors.MolLogP(mol), | |
| Descriptors.TPSA(mol), Descriptors.NumHDonors(mol), | |
| Descriptors.NumHAcceptors(mol), | |
| Descriptors.NumRotatableBonds(mol), | |
| ], dtype=float)) | |
| rows.append(np.concatenate(parts) if parts else np.array([])) | |
| X = np.vstack(rows) | |
| return pd.DataFrame(X, columns=[f"feature_{i}" for i in range(X.shape[1])]) | |
| def load_model(path="model.pkl"): | |
| with open(path, "rb") as f: | |
| return pickle.load(f) | |
| def predict_smiles(model, smiles_list, features=("morgan1024", "physchem")): | |
| X = featurize(smiles_list, features) | |
| return model.predict(X) | |