Oloren-AI / olorenchemengine

OCE is the first infinitely composable library for reproducibly implementing SOTA molecular property prediction/QSAR techniques.
MIT License
98 stars 14 forks source link

errors using error model with model.fit_cv method #73

Closed XZhang-ML closed 1 year ago

XZhang-ML commented 1 year ago

I try to running the code example from https://docs.chemengine.org/examples/2C_Error_Model_Integration.html#production-level-models

model = oce.RandomForestModel(oce.OlorenCheckpoint("default"), n_estimators=1000)
error_model = oce.SDC()

model.fit_cv(dataset.entire_dataset[0], dataset.entire_dataset[1], error_model=error_model, scoring = "r2")

But encountered errors like this:

----> 4 model.fit_cv(dataset.entire_dataset[0], dataset.entire_dataset[1], error_model=error_model, scoring = "r2")

File .../python3.9/site-packages/olorenchemengine/base_class.py:729, in BaseModel.fit_cv(self, X, y, n_splits, error_model, ci, scoring)
    727     residuals = np.abs(pred - true)
    728     if hasattr(self, "error_model"):
--> 729         self.error_model._fit(residuals, scores, quantile=ci)
    730         self.em_status = "fitted"
    731 elif self.setting == "classification":

TypeError: _fit() got an unexpected keyword argument 'quantile'

It seems that the error_model does not have quantile=ci yet.

XZhang-ML commented 1 year ago

Also if I don't use the error model, it seems that the fit_cv function currently is not updated for the condition for elif (not hasattr(self, "error_model") and self.setting == "regression".

----> 4 model.fit_cv(dataset.entire_dataset[0],
      5              dataset.entire_dataset[1], 
      6              #error_model=error_model,
      7              scoring = "Root Mean Squared Error")

File /opt/conda/envs/oloren/lib/python3.9/site-packages/olorenchemengine/base_class.py:727, in BaseModel.fit_cv(self, X, y, n_splits, error_model, ci, scoring, **kwargs)
    725 if self.setting == "regression":
    726     self.calibrator = LinearRegression()
--> 727     self.calibrator.fit(pred.reshape(-1, 1), true.reshape(-1, 1))
    728     pred = self.calibrator.predict(pred.reshape(-1, 1)).reshape(-1)
    729     true = true.reshape(-1)

AttributeError: 'NoneType' object has no attribute 'reshape'
davidzqhuang commented 1 year ago

Will look into this

alexzli commented 1 year ago

Fixed in #77