Skip to content

create_ml_model

create_ml_model(
    ml_model_id: EntityId,
    ml_model_type: MLModelType,
    training_data_source_id: EntityId,
    *,
    config_overrides: Optional[MachineLearningClientConfig] = None,
    ml_model_name: Optional[EntityName] = None,
    parameters: Optional[TrainingParameters] = None,
    recipe: Optional[Recipe] = None,
    recipe_uri: Optional[S3Url] = None,
) -> CreateMLModelOutput

Creates a new MLModel using the DataSource and the recipe as information sources.

An MLModel is nearly immutable. Users can update only the MLModelName and the ScoreThreshold in an MLModel without creating a new MLModel.

CreateMLModel is an asynchronous operation. In response to CreateMLModel, Amazon Machine Learning (Amazon ML) immediately returns and sets the MLModel status to PENDING. After the MLModel has been created and ready is for use, Amazon ML sets the status to COMPLETED.

You can use the GetMLModel operation to check the progress of the MLModel during the creation operation.

CreateMLModel requires a DataSource with computed statistics, which can be created by setting ComputeStatistics to true in CreateDataSourceFromRDS, CreateDataSourceFromS3, or CreateDataSourceFromRedshift operations.

Parameters:

  • ml_model_id (EntityId) –

    A user-supplied ID that uniquely identifies the MLModel.

  • ml_model_name (Optional[EntityName], default: None ) –

    A user-supplied name or description of the MLModel.

  • ml_model_type (MLModelType) –

    The category of supervised learning that this MLModel will address. Choose from the following types:

    • Choose REGRESSION if the MLModel will be used to predict a numeric value.

    • Choose BINARY if the MLModel result has two possible values.

    • Choose MULTICLASS if the MLModel result has a limited number of values.

    For more information, see the Amazon Machine Learning Developer Guide.

  • parameters (Optional[TrainingParameters], default: None ) –

    A list of the training parameters in the MLModel. The list is implemented as a map of key-value pairs.

    The following is the current set of training parameters:

    • sgd.maxMLModelSizeInBytes - The maximum allowed size of the model. Depending on the input data, the size of the model might affect its performance.

      The value is an integer that ranges from 100000 to 2147483648. The default value is 33554432.

    • sgd.maxPasses - The number of times that the training process traverses the observations to build the MLModel. The value is an integer that ranges from 1 to 10000. The default value is 10.

    • sgd.shuffleType - Whether Amazon ML shuffles the training data. Shuffling the data improves a model's ability to find the optimal solution for a variety of data types. The valid values are auto and none. The default value is none. We strongly recommend that you shuffle your data.

    • sgd.l1RegularizationAmount - The coefficient regularization L1 norm. It controls overfitting the data by penalizing large coefficients. This tends to drive coefficients to zero, resulting in a sparse feature set. If you use this parameter, start by specifying a small value, such as 1.0E-08.

      The value is a double that ranges from 0 to MAX_DOUBLE. The default is to not use L1 normalization. This parameter can't be used when L2 is specified. Use this parameter sparingly.

    • sgd.l2RegularizationAmount - The coefficient regularization L2 norm. It controls overfitting the data by penalizing large coefficients. This tends to drive coefficients to small, nonzero values. If you use this parameter, start by specifying a small value, such as 1.0E-08.

      The value is a double that ranges from 0 to MAX_DOUBLE. The default is to not use L2 normalization. This parameter can't be used when L1 is specified. Use this parameter sparingly.

  • training_data_source_id (EntityId) –

    The DataSource that points to the training data.

  • recipe (Optional[Recipe], default: None ) –

    The data recipe for creating the MLModel. You must specify either the recipe or its URI. If you don't specify a recipe or its URI, Amazon ML creates a default.

  • recipe_uri (Optional[S3Url], default: None ) –

    The Amazon Simple Storage Service (Amazon S3) location and file name that contains the MLModel recipe. You must specify either the recipe or its URI. If you don't specify a recipe or its URI, Amazon ML creates a default.

Raises:

  • IdempotentParameterMismatchException –

    A second request to use or change an object was not allowed. This can result from retrying a request using a parameter that was not present in the original request.

  • InternalServerException –

    An error on the server occurred when trying to process a request.

  • InvalidInputException –

    An error on the client occurred. Typically, the cause is an invalid input value.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_machine_learning/_services/machine_learning.py
def create_ml_model(
    self,
    ml_model_id: "capo_machine_learning.types.entity_id.EntityId",
    ml_model_type: "capo_machine_learning.types.ml_model_type.MLModelType",
    training_data_source_id: "capo_machine_learning.types.entity_id.EntityId",
    *,
    config_overrides: Optional[MachineLearningClientConfig] = None,
    ml_model_name: Optional[
        "capo_machine_learning.types.entity_name.EntityName"
    ] = None,
    parameters: Optional[
        "capo_machine_learning.types.training_parameters.TrainingParameters"
    ] = None,
    recipe: Optional["capo_machine_learning.types.recipe.Recipe"] = None,
    recipe_uri: Optional["capo_machine_learning.types.s3_url.S3Url"] = None,
) -> "capo_machine_learning.types.create_ml_model_output.CreateMLModelOutput":
    """<p>Creates a new <code>MLModel</code> using the <code>DataSource</code> and the recipe as information sources. </p> <p>An <code>MLModel</code> is nearly immutable. Users can update only the <code>MLModelName</code> and the <code>ScoreThreshold</code> in an <code>MLModel</code> without creating a new <code>MLModel</code>. </p> <p> <code>CreateMLModel</code> is an asynchronous operation. In response to <code>CreateMLModel</code>, Amazon Machine Learning (Amazon ML) immediately returns and sets the <code>MLModel</code> status to <code>PENDING</code>. After the <code>MLModel</code> has been created and ready is for use, Amazon ML sets the status to <code>COMPLETED</code>. </p> <p>You can use the <code>GetMLModel</code> operation to check the progress of the <code>MLModel</code> during the creation operation.</p> <p> <code>CreateMLModel</code> requires a <code>DataSource</code> with computed statistics, which can be created by setting <code>ComputeStatistics</code> to <code>true</code> in <code>CreateDataSourceFromRDS</code>, <code>CreateDataSourceFromS3</code>, or <code>CreateDataSourceFromRedshift</code> operations. </p>

    Args:
        ml_model_id: <p>A user-supplied ID that uniquely identifies the <code>MLModel</code>.</p>
        ml_model_name: <p>A user-supplied name or description of the <code>MLModel</code>.</p>
        ml_model_type: <p>The category of supervised learning that this <code>MLModel</code> will address. Choose from the following types:</p> <ul> <li> <p>Choose <code>REGRESSION</code> if the <code>MLModel</code> will be used to predict a numeric value.</p> </li> <li> <p>Choose <code>BINARY</code> if the <code>MLModel</code> result has two possible values.</p> </li> <li> <p>Choose <code>MULTICLASS</code> if the <code>MLModel</code> result has a limited number of values.</p> </li> </ul> <p> For more information, see the <a href="https://docs.aws.amazon.com/machine-learning/latest/dg">Amazon Machine Learning Developer Guide</a>.</p>
        parameters: <p>A list of the training parameters in the <code>MLModel</code>. The list is implemented as a map of key-value pairs.</p> <p>The following is the current set of training parameters:</p> <ul> <li> <p> <code>sgd.maxMLModelSizeInBytes</code> - The maximum allowed size of the model. Depending on the input data, the size of the model might affect its performance.</p> <p> The value is an integer that ranges from <code>100000</code> to <code>2147483648</code>. The default value is <code>33554432</code>.</p> </li> <li> <p> <code>sgd.maxPasses</code> - The number of times that the training process traverses the observations to build the <code>MLModel</code>. The value is an integer that ranges from <code>1</code> to <code>10000</code>. The default value is <code>10</code>.</p> </li> <li> <p> <code>sgd.shuffleType</code> - Whether Amazon ML shuffles the training data. Shuffling the data improves a model's ability to find the optimal solution for a variety of data types. The valid values are <code>auto</code> and <code>none</code>. The default value is <code>none</code>. We strongly recommend that you shuffle your data.</p> </li> <li> <p> <code>sgd.l1RegularizationAmount</code> - The coefficient regularization L1 norm. It controls overfitting the data by penalizing large coefficients. This tends to drive coefficients to zero, resulting in a sparse feature set. If you use this parameter, start by specifying a small value, such as <code>1.0E-08</code>.</p> <p>The value is a double that ranges from <code>0</code> to <code>MAX_DOUBLE</code>. The default is to not use L1 normalization. This parameter can't be used when <code>L2</code> is specified. Use this parameter sparingly.</p> </li> <li> <p> <code>sgd.l2RegularizationAmount</code> - The coefficient regularization L2 norm. It controls overfitting the data by penalizing large coefficients. This tends to drive coefficients to small, nonzero values. If you use this parameter, start by specifying a small value, such as <code>1.0E-08</code>.</p> <p>The value is a double that ranges from <code>0</code> to <code>MAX_DOUBLE</code>. The default is to not use L2 normalization. This parameter can't be used when <code>L1</code> is specified. Use this parameter sparingly.</p> </li> </ul>
        training_data_source_id: <p>The <code>DataSource</code> that points to the training data.</p>
        recipe: <p>The data recipe for creating the <code>MLModel</code>. You must specify either the recipe or its URI. If you don't specify a recipe or its URI, Amazon ML creates a default.</p>
        recipe_uri: <p>The Amazon Simple Storage Service (Amazon S3) location and file name that contains the <code>MLModel</code> recipe. You must specify either the recipe or its URI. If you don't specify a recipe or its URI, Amazon ML creates a default.</p>

    Raises:
        capo_machine_learning.errors.idempotent_parameter_mismatch_exception.IdempotentParameterMismatchException: <p>A second request to use or change an object was not allowed. This can result from retrying a request using a parameter that was not present in the original request.</p>
        capo_machine_learning.errors.internal_server_exception.InternalServerException: <p>An error on the server occurred when trying to process a request.</p>
        capo_machine_learning.errors.invalid_input_exception.InvalidInputException: <p>An error on the client occurred. Typically, the cause is an invalid input value.</p>
        capo_machine_learning.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_machine_learning.types.create_ml_model_input.CreateMLModelInput]",
    ) -> OperationResponse[
        "capo_machine_learning.types.create_ml_model_output.CreateMLModelOutput"
    ]:
        import capo_machine_learning._operations.amazon_ml_20141212.create_ml_model

        output, http_response = (
            capo_machine_learning._operations.amazon_ml_20141212.create_ml_model.create_ml_model(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateMLModel")
    )
    input_: capo_machine_learning.types.create_ml_model_input.CreateMLModelInput = {
        "ml_model_id": ml_model_id,
        "ml_model_type": ml_model_type,
        "training_data_source_id": training_data_source_id,
    }
    if ml_model_name is not None:
        input_["ml_model_name"] = ml_model_name
    if parameters is not None:
        input_["parameters"] = parameters
    if recipe is not None:
        input_["recipe"] = recipe
    if recipe_uri is not None:
        input_["recipe_uri"] = recipe_uri

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output