GeneralizedOptimalSparseDecisionTrees icon indicating copy to clipboard operation
GeneralizedOptimalSparseDecisionTrees copied to clipboard

Cannot use F1 objective, because w is set to None

Open wolpl opened this issue 4 years ago • 0 comments

When running the fit(X,y) method of the GOSDT python class, I consistently get the following error message (trace shortened):

Traceback (most recent call last):
...
  File ".../gosdt.py", line 95, in fit
    self.__python_train__(X, y)
  File ".../gosdt.py", line 273, in __python_train__
    leaves_c, pred_c, dic, nleaves, m, n, totaltime, time_c, R_c, COUNT, C_c, accu, best_is_cart, clf = bbound(
  File ".../imbalance/osdt_imb_v9.py", line 1875, in bbound
    root_leaf = CacheLeaf(name, n, P, N, (), x, y, y_mpz, z_mpz, make_all_ones(n + 1),
  File ".../imbalance/osdt_imb_v9.py", line 1676, in __init__
    self.pred = bound.leaf_predict(self.p, self.n, w)
  File ".../imbalance/osdt_imb_v9.py", line 1344, in leaf_predict
    if w * p <= n:
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

When printing the variables w, p and n prior to the last call (line 1344 in osdt_imb_v9.py) I can see that w is None, the other two are not.

It seems to me that using the F1-score is impossible, because in gosdt.py the configuration entry for w is set to None whenever F1 should be used. Unless w is altered somewhere the operation in osdt_imb_v9.py consequently has to fail. File gosdt.py, lines 85-87:

elif self.configuration["objective"] == "f1":
    self.configuration["theta"] = None
    self.configuration["w"] = None

Running the algorithm without specifying the objective and with other objectives like acc, bacc or wacc works perfectly fine. How can I use F1? Is the C++ implementation able to optimize for an F1 objective function?

wolpl avatar Sep 09 '20 09:09 wolpl