<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vivek Gupta on Medium]]></title>
        <description><![CDATA[Stories by Vivek Gupta on Medium]]></description>
        <link>https://medium.com/@vivekgupta.er?source=rss-29ce234151df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GK7JIME1oLFqvfCCy5pVvQ.jpeg</url>
            <title>Stories by Vivek Gupta on Medium</title>
            <link>https://medium.com/@vivekgupta.er?source=rss-29ce234151df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 20:12:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vivekgupta.er/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Databricks and MLflow]]></title>
            <link>https://medium.com/@vivekgupta.er/databricks-and-mlflow-1c6c6a8b3834?source=rss-29ce234151df------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c6c6a8b3834</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Vivek Gupta]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 04:17:00 GMT</pubDate>
            <atom:updated>2023-04-24T04:18:04.114Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure Databricks and MLflow are potent tools that can be used together to streamline the machine learning workflow, from data preparation and model training to model deployment and monitoring. This blog will explore how to use Azure Databricks and MLflow together and provide practical examples to illustrate the integration.</p><p><strong>Data Preparation with Azure Databricks</strong></p><p>Azure Databricks provides a collaborative workspace for data scientists and engineers to process and analyze data at scale. You can use Databricks to load, transform, and clean data before training machine learning models.</p><pre># Load data into Databricks from a data source<br>from pyspark.sql import SparkSession<br><br># Create a Spark session<br>spark = SparkSession.builder.appName(&quot;DataPreparation&quot;).getOrCreate()<br><br># Load data from a CSV file<br>df = spark.read.csv(&quot;dbfs:/mnt/data/data.csv&quot;, header=True, inferSchema=True)<br><br># Perform data transformations<br>df = df.dropna()  # Drop rows with missing values<br>df = df.filter(df[&quot;age&quot;] &gt; 18)  # Filter out records with age less than 18<br>df.show()</pre><p><strong>Model Training with MLflow</strong></p><p>MLflow is an open-source platform for managing the end-to-end machine learning workflow. It provides tools for tracking experiments, packaging code into reproducible runs, and managing models.</p><pre># Train a machine learning model using MLflow in Databricks<br>import mlflow<br>import mlflow.sklearn<br>from sklearn.linear_model import LinearRegression<br><br># Start an MLflow run<br>with mlflow.start_run() as run:<br>    # Train a linear regression model<br>    model = LinearRegression()<br>    model.fit(df.select(&quot;age&quot;, &quot;income&quot;).toPandas())<br><br>    # Log model parameters and metrics to MLflow<br>    mlflow.log_params({&quot;alpha&quot;: 0.5})<br>    mlflow.log_metric(&quot;rmse&quot;, 0.25)<br><br>    # Log the trained model to MLflow<br>    mlflow.sklearn.log_model(model, &quot;model&quot;)</pre><p><strong>Model Deployment with Azure Databricks</strong></p><p>After training the model with MLflow, you can deploy the model to a production environment using Azure Databricks. Databricks provides a scalable and managed platform for running machine learning models in production.</p><pre># Deploy a trained model to Azure Databricks using MLflow<br>import mlflow.azureml<br>from azureml.core import Workspace<br><br># Authenticate with Azure ML workspace<br>ws = Workspace.from_config()<br><br># Deploy the MLflow model to Azure Databricks<br>model_path = &quot;runs:/{run_id}/model&quot;.format(run_id=run.info.run_id)<br>model_uri = mlflow.get_artifact_uri()<br>mlflow.azureml.build_image(model_uri=model_uri, model_path=model_path)<br>image_uri = mlflow.azureml.get_image_uri(ws)<br><br># Deploy the image to an Azure Kubernetes Service (AKS) cluster<br>from azureml.core.webservice import AksWebservice, Webservice<br>from azureml.core.compute import AksCompute<br><br># Connect to an existing AKS cluster<br>aks_target = AksCompute(ws, &quot;my-aks-cluster&quot;)<br><br># Deploy the image to the AKS cluster<br>aks_service_name = &quot;my-aks-service&quot;<br>aks_config = AksWebservice.deploy_configuration()<br>aks_service = Webservice.deploy_from_image(<br>    workspace=ws,<br>    name=aks_service_name,<br>    image=image_uri,<br>    deployment_config=aks_config,<br>    deployment_target=aks_target,<br>)<br>aks_service.wait_for_deployment(show_output=True)</pre><p><strong>Model Monitoring with Azure Databricks</strong></p><p>Once the model is deployed, you can use Azure Databricks to monitor its performance and make necessary updates. Databricks provides tools for monitoring model metrics, visualizing model performance, and triggering model updates.</p><pre># Monitor model performance using Azure Databricks<br>import mlflow.azureml<br><br># Get the AKS service endpoint<br>aks_service = mlflow.azureml.get_deployment_by_name(ws, aks_service_name)<br>aks_service_endpoint = aks_service.scoring_uri<br><br># Call the model endpoint with test data<br>import requests<br>import json<br><br>test_data = {&quot;age&quot;: 30, &quot;income&quot;: 60000}<br>response = requests.post(aks_service_endpoint, json=test_data)<br><br># Extract the prediction from the response<br>prediction = json.loads(response.text)[&quot;prediction&quot;]<br>print(&quot;Prediction: &quot;, prediction)</pre><p><strong>Model Retraining with MLflow</strong></p><p>As new data becomes available, you may need to retrain the machine learning model to keep it up-to-date. MLflow provides functionality to retrain and update the deployed model using the latest data.</p><pre># Retrain the model with new data using MLflow<br>new_data = spark.read.csv(&quot;dbfs:/mnt/data/new_data.csv&quot;, header=True, inferSchema=True)<br><br># Train a new model with the new data<br>new_model = LinearRegression()<br>new_model.fit(new_data.select(&quot;age&quot;, &quot;income&quot;).toPandas())<br><br># Log the new model to MLflow<br>with mlflow.start_run() as run:<br>    mlflow.log_params({&quot;alpha&quot;: 0.6})<br>    mlflow.log_metric(&quot;rmse&quot;, 0.23)<br>    mlflow.sklearn.log_model(new_model, &quot;model&quot;)<br><br># Update the deployed model with the new model<br>mlflow.azureml.update_aks_service_model(ws, aks_service_name, model_path=&quot;runs:/{run_id}/model&quot;.format(run_id=run.info.run_id))</pre><p>In conclusion, Azure Databricks and MLflow provide a powerful combination for end-to-end machine learning workflows, from data preparation and model training to model deployment and monitoring. With practical examples, you can leverage the integration of Azure Databricks and MLflow to streamline your machine learning projects and ensure the security and reliability of your models in production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c6c6a8b3834" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>