# tf.keras.wrappers.scikit_learn.KerasRegressor

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/keras/wrappers/scikit_learn/KerasRegressor) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L314-L355) |

Implementation of the scikit-learn regressor API for Keras.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.wrappers.scikit_learn.KerasRegressor`](https://www.tensorflow.org/api_docs/python/tf/keras/wrappers/scikit_learn/KerasRegressor), \`tf.compat.v2.keras.wrappers.scikit_learn.KerasRegressor\`

<br />

    tf.keras.wrappers.scikit_learn.KerasRegressor(
        build_fn=None, **sk_params
    )

## Methods

### `check_params`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L79-L106)

    check_params(
        params
    )

Checks for user typos in `params`.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `params` | dictionary; the parameters to be checked |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | if any member of `params` is not a valid argument. |

<br />

### `filter_sk_params`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L170-L187)

    filter_sk_params(
        fn, override=None
    )

Filters `sk_params` and returns those in `fn`'s arguments.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `fn` | arbitrary function |
| `override` | dictionary, values to override `sk_params` |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `res` | dictionary containing variables in both `sk_params` and `fn`'s arguments. |

<br />

### `fit`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L134-L168)

    fit(
        x, y, **kwargs
    )

Constructs a new model with `build_fn` \& fit the model to `(x, y)`.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `x` | array-like, shape `(n_samples, n_features)` Training samples where `n_samples` is the number of samples and `n_features` is the number of features. |
| `y` | array-like, shape `(n_samples,)` or `(n_samples, n_outputs)` True labels for `x`. |
| `**kwargs` | dictionary arguments Legal arguments are the arguments of [`Sequential.fit`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/Model#fit) |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `history` | object details about the training history at each epoch. |

<br />

### `get_params`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L108-L119)

    get_params(
        **params
    )

Gets parameters for this estimator.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `**params` | ignored (exists for API compatibility). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Dictionary of parameter names mapped to their values. ||

<br />

### `predict`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L318-L333)

    predict(
        x, **kwargs
    )

Returns predictions for the given test data.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `x` | array-like, shape `(n_samples, n_features)` Test samples where `n_samples` is the number of samples and `n_features` is the number of features. |
| `**kwargs` | dictionary arguments Legal arguments are the arguments of [`Sequential.predict`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/Model#predict). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `preds` | array-like, shape `(n_samples,)` Predictions. |

<br />

### `score`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L335-L355)

    score(
        x, y, **kwargs
    )

Returns the mean loss on the given test data and labels.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `x` | array-like, shape `(n_samples, n_features)` Test samples where `n_samples` is the number of samples and `n_features` is the number of features. |
| `y` | array-like, shape `(n_samples,)` True labels for `x`. |
| `**kwargs` | dictionary arguments Legal arguments are the arguments of [`Sequential.evaluate`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/Model#evaluate). |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `score` | float Mean accuracy of predictions on `x` wrt. `y`. |

<br />

### `set_params`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/wrappers/scikit_learn.py#L121-L132)

    set_params(
        **params
    )

Sets the parameters of this estimator.

<br />

<br />

<br />

| Arguments ||
|---|---|
| `**params` | Dictionary of parameter names mapped to their values. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| self ||

<br />