Skip to content

DemoRegression.ipynb reveals some bug #155

Description

@gciatto

The following cell in demos/DemoRegression.ipynb:

crash = CRASH(predictor, train, max_depth=3, patience=1, readability_tradeoff=.75, algorithm=CRASH.Algorithm.ORCHiD)
crash.search()
(_, _, depth, threshold) = crash.get_best()[0]

orchid = Extractor.orchid(predictor, depth=depth, error_threshold=threshold, output=Target.REGRESSION)
theory_from_orchid = orchid.extract(train)
evaluate('ORCHiD', orchid, true, predicted)
print('ORCHiD extracted rules:\n\n' + pretty_theory(theory_from_orchid))

produces the following output and error:

Algorithm.ORCHiD. Depth: 1. Threshold = 0.00. MAE = 10.29, 2 rules
Algorithm.ORCHiD. Depth: 1. Threshold = 0.00. MAE = 8.47, 2 rules
Algorithm.ORCHiD. Depth: 1. Threshold = 0.00. MAE = 10.39, 2 rules

Algorithm.ORCHiD. Depth: 2. Threshold = 0.00. MAE = 6.76, 4 rules
Algorithm.ORCHiD. Depth: 2. Threshold = 0.00. MAE = 6.06, 4 rules
Algorithm.ORCHiD. Depth: 2. Threshold = 0.00. MAE = 6.71, 4 rules

Algorithm.ORCHiD. Depth: 3. Threshold = 0.00. MAE = 5.66, 8 rules
Algorithm.ORCHiD. Depth: 3. Threshold = 0.00. 

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [10], line 2
      1 crash = CRASH(predictor, train, max_depth=3, patience=1, readability_tradeoff=.75, algorithm=CRASH.Algorithm.ORCHiD)
----> 2 crash.search()
      3 (_, _, depth, threshold) = crash.get_best()[0]
      5 orchid = Extractor.orchid(predictor, depth=depth, error_threshold=threshold, output=Target.REGRESSION)

File /usr/local/lib/python3.9/site-packages/psyke/tuning/crash/__init__.py:25, in CRASH.search(self)
     24 def search(self):
---> 25     self.params = self.__search_depth()

File /usr/local/lib/python3.9/site-packages/psyke/tuning/crash/__init__.py:32, in CRASH.__search_depth(self)
     29 best = None
     31 for depth in range(1, self.max_depth + 1):
---> 32     p = self.__search_threshold(depth)
     33     b = Optimizer._best(p)[1]
     34     print()

File /usr/local/lib/python3.9/site-packages/psyke/tuning/crash/__init__.py:57, in CRASH.__search_threshold(self, depth)
     52 print(f"{self.algorithm}. Depth: {depth}. Threshold = {threshold:.2f}. ", end="")
     53 extractor = Extractor.creepy(self.predictor, depth, threshold, self.output, 10,
     54                              normalization=self.normalization) if self.algorithm == CRASH.Algorithm.CReEPy \
     55     else Extractor.orchid(self.predictor, depth, threshold, self.output, 10,
     56                           normalization=self.normalization)
---> 57 _ = extractor.extract(self.dataframe)
     58 mae, n = (extractor.mae(self.dataframe, self.predictor) if self.objective == Objective.MODEL else
     59           extractor.mae(self.dataframe)), extractor.n_rules
     60 print(f"MAE = {mae:.2f}, {n} rules")

File /usr/local/lib/python3.9/site-packages/psyke/__init__.py:251, in PedagogicalExtractor.extract(self, dataframe, mapping)
    249 data = dataframe.iloc[:, :-1].copy().join(new_y)
    250 data.columns = dataframe.columns
--> 251 return self._extract(data, mapping)

File /usr/local/lib/python3.9/site-packages/psyke/extraction/hypercubic/creepy/__init__.py:28, in CReEPy._extract(self, dataframe, mapping)
     27 def _extract(self, dataframe: pd.DataFrame, mapping: dict[str: int] = None) -> Theory:
---> 28     self._hypercubes = self.clustering.extract(dataframe)
     29     for cube in self._hypercubes:
     30         for dimension in self._ignore_dimensions():

File /usr/local/lib/python3.9/site-packages/psyke/clustering/exact/__init__.py:55, in ExACT.extract(self, dataframe)
     52 def extract(self, dataframe: pd.DataFrame) -> Iterable[HyperCube]:
     53     self._predictor.fit(dataframe.iloc[:, :-1], dataframe.iloc[:, -1])
     54     self._hypercubes = \
---> 55         self._iterate(Node(dataframe, HyperCube.create_surrounding_cube(dataframe, True, self._output)))
     56     return list(self._hypercubes)

File /usr/local/lib/python3.9/site-packages/psyke/clustering/cream/__init__.py:54, in CREAM._iterate(self, surrounding)
     52 gauss_params = select_gaussian_mixture(data, self.gauss_components)
     53 gauss_pred = gauss_params[2].predict(data)
---> 54 cubes = self.__eligible_cubes(gauss_pred, node, gauss_params[1])
     55 if len(cubes) < 1:
     56     continue

File /usr/local/lib/python3.9/site-packages/psyke/clustering/cream/__init__.py:29, in CREAM.__eligible_cubes(self, gauss_pred, node, clusters)
     27 if len(df) == 0:
     28     continue
---> 29 inner_cube = self._create_cube(df, clusters)
     30 indices = self._indices(inner_cube, node.dataframe)
     31 if indices is None:

File /usr/local/lib/python3.9/site-packages/psyke/clustering/exact/__init__.py:46, in ExACT._create_cube(self, dataframe, clusters)
     44 def _create_cube(self, dataframe: pd.DataFrame, clusters: int) -> ClosedCube:
     45     data = ExACT._remove_string_label(dataframe)
---> 46     dbscan_pred = DBSCAN(eps=select_dbscan_epsilon(data, clusters)).fit_predict(data.iloc[:, :-1])
     47     return HyperCube.create_surrounding_cube(
     48         dataframe.iloc[np.where(dbscan_pred == Counter(dbscan_pred).most_common(1)[0][0])],
     49         True, self._output
     50     )

File /usr/local/lib/python3.9/site-packages/psyke/clustering/utils.py:32, in select_dbscan_epsilon(data, clusters)
     30     epsilon = max(distances[-1], 1e-3)
     31 k = 1.
---> 32 dbscan_pred = DBSCAN(eps=epsilon * k).fit_predict(data.iloc[:, :-1])
     33 # while Counter(dbscan_pred).most_common(1)[0][0] == -1:
     34 for i in range(1000):

TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions