The learning objectives of this article is to learn how to:
Abacus allows you to generate and register plots within our UI. Using this method, you can create a custom dashboard that looks like below:
Please note that not all projects allow for a dashboard to be created. “Predictive Modeling” is the essential project type that supports dashboard creation.
Create a project:
from abacusai import ApiClient, ApiException
client = ApiClient()
project_name = 'sales_over_time_test_ak'
project = client.create_project(name=project_name, use_case='PREDICTING')
Create a dashboard:
graph_dashboard = client.create_graph_dashboard(project_id=project.id, name=project_name)
Define a plot function. The example function below takes as an input feature group, aggregates sales by the day of week and promo indicator. The column names can be used as the function arguments as well.
function_name = 'sales_over_time'
def sales_over_time(df):
import plotly.express as px
# bring data into appropriate format
df = df.groupby(['DayOfWeek', 'Promo']).agg({'Sales': sum}).reset_index()
df = df.sort_values(by = ['DayOfWeek', 'Promo'])
# make a plotly animation plot
fig = px.scatter(df, x="DayOfWeek", y="Sales", color = "Promo")
# adjust labels
fig.update_layout(title='Sales variability by Day of Week & Promo')
fig.update_xaxes(title_text='DayOfWeek',title_standoff=0)
return fig
For creating a python function, we need to specify the function variable mappings. They can have literal types and values. FEATURE_GROUP is one of the types and its value points to a table name in the example below.
function_variable_mappings = [{'name': 'df', 'value': 'store_sales_data_test', 'variable_type': 'FEATURE_GROUP', 'is_required': True}]
Register and add the plot to the dashboard
try:
python_function = client.create_python_function(
name=function_name,
function_name=function_name,
source_code=sales_over_time,
function_variable_mappings=function_variable_mappings,
function_type='plotly_fig')
except ApiException as error:
if error.exception == 'AlreadyExistsError':
python_function = client.describe_python_function(name=function_name)
else:
raise error
client.add_graph_to_dashboard(python_function_id=python_function.python_function_id, graph_dashboard_id=graph_dashboard.id, function_variable_mappings=function_variable_mappings, name=function_name)