Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add snippets for visualizing a time series and creating a time series model for the Limit forecasted values in time series model tutorial #1310

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (t
# you may not use this file except in compliance wi
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in
# distributed under the License is distributed on a
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, eit
# See the License for the specific language governi
# limitations under the License.


def test_limit_single_timeseries(random_model_id: str) -> None:
your_model_id = random_model_id

# [START bigquery_dataframes_bqml_limit_forecast_visualize]
import bigframes.pandas as bpd

df = bpd.read_gbq("bigquery-public-data.new_york.citibike_trips")

features = bpd.DataFrame(
{
"num_trips": df.starttime,
"date": df["starttime"].dt.date,
}
)
date = df["starttime"].dt.date
df.groupby([date])
num_trips = features.groupby(["date"]).count()
# [END bigquery_dataframes_bqml_limit_forecast_visualize]

# [START bigquery_dataframes_bqml_limit_forecast_create]
from bigframes.ml import forecasting
import bigframes.pandas as bpd

df = bpd.read_gbq("bigquery-public-data.new_york.citibike_trips")

features = bpd.DataFrame(
{
"num_trips": df.starttime,
"date": df["starttime"].dt.date,
}
)
num_trips = features.groupby(["date"], as_index=False).count()
model = forecasting.ARIMAPlus()

X = num_trips["date"].to_frame()
y = num_trips["num_trips"].to_frame()

model.fit(X, y)

model.to_gbq(
your_model_id, # For example: "bqml_tutorial.nyc_citibike_arima_model",
replace=True,
)
# [END bigquery_dataframes_bqml_limit_forecast_create
assert df is not None
assert features is not None
assert num_trips is not None
Loading