

# Tune a Factorization Machines Model
<a name="fm-tuning"></a>

*Automatic model tuning*, also known as hyperparameter tuning, finds the best version of a model by running many jobs that test a range of hyperparameters on your dataset. You choose the tunable hyperparameters, a range of values for each, and an objective metric. You choose the objective metric from the metrics that the algorithm computes. Automatic model tuning searches the hyperparameters chosen to find the combination of values that result in the model that optimizes the objective metric.

For more information about model tuning, see [Automatic model tuning with SageMaker AI](automatic-model-tuning.md).

## Metrics Computed by the Factorization Machines Algorithm
<a name="fm-metrics"></a>

The Factorization Machines algorithm has both binary classification and regression predictor types. The predictor type determines which metric you can use for automatic model tuning. The algorithm reports a `test:rmse` regressor metric, which is computed during training. When tuning the model for regression tasks, choose this metric as the objective.


| Metric Name | Description | Optimization Direction | 
| --- | --- | --- | 
| test:rmse | Root Mean Square Error | Minimize | 

The Factorization Machines algorithm reports three binary classification metrics, which are computed during training. When tuning the model for binary classification tasks, choose one of these as the objective.


| Metric Name | Description | Optimization Direction | 
| --- | --- | --- | 
| test:binary\$1classification\$1accuracy | Accuracy | Maximize | 
| test:binary\$1classification\$1cross\$1entropy | Cross Entropy | Minimize | 
| test:binary\$1f\$1beta | Beta | Maximize | 

## Tunable Factorization Machines Hyperparameters
<a name="fm-tunable-hyperparameters"></a>

You can tune the following hyperparameters for the Factorization Machines algorithm. The initialization parameters that contain the terms bias, linear, and factorization depend on their initialization method. There are three initialization methods: `uniform`, `normal`, and `constant`. These initialization methods are not themselves tunable. The parameters that are tunable are dependent on this choice of the initialization method. For example, if the initialization method is `uniform`, then only the `scale` parameters are tunable. Specifically, if `bias_init_method==uniform`, then `bias_init_scale`, `linear_init_scale`, and `factors_init_scale` are tunable. Similarly, if the initialization method is `normal`, then only `sigma` parameters are tunable. If the initialization method is `constant`, then only `value` parameters are tunable. These dependencies are listed in the following table. 


| Parameter Name | Parameter Type | Recommended Ranges | Dependency | 
| --- | --- | --- | --- | 
| bias\$1init\$1scale | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==uniform | 
| bias\$1init\$1sigma | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==normal | 
| bias\$1init\$1value | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==constant | 
| bias\$1lr | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | None | 
| bias\$1wd | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | None | 
| epoch | IntegerParameterRange | MinValue: 1, MaxValue: 1000 | None | 
| factors\$1init\$1scale | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==uniform | 
| factors\$1init\$1sigma | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==normal | 
| factors\$1init\$1value | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==constant | 
| factors\$1lr | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | None | 
| factors\$1wd | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512] | None | 
| linear\$1init\$1scale | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==uniform | 
| linear\$1init\$1sigma | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==normal | 
| linear\$1init\$1value | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | bias\$1init\$1method==constant | 
| linear\$1lr | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | None | 
| linear\$1wd | ContinuousParameterRange | MinValue: 1e-8, MaxValue: 512 | None | 
| mini\$1batch\$1size | IntegerParameterRange | MinValue: 100, MaxValue: 10000 | None | 