Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bigframes/ml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ def fit(
) -> _T:
return self._fit(X, y)

def fit_predict(
self: _T,
X: utils.ArrayType,
y: Optional[utils.ArrayType] = None,
) -> _T:
return self.fit(X).predict(X)


class RetriableRemotePredictor(BaseEstimator):
def _predict_and_retry(
Expand Down
4 changes: 2 additions & 2 deletions notebooks/generative_ai/bq_dataframes_llm_kmeans.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv (3.10.14)",
"language": "python",
"name": "python3"
},
Expand All @@ -1750,7 +1750,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
20 changes: 20 additions & 0 deletions third_party/bigframes_vendored/sklearn/cluster/_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ def predict(
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def fit_predict(
self,
X,
y=None,
):
"""Compute cluster centers and predict cluster index for each sample.

Convenience method; equivalent to calling fit(X) followed by predict(X).

Args:
X (bigframes.dataframe.DataFrame or bigframes.series.Series or pandas.core.frame.DataFrame or pandas.core.series.Series):
DataFrame of shape (n_samples, n_features). Training data.
y (default None):
Not used, present here for API consistency by convention.

Returns:
bigframes.dataframe.DataFrame: DataFrame of shape (n_samples, n_input_columns + n_prediction_columns). Returns predicted labels.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def score(
self,
X,
Expand Down
20 changes: 20 additions & 0 deletions third_party/bigframes_vendored/sklearn/decomposition/_mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,23 @@ def predict(self, X):
Returns:
bigframes.dataframe.DataFrame: Predicted DataFrames."""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def fit_predict(
self,
X,
y=None,
):
"""Fit the model with X and generate a predicted rating for every user-item row combination for a matrix factorization model. on X.

Convenience method; equivalent to calling fit(X) followed by predict(X).

Args:
X (bigframes.dataframe.DataFrame or bigframes.series.Series or pandas.core.frame.DataFrame or pandas.core.series.Series):
DataFrame of shape (n_samples, n_features). Training data.
y (default None):
Not used, present here for API consistency by convention.

Returns:
bigframes.dataframe.DataFrame: DataFrame of shape (n_samples, n_input_columns + n_prediction_columns). Returns predicted labels.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
20 changes: 20 additions & 0 deletions third_party/bigframes_vendored/sklearn/decomposition/_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ def predict(self, X):
bigframes.dataframe.DataFrame: Predicted DataFrames."""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def fit_predict(
self,
X,
y=None,
):
"""Fit the model with X and apply the dimensionality reduction on X.

Convenience method; equivalent to calling fit(X) followed by predict(X).

Args:
X (bigframes.dataframe.DataFrame or bigframes.series.Series or pandas.core.frame.DataFrame or pandas.core.series.Series):
DataFrame of shape (n_samples, n_features). Training data.
y (default None):
Not used, present here for API consistency by convention.

Returns:
bigframes.dataframe.DataFrame: DataFrame of shape (n_samples, n_input_columns + n_prediction_columns). Returns predicted labels.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
def components_(self):
"""Principal axes in feature space, representing the directions of maximum variance in the data.
Expand Down