Spaces:
Running
Running
refactor: move keyword suggester to utils
Browse files- pysr/sr.py +1 -12
- pysr/utils.py +12 -0
pysr/sr.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
"""Define the PySRRegressor scikit-learn interface."""
|
| 2 |
|
| 3 |
import copy
|
| 4 |
-
import difflib
|
| 5 |
-
import inspect
|
| 6 |
import os
|
| 7 |
import pickle as pkl
|
| 8 |
import re
|
|
@@ -57,6 +55,7 @@ from .utils import (
|
|
| 57 |
_preprocess_julia_floats,
|
| 58 |
_safe_check_feature_names_in,
|
| 59 |
_subscriptify,
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
ALREADY_RAN = False
|
|
@@ -2551,16 +2550,6 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2551 |
return with_preamble(table_string)
|
| 2552 |
|
| 2553 |
|
| 2554 |
-
def _suggest_keywords(cls, k: str) -> List[str]:
|
| 2555 |
-
valid_keywords = [
|
| 2556 |
-
param
|
| 2557 |
-
for param in inspect.signature(cls.__init__).parameters
|
| 2558 |
-
if param not in ["self", "kwargs"]
|
| 2559 |
-
]
|
| 2560 |
-
suggestions = difflib.get_close_matches(k, valid_keywords, n=3)
|
| 2561 |
-
return suggestions
|
| 2562 |
-
|
| 2563 |
-
|
| 2564 |
def idx_model_selection(equations: pd.DataFrame, model_selection: str):
|
| 2565 |
"""Select an expression and return its index."""
|
| 2566 |
if model_selection == "accuracy":
|
|
|
|
| 1 |
"""Define the PySRRegressor scikit-learn interface."""
|
| 2 |
|
| 3 |
import copy
|
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
import pickle as pkl
|
| 6 |
import re
|
|
|
|
| 55 |
_preprocess_julia_floats,
|
| 56 |
_safe_check_feature_names_in,
|
| 57 |
_subscriptify,
|
| 58 |
+
_suggest_keywords,
|
| 59 |
)
|
| 60 |
|
| 61 |
ALREADY_RAN = False
|
|
|
|
| 2550 |
return with_preamble(table_string)
|
| 2551 |
|
| 2552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2553 |
def idx_model_selection(equations: pd.DataFrame, model_selection: str):
|
| 2554 |
"""Select an expression and return its index."""
|
| 2555 |
if model_selection == "accuracy":
|
pysr/utils.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
from pathlib import Path
|
|
@@ -61,3 +63,13 @@ def _subscriptify(i: int) -> str:
|
|
| 61 |
For example, 123 -> "βββ".
|
| 62 |
"""
|
| 63 |
return "".join([chr(0x2080 + int(c)) for c in str(i)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import difflib
|
| 2 |
+
import inspect
|
| 3 |
import os
|
| 4 |
import re
|
| 5 |
from pathlib import Path
|
|
|
|
| 63 |
For example, 123 -> "βββ".
|
| 64 |
"""
|
| 65 |
return "".join([chr(0x2080 + int(c)) for c in str(i)])
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _suggest_keywords(cls, k: str) -> List[str]:
|
| 69 |
+
valid_keywords = [
|
| 70 |
+
param
|
| 71 |
+
for param in inspect.signature(cls.__init__).parameters
|
| 72 |
+
if param not in ["self", "kwargs"]
|
| 73 |
+
]
|
| 74 |
+
suggestions = difflib.get_close_matches(k, valid_keywords, n=3)
|
| 75 |
+
return suggestions
|