SIENTIAPDE-1321: Formatted files
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -145,6 +145,7 @@ celerybeat.pid
|
|||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
|
venv_311/
|
||||||
env.bak/
|
env.bak/
|
||||||
venv.bak/
|
venv.bak/
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ class ModelRepository:
|
|||||||
self.model_serving.log_artifact(data.report_path)
|
self.model_serving.log_artifact(data.report_path)
|
||||||
self.model_serving.log_artifact(data.train_data_path)
|
self.model_serving.log_artifact(data.train_data_path)
|
||||||
self.model_serving.log_artifact(data.test_data_path)
|
self.model_serving.log_artifact(data.test_data_path)
|
||||||
|
|
||||||
# Log equation artifact if available
|
# Log equation artifact if available
|
||||||
if data.equation_path and path.exists(data.equation_path):
|
if data.equation_path and path.exists(data.equation_path):
|
||||||
self.model_serving.log_artifact(data.equation_path)
|
self.model_serving.log_artifact(data.equation_path)
|
||||||
|
|||||||
@@ -175,10 +175,10 @@ class TrainingRepository:
|
|||||||
)
|
)
|
||||||
|
|
||||||
tmr.r2_val = round(r2(tmr.y_test.astype(np.float64), tmr.y_pred.astype(np.float64)), 2)
|
tmr.r2_val = round(r2(tmr.y_test.astype(np.float64), tmr.y_pred.astype(np.float64)), 2)
|
||||||
|
|
||||||
# Extract model equation
|
# Extract model equation
|
||||||
tmr.equation = self._extract_model_equation(tmr.regr, params)
|
tmr.equation = self._extract_model_equation(tmr.regr, params)
|
||||||
|
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
f'Model metrics calculated successfully - experiment run id: {params.experiment_run_id}'
|
f'Model metrics calculated successfully - experiment run id: {params.experiment_run_id}'
|
||||||
)
|
)
|
||||||
@@ -254,18 +254,20 @@ class TrainingRepository:
|
|||||||
ar_var=params.target_variable if params.include_ar else None,
|
ar_var=params.target_variable if params.include_ar else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _extract_model_equation(self, regr: LinearRegressionModel, params: TrainModelParams) -> dict:
|
def _extract_model_equation(
|
||||||
|
self, regr: LinearRegressionModel, params: TrainModelParams
|
||||||
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Extract the linear regression equation coefficients and create equation metadata.
|
Extract the linear regression equation coefficients and create equation metadata.
|
||||||
|
|
||||||
This method extracts the coefficients and intercept from the trained model
|
This method extracts the coefficients and intercept from the trained model
|
||||||
and creates a structured dictionary containing the equation information
|
and creates a structured dictionary containing the equation information
|
||||||
for serialization as JSON artifact.
|
for serialization as JSON artifact.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
regr: Trained LinearRegressionModel object
|
regr: Trained LinearRegressionModel object
|
||||||
params: Training parameters containing variable information
|
params: Training parameters containing variable information
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Equation metadata containing:
|
dict: Equation metadata containing:
|
||||||
- target_variable: Name of the target variable
|
- target_variable: Name of the target variable
|
||||||
@@ -276,25 +278,27 @@ class TrainingRepository:
|
|||||||
"""
|
"""
|
||||||
coefficients = regr.regr.coef_
|
coefficients = regr.regr.coef_
|
||||||
intercept = regr.regr.intercept_
|
intercept = regr.regr.intercept_
|
||||||
|
|
||||||
# Create coefficients dictionary
|
# Create coefficients dictionary
|
||||||
coefficients_dict = {}
|
coefficients_dict = {}
|
||||||
for i, var in enumerate(params.variable_columns):
|
for i, var in enumerate(params.variable_columns):
|
||||||
coefficients_dict[var] = float(coefficients[i])
|
coefficients_dict[var] = float(coefficients[i])
|
||||||
|
|
||||||
# Create equation string
|
# Create equation string
|
||||||
equation_parts = [f"{coef:.6f} * {var}" for var, coef in coefficients_dict.items()]
|
equation_parts = [f'{coef:.6f} * {var}' for var, coef in coefficients_dict.items()]
|
||||||
equation_string = f"{params.target_variable} = {intercept:.6f} + " + " + ".join(equation_parts)
|
equation_string = f'{params.target_variable} = {intercept:.6f} + ' + ' + '.join(
|
||||||
|
equation_parts
|
||||||
|
)
|
||||||
|
|
||||||
# Create LaTeX equation
|
# Create LaTeX equation
|
||||||
latex_parts = [f"{coef:.6f} \\cdot {var}" for var, coef in coefficients_dict.items()]
|
latex_parts = [f'{coef:.6f} \\cdot {var}' for var, coef in coefficients_dict.items()]
|
||||||
latex_equation = f"{params.target_variable} = {intercept:.6f} + " + " + ".join(latex_parts)
|
latex_equation = f'{params.target_variable} = {intercept:.6f} + ' + ' + '.join(latex_parts)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'target_variable': params.target_variable,
|
'target_variable': params.target_variable,
|
||||||
'coefficients': coefficients_dict,
|
'coefficients': coefficients_dict,
|
||||||
'intercept': float(intercept),
|
'intercept': float(intercept),
|
||||||
'equation_string': equation_string,
|
'equation_string': equation_string,
|
||||||
'latex_equation': latex_equation,
|
'latex_equation': latex_equation,
|
||||||
'model_type': 'Linear Regression'
|
'model_type': 'Linear Regression',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user