@@ -222,8 +222,9 @@ def simplify_model(name, params, tol=1e-6):
222222
223223def select_best_fitting_model (x_data , y_data ):
224224 """
225- Attempts to fit the data with the best model using the original logic first.
226- If no valid model is found, falls back to the updated logic.
225+ Attempts to fit the data with the best model with just rss comparing approach.
226+ If no valid model is found during the fitting process,
227+ the fallback approach ensures that a model is still selected
227228
228229 Args:
229230 x_data (np.array): Input data sizes.
@@ -233,7 +234,7 @@ def select_best_fitting_model(x_data, y_data):
233234 dict: Dictionary containing the best-fit model, parameters, and residual sum of squares (RSS).
234235 """
235236 best_fit = {'model' : None , 'params' : None , 'rss' : np .inf }
236- fallback_fit = {'model' : 'linear' , 'params' : [0 , np .mean (y_data )], 'rss' : np .inf } # Default to O(n)
237+ fallback_fit = {'model' : 'linear' , 'params' : [0 , np .mean (y_data )], 'rss' : np .inf }
237238 y_scale = np .std (y_data ) if not np .isclose (np .std (y_data ), 0 , atol = 1e-12 ) else 1
238239
239240 model_scores = [] # Track all residuals and penalties
@@ -264,10 +265,8 @@ def select_best_fitting_model(x_data, y_data):
264265 complexity_penalty = len (params ) * 1e-3
265266 rss += complexity_penalty
266267
267- # Save for fallback
268268 model_scores .append ((rss , complexity_penalty , name , params ))
269269
270- # Update best fit
271270 if rss < best_fit ['rss' ]:
272271 simplified_name , simplified_params = simplify_model (name , params )
273272 best_fit = {'model' : simplified_name , 'params' : simplified_params , 'rss' : rss }
0 commit comments