Session Ready
Exercise

Argparse main()

Next, we'll create a __main__.py file to pass shell arguments to classify() or regress(), functions based on code we wrote in Chapter 1.

We will provide default values for all arguments, so that the code can run even if no shell arguments are provided.

To do this, we'll instantiate the ArgumentParser class from the argparse module as parser and use its add_argument() method to create arguments called dataset and model with the following defaults: diabetes and linear_model.Ridge.

Setting nargs to ? means that each argument can accept either one value or none at all.

We will create a keyword arguments (kwargs) variable and unpack kwargs into the classify() or regress() functions in the main() function's return statement.

Instructions
100 XP
  • Set the default for the dataset argument of the main() function.
  • Use args and the built-in dict function to create a dictionary called kwargs, which contains the two shell arguments.