0
0
ML Pythonml~10 mins

Documentation best practices in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a clear description to the machine learning model function.

ML Python
def train_model(data):
    """[1]"""
    # training steps here
    pass
Drag options to blanks, or click blank then click option'
ATrain a model using the given data
BCalculate the accuracy of the model
CLoad the dataset from file
DPlot the training loss graph
Attempts:
3 left
💡 Hint
Common Mistakes
Writing unrelated descriptions like plotting or loading data
Leaving the docstring empty
2fill in blank
medium

Complete the code to add parameter documentation for the input data.

ML Python
def train_model(data):
    """
    Train a model.

    Parameters:
        data: [1]
    """
    pass
Drag options to blanks, or click blank then click option'
Alist of numbers
Bplotting function
Cmodel accuracy score
Dinput dataset for training
Attempts:
3 left
💡 Hint
Common Mistakes
Describing output or unrelated items
Using vague terms like 'list of numbers' without context
3fill in blank
hard

Fix the error in the docstring to correctly document the return value of the function.

ML Python
def train_model(data):
    """
    Train a model.

    Returns:
        [1]: trained model object
    """
    pass
Drag options to blanks, or click blank then click option'
Aaccuracy
Bloss
Cmodel
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using metric names like accuracy or loss instead of the model
Using input parameter names as return values
4fill in blank
hard

Fill both blanks to complete the example section in the docstring.

ML Python
def train_model(data):
    """
    Train a model.

    Example:
        model = train_model([1])
        print(model.[2]())
    """
    pass
Drag options to blanks, or click blank then click option'
Atraining_data
Bscore
Cpredict
Dtest_data
Attempts:
3 left
💡 Hint
Common Mistakes
Using test data as input in the example
Using metric methods like 'score' instead of 'predict' in example
5fill in blank
hard

Fill all three blanks to complete the docstring with description, parameters, and returns.

ML Python
def evaluate_model(model, test_data):
    """
    [1].

    Parameters:
        model: [2]
        test_data: [3]

    Returns:
        float: accuracy score
    """
    pass
Drag options to blanks, or click blank then click option'
AEvaluate the model on test data
Ba trained machine learning model
Cdataset used for testing the model
DTrain the model with data
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing training and evaluation descriptions
Using vague parameter descriptions