ifiguero 2025-03-18 22:37:06 -03:00
parent 6af8ab89e4
commit 70aa3e905d
1 changed files with 17 additions and 13 deletions

View File

@ -44,7 +44,7 @@ def get_seed():
class eNoseTrainer:
def __init__(self, loader, test_size=0.2, debug=False):
self.ledger = pd.DataFrame(columns=["node", "ts", "Dataset", "Samples", "Target", "Train Size", "Train Ratio", "Model", "Params", "Ratio", "Train mse", "mse", "mae", "rmse"])
self.ledger = pd.DataFrame(columns=["node", "ts", "Dataset", "Samples", "Target", "Train Size", "Train Ratio", "Model", "Params", "Ratio", "Train mse", "mse", "mae", "rmse", "num_params"])
self.loader = loader
self.name = self.loader.label_file
self.state = dict()
@ -179,8 +179,8 @@ class eNoseTrainer:
Y_pred = model.predict(X_test)
mse = mean_squared_error(Y_test, Y_pred)
num_params = model.count_params() # Get number of weights in the model
trial.set_user_attr("num_params", num_params) # Store it in the trial object
# num_params = model.count_params() # Get number of weights in the model
# trial.set_user_attr("num_params", num_params) # Store it in the trial object
return mse
@ -371,7 +371,8 @@ class eNoseTrainer:
"Train mse": tmse,
"mse": mse,
"mae": mae,
"rmse": rmse
"rmse": rmse,
"num_params": sum(t.count("\n") for t in optimized_model.get_booster().get_dump())
}] )
self.ledger = pd.concat([self.ledger, newrow], ignore_index=True)
self.bar.update()
@ -428,7 +429,8 @@ class eNoseTrainer:
"Train mse": tmse,
"mse": mse,
"mae": mae,
"rmse": rmse
"rmse": rmse,
"num_params": sum(t.count("\n") for t in optimized_model.get_booster().get_dump())
}] )
self.ledger = pd.concat([self.ledger, newrow], ignore_index=True)
self.bar.update()
@ -481,7 +483,7 @@ class eNoseTrainer:
for trial in study.trials:
trial_info = trial.params.copy()
trial_info['mse'] = trial.value
trial_info['num_params'] = trial.user_attrs.get("num_params", 0)
# trial_info['num_params'] = trial.user_attrs.get("num_params", 0)
trials_data.append(trial_info)
df = pd.DataFrame(trials_data)
@ -508,17 +510,18 @@ class eNoseTrainer:
newrow = pd.DataFrame( [{"node": node,
"ts": ts,
"Dataset": dataset,
"Samples": Y_xboost.shape[0],
"Samples": Y_conv1d.shape[0],
"Target": self.loader.target,
"Train Size": Y_train.shape[0],
"Train Ratio": Y_train.shape[0]/Y_xboost.shape[0],
"Train Ratio": Y_train.shape[0]/Y_conv1d.shape[0],
"Ratio": self.ratio,
"Model": model_id,
"Params": json.dumps(study.best_params),
"Train mse": mse_train,
"mse": mse_test,
"mae": mae_test,
"rmse": rmse_test
"rmse": rmse_test,
"num_params": best_model.count_params()
}] )
self.ledger = pd.concat([self.ledger, newrow], ignore_index=True)
self.bar.update()
@ -572,7 +575,7 @@ class eNoseTrainer:
for trial in study.trials:
trial_info = trial.params.copy()
trial_info['mse'] = trial.value
trial_info['num_params'] = trial.user_attrs.get("num_params", 0)
# trial_info['num_params'] = trial.user_attrs.get("num_params", 0)
trials_data.append(trial_info)
df = pd.DataFrame(trials_data)
@ -599,17 +602,18 @@ class eNoseTrainer:
newrow = pd.DataFrame( [{"node": node,
"ts": ts,
"Dataset": dataset,
"Samples": Y_xboost.shape[0],
"Samples": Y_conv1d.shape[0],
"Target": self.loader.target,
"Train Size": Y_train.shape[0],
"Train Ratio": Y_train.shape[0]/Y_xboost.shape[0],
"Train Ratio": Y_train.shape[0]/Y_conv1d.shape[0],
"Ratio": self.ratio,
"Model": model_id,
"Params": json.dumps(study.best_params),
"Train mse": mse_train,
"mse": mse_test,
"mae": mae_test,
"rmse": rmse_test
"rmse": rmse_test,
"num_params": best_model.count_params()
}] )
self.ledger = pd.concat([self.ledger, newrow], ignore_index=True)