trained regression model evaluation

This commit is contained in:
Dylan Knutson
2025-07-10 22:37:59 +00:00
parent 0e262f99b9
commit 9f1fc93267
8 changed files with 545 additions and 195 deletions

View File

@@ -65,7 +65,7 @@ namespace :stats do
# Save each regression model to the database
regressions.each do |name, result|
normalizer = result.equation.normalizer
equation = result.equation
model_name = "fa_fav_id_and_date_#{name.downcase}"
TrainedRegressionModel.find_by(name: model_name)&.destroy
TrainedRegressionModel.create!(
@@ -78,17 +78,17 @@ namespace :stats do
train_test_split_ratio: 0.8, # hardcoded, see split_train_test default
random_seed: 42, # hardcoded, see split_train_test
max_points_limit: max_points,
x_min: normalizer.x.min,
x_max: normalizer.x.max,
y_min: normalizer.y.min,
y_max: normalizer.y.max,
coefficients: result.equation.coefficients,
x_min: equation.x.min,
x_max: equation.x.max,
y_min: equation.y.min,
y_max: equation.y.max,
coefficients: equation.coefficients,
training_r_squared: result.training_r_squared,
evaluation_r_squared: result.evaluation_r_squared,
equation_string: result.equation_string,
metadata: {
x_range: normalizer.x_range,
y_range: normalizer.y_range,
x_range: equation.x.range,
y_range: equation.y.range,
},
)
puts "💾 Saved #{name} regression model to DB."