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:
- Export predictions from Azure ML to Azure SQL Database.
- Connect Power BI to Azure ML outputs.
- 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
- Open Power BI Desktop.
- Go to Home > Get Data > SQL Server.
- 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.
- Server:
- 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:
- Bar Chart: Visualize churn rates by customer demographics (e.g., age group, contract type).
- Heatmap: Display churn probability across different customer segments.
- 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
- Publish the Power BI report to the Power BI Service:
- Go to File > Publish > Publish to Power BI.
- Share the dashboard with stakeholders:
- Navigate to the Power BI workspace.
- Select the report and click Share.
- 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.