Skip to content
Visualizing Churn Predictions with Power BI and Azure ML Insights
todd-bernson-leadership

Effective visualization of machine learning predictions is key to making data-driven decisions. Power BI, integrated with Azure Machine Learning (Azure ML) insights, provides an interactive and accessible way to visualize churn predictions and extract actionable insights. This article demonstrates how to:

  1. Export predictions from Azure ML to Azure SQL Database.
  2. Connect Power BI to Azure ML outputs.
  3. Create an interactive dashboard to visualize churn metrics and customer insights.

Step 1: Exporting Predictions from Azure ML to Azure SQL Database

The first step is to export churn predictions from Azure ML to Azure SQL Database, where Power BI can access the data.

Configure Azure SQL Database with Terraform

Here’s a Terraform configuration to set up an Azure SQL Database:

resource "azurerm_sql_server" "sql_server" {
  name                         = "ml-churn-sql-server"
  resource_group_name          = azurerm_resource_group.this.name
  location                     = azurerm_resource_group.this.location
  version                      = "12.0"
  administrator_login          = "adminuser"
  administrator_login_password = "P@ssword01!"

  tags = var.tags
}

resource "azurerm_sql_database" "churn_db" {
  name                = "churn_predictions_db"
  resource_group_name = azurerm_resource_group.this.name
  location            = azurerm_resource_group.this.location
  server_name         = azurerm_sql_server.sql_server.name
  requested_service_objective_name = "S0"

  tags = var.tags
}

Export Predictions from Azure ML

Use the Azure ML SDK to write model predictions to Azure SQL Database:

from azureml.core import Workspace, Dataset
import pyodbc

# Connect to Azure ML Workspace
ws = Workspace.from_config()

# Load predictions from the experiment
dataset = Dataset.get_by_name(ws, "churn_predictions")
predictions_df = dataset.to_pandas_dataframe()

# Connect to Azure SQL Database
conn = pyodbc.connect(
    "DRIVER={ODBC Driver 17 for SQL Server};"
    "SERVER=ml-churn-sql-server.database.windows.net;"
    "DATABASE=churn_predictions_db;"
    "UID=adminuser;"
    "PWD=P@ssword01!"
)

# Write predictions to SQL
cursor = conn.cursor()
for index, row in predictions_df.iterrows():
    cursor.execute("""
        INSERT INTO churn_predictions (customer_id, churn_probability, predicted_class)
        VALUES (?, ?, ?)
    """, row["customer_id"], row["churn_probability"], row["predicted_class"])
conn.commit()
cursor.close()
conn.close()

Step 2: Connecting Power BI to Azure ML Outputs

  1. Open Power BI Desktop.
  2. Go to Home > Get Data > SQL Server.
  3. Enter your Azure SQL Server name and database credentials:
    • Server: ml-churn-sql-server.database.windows.net
    • Database: churn_predictions_db
    • Authentication Method: SQL Server Authentication.
  4. Select the churn_predictions table and load the data.

Step 3: Designing a Dashboard with Churn Metrics and Customer Insights

With the churn predictions data loaded into Power BI, you can design an interactive dashboard.

Metrics to Include:

  • Churn Probability: Average churn probability by customer segment.
  • Predicted Churn Rate: Percentage of customers predicted to churn.
  • Customer Insights: Churn predictions segmented by demographics or service usage.

Visualizations:

  1. Bar Chart: Visualize churn rates by customer demographics (e.g., age group, contract type).
  2. Heatmap: Display churn probability across different customer segments.
  3. KPI Cards: Highlight key metrics like average churn probability and total predicted churn.

Example DAX Measures:

Create a measure for the churn rate:

Churn Rate = 
DIVIDE(
    COUNTROWS(FILTER(churn_predictions, churn_predictions[predicted_class] = 1)),
    COUNTROWS(churn_predictions)
)

Step 4: Publishing and Sharing the Dashboard

  1. Publish the Power BI report to the Power BI Service:
    • Go to File > Publish > Publish to Power BI.
  2. Share the dashboard with stakeholders:
    • Navigate to the Power BI workspace.
    • Select the report and click Share.
  3. Set up scheduled refresh to keep the dashboard updated:
    • Go to Dataset > Schedule Refresh and configure credentials for the Azure SQL Database.

Key Takeaway

By integrating Azure ML insights with Power BI, businesses can create interactive dashboards that make churn predictions actionable. From real-time updates to detailed segment analysis, this approach empowers stakeholders to make informed decisions and improve customer retention strategies.

Related Articles

Inter-Region WireGuard VPN in AWS

Read more

Making PDFs Searchable Using AWS Textract and CloudSearch

Read more

Slack AI Bot with AWS Bedrock Part 2

Read more

Contact Us

Achieve a competitive advantage through BSC data analytics and cloud solutions.

Contact Us