Gilad Rubin
11/25/2023, 5:54 PMnodes.py
.
In the tutorial, parameters are passed to functions using a parameters
dictionary, as shown in the split_data
function:
def split_data(data: pd.DataFrame, parameters: Dict) -> Tuple:
# function body
features = parameters["features"]
...
My question is: Is it possible to specify function parameters in nodes.py
directly, instead of using a params
dictionary? For example, I'd like to directly define parameters like features
and test_size
in the function signature, rather than extracting them from a dictionary. This approach would make the function more portable and easier to interact with.
Specifically, I'm looking to refactor the function to unpack the dictionary within the node definition itself. Is this a supported pattern in Kedro, or are there any best practices or considerations I should be aware of when implementing this?
Any guidance or examples would be greatly appreciated!
Thank you!William Caicedo
11/25/2023, 8:36 PM# in parameters.yml
step_size: 1
learning_rate: 0.01
# in node definition
def increase_volume(volume, step):
return volume + step
# in pipeline definition
node(
func=increase_volume,
inputs=["input_volume", "params:step_size"],
outputs="output_volume",
)
https://docs.kedro.org/en/0.18.8/configuration/parameters.html#how-to-use-parametersGilad Rubin
11/26/2023, 8:12 AMWilliam Caicedo
11/26/2023, 9:20 AM# in parameters.yml
model_params:
learning_rate: 0.01
test_data_ratio: 0.2
number_of_train_iterations: 10000
# in node definition
def train_model(data, model):
lr = model["learning_rate"]
test_data_ratio = model["test_data_ratio"]
iterations = model["number_of_train_iterations"]
...
# in pipeline definition
node(
func=train_model,
inputs=["input_data", "params:model_params"],
outputs="output_data",
)
Gilad Rubin
11/26/2023, 9:23 AM# in parameters.yml
model_params:
learning_rate: 0.01
test_data_ratio: 0.2
number_of_train_iterations: 10000
# in node definition
def train_model(data, model, lr):
test_data_ratio = model["test_data_ratio"]
iterations = model["number_of_train_iterations"]
...
# in pipeline definition
node(
func=train_model,
inputs=["input_data", "params:model_params:learning_rate"], #this doesn't work
outputs="output_data",
)
Juan Luis
11/26/2023, 12:22 PMparams:model_params.learning_rate
@Gilad Rubin?Juan Luis
11/26/2023, 12:22 PM.
instead of :
in the accessor)Gilad Rubin
11/26/2023, 1:16 PMfmfreeze
12/12/2023, 9:59 PMparams:model_params.learning_rate
is not showing up properly in kedro viz.
Is that on purpose?