Skip to content

Commit

Permalink
perf: perfect the enum class usage in regression algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanyHe committed Jan 20, 2025
1 parent e68ce44 commit b25d386
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 98 deletions.
14 changes: 11 additions & 3 deletions geochemistrypi/data_mining/model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,21 @@ class LinearWorkflowMixin:

@staticmethod
def _show_formula(
coef: np.ndarray, intercept: np.ndarray, features_name: np.ndarray, algorithm_name: str, regression_classification: str, y_train: pd.DataFrame, local_path: str, mlflow_path: str
coef: np.ndarray,
intercept: np.ndarray,
features_name: np.ndarray,
algorithm_name: str,
func_name: str,
regression_classification: str,
y_train: pd.DataFrame,
local_path: str,
mlflow_path: str,
) -> None:
"""Show the formula."""
print(f"-----* {algorithm_name} Formula *-----")
print(f"-----* {func_name} *-----")
formula = show_formula(coef, intercept, features_name, regression_classification, y_train)
formula_str = json.dumps(formula, indent=4)
save_text(formula_str, f"{algorithm_name} Formula", local_path, mlflow_path)
save_text(formula_str, f"{func_name}", local_path, mlflow_path)

@staticmethod
def _plot_2d_scatter_diagram(feature_data: pd.DataFrame, target_data: pd.DataFrame, data_name: str, algorithm_name: str, func_name: str, local_path: str, mlflow_path: str) -> None:
Expand Down
28 changes: 19 additions & 9 deletions geochemistrypi/data_mining/model/func/algo_regression/_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ class RegressionCommonFunction(Enum):
PERMUTATION_IMPORTANC_DIAGRAM = "Permutation Importance Diagram"


class RegressionSpecialFunction(Enum):
FEATURE_IMPORTANCE_DIAGRAM = "Feature Importance Diagram"
SINGLE_TREE_DIAGRAM = "Single Tree Diagram"
TWO_DIMENSIONAL_SCATTER_DIAGRAM = "2D Scatter Diagram"
THREE_DIMENSIONAL_SCATTER_DIAGRAM = "3D Scatter Diagram"
TWO_DIMENSIONAL_LINE_DIAGRAM = "2D Line Diagram"
THREE_DIMENSIONAL_SURFACE_DIAGRAM = "3D Surface Diagram"


class XGBoostSpecialFunction(Enum):
FEATURE_IMPORTANCE_DIAGRAM = "Feature Importance Diagram"

Expand Down Expand Up @@ -71,3 +62,22 @@ class RidgeSpecialFunction(Enum):
THREE_DIMENSIONAL_SCATTER_DIAGRAM = "3D Scatter Diagram"
TWO_DIMENSIONAL_LINE_DIAGRAM = "2D Line Diagram"
THREE_DIMENSIONAL_SURFACE_DIAGRAM = "3D Surface Diagram"


class ExtraTreesSpecialFunction(Enum):
FEATURE_IMPORTANCE_DIAGRAM = "Feature Importance Diagram"
SINGLE_TREE_DIAGRAM = "Single Tree Diagram"


class RandomForestSpecialFunction(Enum):
FEATURE_IMPORTANCE_DIAGRAM = "Feature Importance Diagram"
SINGLE_TREE_DIAGRAM = "Single Tree Diagram"


class GradientBoostingSpecialFunction(Enum):
FEATURE_IMPORTANCE_DIAGRAM = "Feature Importance Diagram"
SINGLE_TREE_DIAGRAM = "Single Tree Diagram"


class PolynomialSpecialFunction(Enum):
POLYNOMIAL_REGRESSION_FORMULA = "Polynomial Regression Formula"
Loading

0 comments on commit b25d386

Please sign in to comment.