wfondrie / mokapot

Fast and flexible semi-supervised learning for peptide detection in Python
https://mokapot.readthedocs.io
Apache License 2.0
40 stars 14 forks source link

AttributeError when using alternative machine learning algorithms #61

Closed surya-money closed 1 year ago

surya-money commented 1 year ago

Describe the bug: When trying to pass a RandomForestClassifier to brew() as an alternative Model object in place of the default PercolatorModel, the following error is raised:

Traceback (most recent call last):
  File "/Users/Surya/TalusBio/test.py", line 143, in <module>
    moka_test_model, _ = mokapot.brew(psms, model=rf_model)
  File "/Users/Surya/TalusBio/mokapot/mokapot/brew.py", line 124, in brew
    models.sort(key=lambda x: x[0].estimator.intercept_)
  File "/Users/Surya/TalusBio/mokapot/mokapot/brew.py", line 124, in <lambda>
    models.sort(key=lambda x: x[0].estimator.intercept_)
AttributeError: 'RandomForestClassifier' object has no attribute 'intercept_'

To Reproduce:

import mokapot
from mokapot.model import Model
from sklearn.ensemble import RandomForestClassifier
psms = mokapot.read_pin("psms.pin")
moka_conf, _ = mokapot.brew(psms, model=Model(RandomForestClassifier(max_depth=2, 2)))

The hyperparameters for RandomForestClassifier are optional but greatly decrease runtime.

wfondrie commented 1 year ago

Thanks this is great @surya-money!