Skip to content

StructuredDataRegressor

[source]

StructuredDataRegressor

autokeras.StructuredDataRegressor(
    column_names=None,
    column_types=None,
    output_dim=None,
    loss="mean_squared_error",
    metrics=None,
    project_name="structured_data_regressor",
    max_trials=100,
    directory=None,
    objective="val_loss",
    tuner=None,
    overwrite=False,
    seed=None,
    max_model_size=None,
    **kwargs
)

AutoKeras structured data regression class.

Arguments

  • column_names Optional[List[str]]: A list of strings specifying the names of the columns. The length of the list should be equal to the number of columns of the data excluding the target column. Defaults to None. If None, it will obtained from the header of the csv file or the pandas.DataFrame.
  • column_types Optional[Dict[str, str]]: Dict. The keys are the column names. The values should either be 'numerical' or 'categorical', indicating the type of that column. Defaults to None. If not None, the column_names need to be specified. If None, it will be inferred from the data.
  • output_dim Optional[int]: Int. The number of output dimensions. Defaults to None. If None, it will be inferred from the data.
  • loss Union[str, Callable, tensorflow.keras.losses.Loss]: A Keras loss function. Defaults to use 'mean_squared_error'.
  • metrics Union[List[Union[str, Callable, tensorflow.keras.metrics.Metric]], List[List[Union[str, Callable, tensorflow.keras.metrics.Metric]]], Dict[str, Union[str, Callable, tensorflow.keras.metrics.Metric]], None]: A list of Keras metrics. Defaults to use 'mean_squared_error'.
  • project_name str: String. The name of the AutoModel. Defaults to 'structured_data_regressor'.
  • max_trials int: Int. The maximum number of different Keras Models to try. The search may finish before reaching the max_trials. Defaults to 100.
  • directory Union[str, pathlib.Path, None]: String. The path to a directory for storing the search outputs. Defaults to None, which would create a folder with the name of the AutoModel in the current directory.
  • objective str: String. Name of model metric to minimize or maximize, e.g. 'val_accuracy'. Defaults to 'val_loss'.
  • tuner Union[str, Type[autokeras.engine.tuner.AutoTuner]]: String or subclass of AutoTuner. If string, it should be one of 'greedy', 'bayesian', 'hyperband' or 'random'. It can also be a subclass of AutoTuner. If left unspecified, it uses a task specific tuner, which first evaluates the most commonly used models for the task before exploring other models.
  • overwrite bool: Boolean. Defaults to False. If False, reloads an existing project of the same name if one is found. Otherwise, overwrites the project.
  • seed Optional[int]: Int. Random seed.
  • max_model_size Optional[int]: Int. Maximum number of scalars in the parameters of a model. Models larger than this are rejected.
  • **kwargs: Any arguments supported by AutoModel.

[source]

fit

StructuredDataRegressor.fit(
    x=None, y=None, epochs=None, callbacks=None, validation_split=0.2, validation_data=None, **kwargs
)

Search for the best model and hyperparameters for the task.

Arguments

  • x: String, numpy.ndarray, pandas.DataFrame or tensorflow.Dataset. Training data x. If the data is from a csv file, it should be a string specifying the path of the csv file of the training data.
  • y: String, numpy.ndarray, or tensorflow.Dataset. Training data y. If the data is from a csv file, it should be a string, which is the name of the target column. Otherwise, it can be single-column or multi-column. The values should all be numerical.
  • epochs: Int. The number of epochs to train each model during the search. If unspecified, we would use epochs equal to 1000 and early stopping with patience equal to 30.
  • callbacks: List of Keras callbacks to apply during training and validation.
  • validation_split: Float between 0 and 1. Defaults to 0.2. Fraction of the training data to be used as validation data. The model will set apart this fraction of the training data, will not train on it, and will evaluate the loss and any model metrics on this data at the end of each epoch. The validation data is selected from the last samples in the x and y data provided, before shuffling. This argument is not supported when x is a dataset. The best model found would be fit on the entire dataset including the validation data.
  • validation_data: Data on which to evaluate the loss and any model metrics at the end of each epoch. The model will not be trained on this data. validation_data will override validation_split. The type of the validation data should be the same as the training data. The best model found would be fit on the training dataset without the validation data.
  • **kwargs: Any arguments supported by keras.Model.fit.

[source]

predict

StructuredDataRegressor.predict(x, **kwargs)

Predict the output for a given testing data.

Arguments

  • x: String, numpy.ndarray, pandas.DataFrame or tensorflow.Dataset. Testing data x. If the data is from a csv file, it should be a string specifying the path of the csv file of the testing data.
  • **kwargs: Any arguments supported by keras.Model.predict.

Returns

A list of numpy.ndarray objects or a single numpy.ndarray. The predicted results.


[source]

evaluate

StructuredDataRegressor.evaluate(x, y=None, **kwargs)

Evaluate the best model for the given data.

Arguments

  • x: String, numpy.ndarray, pandas.DataFrame or tensorflow.Dataset. Testing data x. If the data is from a csv file, it should be a string specifying the path of the csv file of the testing data.
  • y: String, numpy.ndarray, or tensorflow.Dataset. Testing data y. If the data is from a csv file, it should be a string corresponding to the label column.
  • **kwargs: Any arguments supported by keras.Model.evaluate.

Returns

Scalar test loss (if the model has a single output and no metrics) or list of scalars (if the model has multiple outputs and/or metrics). The attribute model.metrics_names will give you the display labels for the scalar outputs.


[source]

export_model

StructuredDataRegressor.export_model()

Export the best Keras Model.

Returns

tf.keras.Model instance. The best model found during the search, loaded with trained weights.