Spaces:
Running
Running
Commit
·
255c89c
1
Parent(s):
b7b7f87
Better error message for custom operators
Browse files- pysr/sr.py +14 -3
pysr/sr.py
CHANGED
@@ -940,9 +940,20 @@ class PySRRegressor(BaseEstimator, RegressorMixin):
|
|
940 |
"""
|
941 |
self.refresh()
|
942 |
best = self.get_best(index=index)
|
943 |
-
|
944 |
-
|
945 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
946 |
|
947 |
def sympy(self, index=None):
|
948 |
"""Return sympy representation of the equation(s) chosen by `model_selection`.
|
|
|
940 |
"""
|
941 |
self.refresh()
|
942 |
best = self.get_best(index=index)
|
943 |
+
try:
|
944 |
+
if self.multioutput:
|
945 |
+
return np.stack([eq["lambda_format"](X) for eq in best], axis=1)
|
946 |
+
return best["lambda_format"](X)
|
947 |
+
except Exception as error:
|
948 |
+
# Add extra information to the error, to say that the user
|
949 |
+
# should try to adjust extra_sympy_params.
|
950 |
+
raise ValueError(
|
951 |
+
"Failed to evaluate the expression.\n"
|
952 |
+
"If you are using a custom operator, make sure to define it in extra_sympy_mappings, "
|
953 |
+
"e.g., `model.extra_sympy_mappings = {'inv': lambda x: 1 / x}`."
|
954 |
+
) from error
|
955 |
+
|
956 |
+
|
957 |
|
958 |
def sympy(self, index=None):
|
959 |
"""Return sympy representation of the equation(s) chosen by `model_selection`.
|