Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
americast committed Nov 10, 2023
1 parent 9e3ec86 commit eb88e9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/reference/ai/model-forecasting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ EvaDB's default forecast framework is `statsforecast <https://nixtla.github.io/s

.. note::

`Forecasting` function also logs suggestions. Logged information, such as metrics and suggestions, is sent to STDOUT by default. If you wish not to print it, please send `FALSE` as an optional argument while calling the function. Eg. `SELECT Forecast(FALSE);`
`Forecasting` function also logs suggestions. Logged information, such as metrics and suggestions, is sent to STDOUT by default. A figure is also plotted and is saved in a binary format supported by OpenCV in the `plot` column of the output table. It maybe rendered using the `cv2.imdecode` function. If you wish not to obtain the logged information, please send `FALSE` as an optional argument while calling the function. Eg. `SELECT Forecast(FALSE);`


Below is an example query specifying the above parameters:
Expand Down
12 changes: 7 additions & 5 deletions evadb/functions/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def forward(self, data) -> pd.DataFrame:

# Feedback
if len(data) == 0 or list(list(data.iloc[0]))[0] is True:
# Suggestions
## Suggestions
suggestion_list = []
# 1: Flat predictions
if self.library == "statsforecast":
Expand All @@ -102,7 +102,7 @@ def forward(self, data) -> pd.DataFrame:
for suggestion in set(suggestion_list):
log_str += "\nSUGGESTION: " + self.suggestion_dict[suggestion]

# Metrics
## Metrics
if self.rmse is not None:
log_str += "\nMean normalized RMSE: " + str(self.rmse)
if self.hypers is not None:
Expand Down Expand Up @@ -142,7 +142,7 @@ def forward(self, data) -> pd.DataFrame:
plt.legend()
plt.tight_layout()

# convert plt figure to opencv https://copyprogramming.com/howto/convert-matplotlib-figure-to-cv2-image-a-complete-guide-with-examples#converting-matplotlib-figure-to-cv2-image
# convert plt figure to opencv, inspired from https://copyprogramming.com/howto/convert-matplotlib-figure-to-cv2-image-a-complete-guide-with-examples#converting-matplotlib-figure-to-cv2-image
# convert figure to canvas
canvas = plt.get_current_fig_manager().canvas

Expand All @@ -156,13 +156,15 @@ def forward(self, data) -> pd.DataFrame:
# convert image to cv2 format
cv2_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

## Conver to bytes
# Conver to bytes
_, buffer = cv2.imencode(".jpg", cv2_img)
img_bytes = buffer.tobytes()

## Add to dataframe as a plot
# Add to dataframe as a plot
forecast_df["plot"] = [img_bytes] + [None] * (len(forecast_df) - 1)

log_str += "\nA plot has been saved in the 'plot' column of the output table. It maybe rendered using the cv2.imdecode function."

print(log_str)

forecast_df = forecast_df.rename(
Expand Down

0 comments on commit eb88e9b

Please sign in to comment.