Use cognitive services in order to predict the number of Sales per article per Account using data from Business Central

by | Sep 16, 2022

Predicting the number of sales per article per account can be a valuable task for businesses looking to improve their sales forecasting and better understand their customers’ behavior. With the help of Azure Cognitive Services, it is possible to build a predictive model that uses data from Business Central to predict the number of sales per article per account. Here are the steps to do this:

  1. Set up an Azure Cognitive Services account To use Azure Cognitive Services, you need to set up an account on the Azure portal. Once you have set up the account, you can access various APIs, including the Machine Learning API, which can be used for building predictive models.
  1. Prepare the data To build a predictive model, you need to prepare the data that you will use to train the model. In this case, you will need data from Business Central that includes the number of sales per article per account. You can extract this data from Business Central using the APIs provided by the application.
  1. Train the model Once you have prepared the data, you can use the Azure Machine Learning API to train the predictive model. This involves selecting the appropriate features (such as account, article, date, etc.), selecting a model type (such as regression, decision tree, or neural network), and tuning the model parameters (such as learning rate, regularization, or depth).
  1. Evaluate the model After training the model, you need to evaluate its performance on a test set of data. This involves comparing the predicted values to the actual values and calculating metrics such as mean squared error or R-squared.
  1. Deploy the model Once you have evaluated the model and are satisfied with its performance, you can deploy it to a production environment. This involves creating an API that allows you to send new data to the model and receive predictions in real-time.

Here’s an example code using Python and the Azure Machine Learning API to build a predictive model for sales per article per account:

import pandas as pd

import requests

from azureml.core import Workspace

from azureml.core.webservice import AciWebservice

from azureml.core.model import Model

from azureml.core.authentication import ServicePrincipalAuthentication

# Define the Business Central API endpoints

bc_endpoint = ‘<YOUR_BUSINESS_CENTRAL_API_ENDPOINT>’

bc_key = ‘<YOUR_BUSINESS_CENTRAL_API_KEY>’

headers = {‘Authorization’: f’Bearer {bc_key}’}

# Define the Azure Machine Learning workspace

svc_pr = ServicePrincipalAuthentication(

    tenant_id='<YOUR_AZURE_TENANT_ID>’,

    service_principal_id='<YOUR_AZURE_SP_ID>’,

    service_principal_password='<YOUR_AZURE_SP_PASSWORD>’

)

ws = Workspace(

    subscription_id='<YOUR_AZURE_SUBSCRIPTION_ID>’,

    resource_group='<YOUR_AZURE_RESOURCE_GROUP>’,

    workspace_name='<YOUR_AZURE_WORKSPACE_NAME>’,

    auth=svc_pr

)

# Extract data from Business Central

data = []

response = requests.get(f'{bc_endpoint}/sales’, headers=headers)

for sale in response.json():

    data.append({

        ‘Account’: sale[‘Account’],

        ‘Article’: sale[‘Article’],

        ‘Quantity’: sale[‘Quantity’],

        ‘Date’: sale[‘Date’]

    })

df = pd.DataFrame(data)

# Train the predictive model

from azureml.core.experiment import Experiment

from azureml.train.automl import AutoMLConfig

automl_config = AutoMLConfig(

    task=’regression’,

    training_data=df,

    label_column_name=’Quantity’,

    iterations=10,

    max_concurrent_iterations=4

)

experiment = Experiment(ws, ‘sales-prediction’)

run = experiment.submit(automl_config)

run.wait_for_completion(show_output=True)

# Evaluate the model

best_run, fitted_model = run