<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data Science Environments Archives - relataly.com</title>
	<atom:link href="https://www.relataly.com/category/tech/datascienceenvironments/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.relataly.com/category/tech/datascienceenvironments/</link>
	<description>The Business AI Blog</description>
	<lastBuildDate>Fri, 09 Feb 2024 10:28:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.relataly.com/wp-content/uploads/2023/04/cropped-AI-cat-Icon-White.png</url>
	<title>Data Science Environments Archives - relataly.com</title>
	<link>https://www.relataly.com/category/tech/datascienceenvironments/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">175977316</site>	<item>
		<title>Building a Conversational Voice Bot with Azure OpenAI and Python: The Future of Human and Machine Interaction</title>
		<link>https://www.relataly.com/voice-conversations-with-azure-ai/14291/</link>
					<comments>https://www.relataly.com/voice-conversations-with-azure-ai/14291/#respond</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Thu, 08 Feb 2024 21:09:50 +0000</pubDate>
				<category><![CDATA[Azure Machine Learning]]></category>
		<category><![CDATA[ChatBots]]></category>
		<category><![CDATA[Generative AI]]></category>
		<category><![CDATA[OpenAI]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=14291</guid>

					<description><![CDATA[<p>OpenAI and Microsoft have just released a new generation of text-to-speech models that take synthetic speech to a new level. In my latest project I have combined these new models with Azure OpenAI&#8217;s ingenuine conversation capacity. The result is a conversational voice bot that uses Generative AI to converse with users in natural spoken language. ... <a title="Building a Conversational Voice Bot with Azure OpenAI and Python: The Future of Human and Machine Interaction" class="read-more" href="https://www.relataly.com/voice-conversations-with-azure-ai/14291/" aria-label="Read more about Building a Conversational Voice Bot with Azure OpenAI and Python: The Future of Human and Machine Interaction">Read more</a></p>
<p>The post <a href="https://www.relataly.com/voice-conversations-with-azure-ai/14291/">Building a Conversational Voice Bot with Azure OpenAI and Python: The Future of Human and Machine Interaction</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">OpenAI and Microsoft have just <a href="https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/azure-openai-service-announces-assistants-api-new-models-for/ba-p/4049940">released a new generation of text-to-speech models</a> that take synthetic speech to a new level. In my latest project I have combined these new models with Azure OpenAI&#8217;s ingenuine conversation capacity. The result is a conversational voice bot that uses Generative AI to converse with users in natural spoken language. </p>



<p class="wp-block-paragraph">This article describes the Python implementation of this project. The bot is designed to understand spoken language and process it through OpenAI GPT-4. It responds with contextually aware dialogue, all in natural-sounding speech. This seamless integration facilitates a conversational flow that feels intuitive and engaging. The voice processing capacities enable users to have meaningful exchanges with the bot as if they were conversing with another person. Testing the bot was a lot of fun. It felt a bit like the iconic scene from Iron Man where the hereo converses with an AI assistant.</p>



<p class="wp-block-paragraph">Here is an example of the audio response quality:</p>



<figure class="wp-block-audio"><audio controls src="https://www.relataly.com/wp-content/uploads/2024/02/ssml_output.wav"></audio></figure>



<p class="wp-block-paragraph">Also:</p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/from-pirates-to-nobleman-simulating-conversations-between-openais-chatgpt-and-itself-using-python/13525/">From Pirates to Nobleman: Simulating Multi-Agent Conversations using OpenAI’s ChatGPT and Python</a></li>



<li><a href="https://www.relataly.com/text-to-sql-with-llms-embracing-the-future-of-data-interaction/14234/" target="_blank" rel="noreferrer noopener">Text-to-SQL with LLMs &#8211; Embracing the Future of Data Interaction</a></li>
</ul>



<h2 class="wp-block-heading"><strong>Understanding the Voice Bot</strong></h2>



<p class="wp-block-paragraph">The magic begins with the user speaking to the bot. Azure Cognitive Services transcribes the spoken words into text, which is then fed into Azure&#8217;s OpenAI service. Here, the text is processed, and a response is generated based on the conversation&#8217;s context and history. Finally, the text-to-speech model transforms the response back into speech, completing the cycle of interaction. This process  showcases the potential of AI in understanding and participating in human-like conversations.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1966" height="512" data-attachment-id="14294" data-permalink="https://www.relataly.com/voice-conversations-with-azure-ai/14291/image-32/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2024/02/image.png" data-orig-size="1966,512" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2024/02/image.png" src="https://www.relataly.com/wp-content/uploads/2024/02/image.png" alt="" class="wp-image-14294" srcset="https://www.relataly.com/wp-content/uploads/2024/02/image.png 1966w, https://www.relataly.com/wp-content/uploads/2024/02/image.png 300w, https://www.relataly.com/wp-content/uploads/2024/02/image.png 512w, https://www.relataly.com/wp-content/uploads/2024/02/image.png 768w, https://www.relataly.com/wp-content/uploads/2024/02/image.png 1536w" sizes="(max-width: 1237px) 100vw, 1237px" /></figure>



<h3 class="wp-block-heading" id="h-prerequisites-azure-service-integration">Prerequisites &amp; Azure Service Integration</h3>



<p class="wp-block-paragraph">Our conversational voice bot is built upon two pivotal Azure services: Cognitive Speech Services and OpenAI. Billing of these services is pay-per-use. Unless you process large numbers of requests, the costs for experimenting with these services is relatively low. </p>



<h4 class="wp-block-heading" id="h-azure-cognitive-speech-services">Azure Cognitive Speech Services</h4>



<p class="wp-block-paragraph"><a href="https://azure.microsoft.com/en-us/products/ai-services/ai-speech">Azure AI Speech Services (previously Cognitive Speech Services)</a> provide the tools necessary for speech-to-text conversion, enabling our voice bot to understand spoken language. This service boasts advanced speech recognition capabilities, ensuring accurate transcription of user speech into text. Furthermore, it powers the text-to-speech synthesis that transforms generated text responses back into natural-sounding voice. This allows for a truly conversational experience. </p>



<p class="wp-block-paragraph">The newest generation of OpenAI text-to-speech models is now also <a href="https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/announcing-openai-text-to-speech-voices-on-azure-openai-service/ba-p/4049696">availbale in Azure AI Speech</a>. These models can synthesize voices in unknown level of quality. I am most impressed by its capability to alter intonation dynamically to express emotions.</p>



<h4 class="wp-block-heading" id="h-azure-openai-service">Azure OpenAI Service</h4>



<p class="wp-block-paragraph">At the heart of our project lies <a href="https://azure.microsoft.com/en-us/products/ai-services/openai-service">Azure&#8217;s OpenAI service</a>, which uses the power of models like GPT-4 context-aware responses. Once Azure Cognitive Speech Services transcribe the user&#8217;s speech into text, this text is sent to OpenAI. The OpenAI model then processes the input and generates a completion. The service&#8217;s ability to understand context and generate engaging responses is what makes our voice bot remarkably human-like.</p>



<h2 class="wp-block-heading" id="h-implementation-detailed-code-walkthrough">Implementation: Detailed Code Walkthrough</h2>



<p class="wp-block-paragraph">Let&#8217;s start with the implementation! We kick things off with <strong>Azure Service Authentication</strong>, where we set up our conversational voice bot to communicate with Azure and OpenAI&#8217;s advanced services. Then, <strong>Speech Recognition</strong> steps in, acting as our bot&#8217;s ears, converting spoken words into text. Next up, <strong>Processing and Response Generation</strong> uses OpenAI&#8217;s GPT-4 to turn text into context-aware responses. <strong>Speech Synthesis</strong> then gives our bot a voice, transforming text responses back into spoken words for a natural conversational flow. Finally, <strong>Managing the Conversation</strong> keeps the dialogue coherent and engaging. Through these steps, we create a voice bot that offers an intuitive and engaging conversational experience. Let&#8217;s discuss these sections one by one. </p>



<p class="wp-block-paragraph">As always, you can find the code on github:</p>



<div class="wp-block-kadence-advancedbtn kb-buttons-wrap kb-btns14291_9e80c9-12"><a class="kb-button kt-button button kb-btn14291_e0f677-ca kt-btn-size-standard kt-btn-width-type-full kb-btn-global-inherit kt-btn-has-text-true kt-btn-has-svg-true wp-block-button__link wp-block-kadence-singlebtn" href="https://github.com/flo7up/AzureOpenAIVoiceAssistant/tree/main" target="_blank" rel="noreferrer noopener"><span class="kb-svg-icon-wrap kb-svg-icon-fe_eye kt-btn-icon-side-left"><svg viewBox="0 0 24 24"  fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"  aria-hidden="true"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg></span><span class="kt-btn-inner-text">View on GitHub </span></a>

<a class="kb-button kt-button button kb-btn14291_8c1344-11 kt-btn-size-standard kt-btn-width-type-full kb-btn-global-inherit kt-btn-has-text-true kt-btn-has-svg-true wp-block-button__link wp-block-kadence-singlebtn" href="https://github.com/flo7up/relataly-public-python-tutorials" target="_blank" rel="noreferrer noopener"><span class="kb-svg-icon-wrap kb-svg-icon-fa_github kt-btn-icon-side-left"><svg viewBox="0 0 496 512"  fill="currentColor" xmlns="http://www.w3.org/2000/svg"  aria-hidden="true"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg></span><span class="kt-btn-inner-text">Relataly Github Repo </span></a></div>



<h3 class="wp-block-heading">Step #1 Azure Service Authentication </h3>



<p class="wp-block-paragraph">First off, we kick things off by getting our ducks in a row with <strong>Azure Service Authentication</strong>. This is where the magic starts, setting the stage for our conversational voice bot to interact with Azure&#8217;s brainy suite of Cognitive Services and the fantastic OpenAI models. By fetching API keys and setting up our service regions, we&#8217;re essentially giving our project the keys to the kingdom.</p>



<p class="wp-block-paragraph">For using dotenv, you need to create an .env file in your root folder. <a href="https://pypi.org/project/python-dotenv/">Here</a> is more information on how this works.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text/x-python&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}">import os
from dotenv import load_dotenv
import azure.cognitiveservices.speech as speechsdk
from openai import AzureOpenAI

# Load environment variables from .env file
load_dotenv()

# Constants from .env file
SPEECH_KEY = os.getenv('SPEECH_KEY')
SERVICE_REGION = os.getenv('SERVICE_REGION')
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
OPENAI_ENDPOINT = os.getenv('OPENAI_ENDPOINT')

# Azure Speech Configuration
speech_config = speechsdk.SpeechConfig(subscription=SPEECH_KEY, region=SERVICE_REGION)
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
speech_config.speech_recognition_language=&quot;en-US&quot;

# OpenAI Configuration
openai_client = AzureOpenAI(
    api_key=OPENAI_API_KEY,
    api_version=&quot;2023-12-01-preview&quot;,
    azure_endpoint=OPENAI_ENDPOINT
)
</pre></div>



<h3 class="wp-block-heading">Step #2 Speech Recognition</h3>



<p class="wp-block-paragraph">The user&#8217;s spoken input is captured and converted into text using Azure&#8217;s Speech-to-Text service. This involves initializing the speech recognition service with Azure credentials and configuring it to listen for and transcribe spoken language in real-time.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text/x-python&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}">def recognize_from_microphone():
    # Configure the recognizer to use the default microphone.
    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    # Create a speech recognizer with the specified audio and speech configuration.
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

    print(&quot;Speak into your microphone.&quot;)
    # Perform speech recognition and wait for a single utterance.
    speech_recognition_result = speech_recognizer.recognize_once_async().get()

    # Process the recognition result based on its reason.
    if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
        print(&quot;Recognized: {}&quot;.format(speech_recognition_result.text))
        # Return the recognized text if speech was recognized.
        return speech_recognition_result.text
    elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
        print(&quot;No speech could be recognized: {}&quot;.format(speech_recognition_result.no_match_details))
    elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = speech_recognition_result.cancellation_details
        print(&quot;Speech Recognition canceled: {}&quot;.format(cancellation_details.reason))
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            print(&quot;Error details: {}&quot;.format(cancellation_details.error_details))
            print(&quot;Did you set the speech resource key and region values?&quot;)
    # Return 'error' if recognition failed or was canceled.
    return 'error'</pre></div>



<h3 class="wp-block-heading">Step #3 Processing and Response Generation</h3>



<p class="wp-block-paragraph">Once we&#8217;ve got your words neatly transcribed, it&#8217;s time for the <strong>Processing and Response Generation</strong> phase. This is where OpenAI steps in, acting like the brain behind the operation. It takes your spoken words, now in text form, and churns out responses that are nothing short of conversational gold. We nudge OpenAI&#8217;s GPT-4 into generating replies that feel as natural as chatting with a close friend over coffee. </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text/x-python&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}">def openai_request(conversation, sample = [], temperature=0.9, model_engine='gpt-4'):
    # Initialize AzureOpenAI client with keys and endpoints from Key Vault.
    
    
    # Send a request to Azure OpenAI with the conversation context and get a response.
    response = openai_client.chat.completions.create(model=model_engine, messages=conversation, temperature=temperature, max_tokens=500)
    return response.choices[0].message.content</pre></div>



<h3 class="wp-block-heading">Step #4 Speech Synthesis</h3>



<p class="wp-block-paragraph">Next up, we tackle <strong>Speech Synthesis</strong>. If the previous step was the brain, consider this the voice of our operation. Taking the AI-generated text, we transform it back into speech—like turning lead into gold, but for conversations. Through Azure&#8217;s Text-to-Speech service, we&#8217;re able to give our bot a voice that&#8217;s not only clear but also surprisingly human-like. </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text/x-python&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}">def synthesize_audio(input_text):
    # Define SSML (Speech Synthesis Markup Language) for input text.
    ssml = f&quot;&quot;&quot;
        &lt;speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'&gt;
            &lt;voice name='en-US-OnyxMultilingualNeuralHD'&gt;
                &lt;p&gt;
                    {input_text}
                &lt;/p&gt;
            &lt;/voice&gt;
        &lt;/speak&gt;
        &quot;&quot;&quot;
    
    audio_filename_path = &quot;audio/ssml_output.wav&quot;  # Define the output audio file path.
    print(ssml)
    # Synthesize speech from the SSML and wait for completion.
    result = speech_synthesizer.speak_ssml_async(ssml).get()

    # Save the synthesized audio to a file if synthesis was successful.
    if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
        with open(audio_filename_path, &quot;wb&quot;) as audio_file:
            audio_file.write(result.audio_data)
        print(f&quot;Speech synthesized and saved to {audio_filename_path}&quot;)
    elif result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = result.cancellation_details
        print(f&quot;Speech synthesis canceled: {cancellation_details.reason}&quot;)
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            print(f&quot;Error details: {cancellation_details.error_details}&quot;)


# Create the audio directory if it doesn't exist.
if not os.path.exists('audio'):
    os.makedirs('audio')</pre></div>



<h3 class="wp-block-heading">Step #5 Managing the Conversation</h3>



<p class="wp-block-paragraph">Finally, we bring it all together in the Managing the Conversation step. This is where we ensure the chat keeps rolling, looping through listening, thinking, and speaking. We keep track of what&#8217;s been said to keep the conversation relevant and engaging. </p>



<p class="wp-block-paragraph">The system message below makes the bot talk like a pirate. But you can easily adjust the system message and this way customize the bots behavior.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text/x-python&quot;,&quot;theme&quot;:&quot;monokai&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}">conversation=[{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You are a helpful assistant that talks like pirate. If you encounter any issues, just tell a pirate joke or a story.&quot;}]

while True:
    user_input = recognize_from_microphone()  # Recognize user input from the microphone.
    conversation.append({&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: user_input})  # Add user input to the conversation context.

    assistant_response = openai_request(conversation)  # Get the assistant's response based on the conversation.

    conversation.append({&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: assistant_response})  # Add the assistant's response to the context.
    
    print(assistant_response)
    synthesize_audio(assistant_response)  # Synthesize the assistant's response into audio.</pre></div>



<p class="wp-block-paragraph">Throughout these steps, the conversation&#8217;s context is managed meticulously to ensure continuity and relevance in the bot&#8217;s responses, making the interaction feel more like a dialogue between humans.</p>



<h2 class="wp-block-heading">Current Challenges</h2>



<p class="wp-block-paragraph">Despite the promising capabilities of our voice bot, the journey through its development and interaction has presented a few challenges that underscore the complexity of human-machine communication.</p>



<h4 class="wp-block-heading">Slow Response Time</h4>



<p class="wp-block-paragraph">One of the notable hurdles is the slow response time experienced during interactions. The process, from speech recognition through to response generation and back to speech synthesis, involves several steps that can introduce latency. This latency can detract from the user experience, as fluid conversations typically require quick exchanges. Optimizing the interaction flow and exploring more efficient data processing methods may mitigate this issue in the future.</p>



<h4 class="wp-block-heading">Handling Pauses in Speech</h4>



<p class="wp-block-paragraph">Another challenge lies in the bot&#8217;s handling of longer pauses while speaking. The current setup does not always allow users to pause thoughtfully without triggering the end of their input. This may sometimes lead to a situation where the model cuts off speech prematurely. This limitation points to the need for more sophisticated speech recognition algorithms capable of distinguishing between a conversational pause and the end of an utterance.</p>



<h2 class="wp-block-heading">Summary</h2>



<p class="wp-block-paragraph">This article has shown how you can build a conversational voice bot in Python with the latest pretrained AI models. The project showcases the incredible potential of combining Azure Cognitive Services with OpenAI&#8217;s conversational models. I hope by now you understand the technical feasibility of creating voice-based applications and how they open up a world of possibilities for human-machine interaction. As we continue to refine and enhance this technology, the line between talking to a machine and conversing with a human will become ever more blurred, leading us into a future where AI companionship becomes reality.</p>



<p class="wp-block-paragraph">This exploration of Azure Cognitive Services and OpenAI&#8217;s integration within a voice bot is just the beginning. As AI continues to evolve, the ways in which we interact with technology will undoubtedly transform, making our interactions more natural, intuitive, and, most importantly, human.</p>



<p class="wp-block-paragraph">Also: <a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/"></a><a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/" target="_blank" rel="noreferrer noopener">9 Business Use Cases of OpenAI&#8217;s ChatGPT</a></p>



<h2 class="wp-block-heading">Sources and Further Reading</h2>



<ul class="wp-block-list">
<li><a href="https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/announcing-openai-text-to-speech-voices-on-azure-openai-service/ba-p/4049696" target="_blank" rel="noreferrer noopener">Microsoft announces openai text-to-speech voices</a></li>



<li><a href="https://azure.microsoft.com/en-us/products/ai-services/openai-service" target="_blank" rel="noreferrer noopener">Azure OpenAI Service Documentation</a></li>



<li><a href="https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/azure-openai-service-announces-assistants-api-new-models-for/ba-p/4049940" target="_blank" rel="noreferrer noopener">Recent Azure OpenAI Update</a></li>



<li><a href="https://azure.microsoft.com/en-us/products/ai-services/ai-speech" target="_blank" rel="noreferrer noopener">AI Spech Service Documentation</a></li>
</ul>
<p>The post <a href="https://www.relataly.com/voice-conversations-with-azure-ai/14291/">Building a Conversational Voice Bot with Azure OpenAI and Python: The Future of Human and Machine Interaction</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/voice-conversations-with-azure-ai/14291/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://www.relataly.com/wp-content/uploads/2024/02/ssml_output.wav" length="1256846" type="audio/wav" />

		<post-id xmlns="com-wordpress:feed-additions:1">14291</post-id>	</item>
		<item>
		<title>Getting Started with the Anaconda Python Environment for Machine Learning</title>
		<link>https://www.relataly.com/anaconda-python-environment-machine-learning/1663/</link>
					<comments>https://www.relataly.com/anaconda-python-environment-machine-learning/1663/#comments</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Fri, 14 Feb 2020 14:05:24 +0000</pubDate>
				<category><![CDATA[Anaconda Environment]]></category>
		<category><![CDATA[Data Science]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Beginner Tutorials]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=1663</guid>

					<description><![CDATA[<p>Anaconda is a popular open-source Python environment specifically designed for data science and machine learning. It comes with a range of useful features and tools, including Jupyter Notebooks, pre-installed packages, and a powerful package manager. It is the most widely used Python environment among data scientists and machine learning practitioners. In this article, we will ... <a title="Getting Started with the Anaconda Python Environment for Machine Learning" class="read-more" href="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/" aria-label="Read more about Getting Started with the Anaconda Python Environment for Machine Learning">Read more</a></p>
<p>The post <a href="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/">Getting Started with the Anaconda Python Environment for Machine Learning</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="wp-block-paragraph">Anaconda is a popular open-source Python environment specifically designed for data science and machine learning. It comes with a range of useful features and tools, including Jupyter Notebooks, pre-installed packages, and a powerful package manager. It is the most widely used Python environment among data scientists and machine learning practitioners.</p>



<p class="wp-block-paragraph">In this article, we will introduce some of the key features of Anaconda and show you how to set up the Anaconda Python environment for machine learning in Microsoft Windows. We will also cover some essential commands, such as managing virtual environments and installing packages, which will help you get started with your machine learning projects. Whether you are new to machine learning or an experienced practitioner, Anaconda is a valuable tool that can help you streamline your workflow and accelerate your progress. So, it is essential to learn how to use it effectively.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<figure class="wp-block-image size-full"><img decoding="async" width="447" height="223" data-attachment-id="12453" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/anaconda_logo/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/Anaconda_Logo.png" data-orig-size="447,223" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Anaconda_Logo" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/Anaconda_Logo.png" src="https://www.relataly.com/wp-content/uploads/2023/02/Anaconda_Logo.png" alt="Setting up the Anaconda Python environment for data science and machine learning" class="wp-image-12453" srcset="https://www.relataly.com/wp-content/uploads/2023/02/Anaconda_Logo.png 447w, https://www.relataly.com/wp-content/uploads/2023/02/Anaconda_Logo.png 300w" sizes="(max-width: 447px) 100vw, 447px" /><figcaption class="wp-element-caption">Setting up the Anaconda Python environment for data science and machine learning</figcaption></figure>
</div>
</div>



<h2 class="wp-block-heading">What is the Anaconda Distribution Platform?</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="wp-block-paragraph">For various reasons, Anaconda has become the most popular Python environment for machine learning. First of all, Anaconda includes a Python distribution, so there is no need for a separate Python installation. In addition, Anaconda has an integrated package manager that provides access to several tools and frameworks used in data science and software engineering, including Spyder, RStudio, Visual Studio Code, and Jupyter Notebooks. Below is a brief description of these tools:</p>



<ul class="wp-block-list">
<li><a href="https://jupyter.org/" target="_blank" rel="noreferrer noopener">Jupyter Notebook</a>s: They are open-source web applications that support creating and sharing code, equations, visualizations, and narrative text.</li>



<li><a href="https://www.jetbrains.com/de-de/pycharm/" target="_blank" rel="noreferrer noopener">Pycharm</a>: A fully integrated python programming environment for professional purposes</li>



<li><a href="https://github.com/jupyter/qtconsole/blob/54495ba073cda2802e410497f99a18c61ab4a599/docs/source/index.rst" target="_blank" rel="noreferrer noopener">Qt Console:</a> A light-weight terminal application for visualization</li>



<li><a href="https://www.spyder-ide.org/" target="_blank" rel="noreferrer noopener">Spyder:</a> Apython environment specifically designed for scientific purposes</li>



<li><a href="https://www.rstudio.com/" target="_blank" rel="noreferrer noopener">RStudio:</a> An environment for the programming language R</li>



<li><a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer noopener">Visual Studio (VS) Code:</a> An IDE for professional purposes by Microsoft</li>



<li><a href="https://orangedatamining.com/download/#windows" target="_blank" rel="noreferrer noopener">Orange</a>: A python environment for data mining and visualization</li>



<li><a href="https://glueviz.org/" target="_blank" rel="noreferrer noopener">Glueviz</a>: An open-source Python library for exploring data relationships</li>
</ul>



<p class="wp-block-paragraph">Many essential libraries related to data science are already preinstalled, including NumPy, Pandas, matplotlib, etc. Furthermore, Anaconda comes with a desktop GUI called Anaconda Navigator (see below), making it easy to launch applications and manage packages and environments without using command-line commands. </p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"></div>
</div>



<h2 class="wp-block-heading">About Jupyter Notebooks</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="wp-block-paragraph">Most data scientists who use Anaconda also work with <a href="https://jupyter.org/" target="_blank" rel="noreferrer noopener">Jupyter</a> notebooks. Jupyter notebooks are often used in the field of data science because they provide a convenient and interactive way to work with data, and they make it easy to share your work with others. They are also widely used in education, allowing you to create interactive lectures and exercises.</p>



<p class="wp-block-paragraph">Jupyter notebooks are interactive documents that contain a mix of code, text, and other media, such as images, equations, and charts. They are commonly used for data exploration, visualization, and machine learning tasks. Jupyter notebooks support more than 40 programming languages, including R and Python, and can run in different environments, thus making them very flexible. Furthermore, they are web-based and easy to set up. They also make it easy to version your code and share it with others.</p>



<p class="wp-block-paragraph">Jupyter notebooks are composed of cells, which can contain either code or text (using the Markdown formatting language). The code in a cell can be executed by pressing Shift+Enter, and the output of the code will be displayed below the cell. This allows you to develop and test your code iteratively, and to document your work by including explanations and visualizations alongside the code.</p>



<p class="wp-block-paragraph">Anaconda includes Jupyter as part of the installation. Once you have Anaconda installed, you can launch Jupyter by running the Jupyter lab or Jupiter notebook command in the terminal. This will open the Jupyter web interface in your web browser, from which you can create and open notebooks.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="652" data-attachment-id="11643" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/jupyter-notebook-screenshot/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png" data-orig-size="2955,1882" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="jupyter-notebook-screenshot" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png" src="https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot-1024x652.png" alt="Jupyter notebooks are interactive documents that allow you to mix code, text, and media in a single document, making them a powerful tool for data exploration, visualization, and analysis." class="wp-image-11643" srcset="https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 1024w, https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 300w, https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 768w, https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 1536w, https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 2048w, https://www.relataly.com/wp-content/uploads/2022/12/jupyter-notebook-screenshot.png 2475w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Jupyter notebooks are interactive documents that allow you to mix code, text, and media in a single document, making them a powerful tool for data exploration, visualization, and analysis.</figcaption></figure>
</div>
</div>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="h-setup-the-anaconda-python-environment-for-machine-learning">Setup the Anaconda Python Environment for Machine Learning</h2>



<p class="wp-block-paragraph">We will set up Anaconda to work with Python and Jupyter notebooks in the following. </p>



<ol class="wp-block-list">
<li>Download Anaconda</li>



<li>Install Anaconda </li>



<li>Starting Anaconda</li>



<li>Create and manage environments</li>



<li>Install additional packages as needed</li>
</ol>



<p class="wp-block-paragraph">Each of the steps will be discussed in more detail in the following. Let&#8217;s get things started! </p>



<h3 class="wp-block-heading" id="h-step-1-choose-and-download-the-right-anaconda-version">Step #1 Choose and Download the Right Anaconda Version</h3>



<p class="wp-block-paragraph">First, download the latest version of the Anaconda individual edition from the <a href="https://www.anaconda.com/products/individual">Anaconda website</a>. The Anaconda full version comes with all packages preinstalled. If disk space is an issue, you can also use Miniconda, a complete Anaconda environment but without the preinstalled packages. </p>



<p class="wp-block-paragraph">You will need to select the version of Anaconda that is appropriate for your operating system. The Anaconda download page will choose between Anaconda for Python 2.x and 3.x. Today, most machine learning libraries support Python 3. However, it wasn&#8217;t long ago when many people debated whether version 2 or 3 was the better Python version. Many people will agree that Python 3 has won this battle and is the preferred choice among the data science community. </p>



<p class="wp-block-paragraph">When writing this article, the latest version of the Anaconda individual edition is 4.3.1. After the download, you can launch the Anaconda installer, which guides you through the installation process.</p>



<h3 class="wp-block-heading" id="h-step-2-install-the-anaconda-python-environment">Step #2 Install the Anaconda Python Environment</h3>



<p class="wp-block-paragraph">You can choose whether to add Anaconda to your PATH environment variable during the installation. You can leave this option unchecked. Also, the installation asks you to register Anaconda as the default Python environment, which I recommend because it enables other tools to access the Anaconda Python distributions.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image is-resized"><img decoding="async" src="https://docs.anaconda.com/_images/win-install-options.png" alt="Install Screen During Anaconda Setup" width="482" height="373"/><figcaption class="wp-element-caption">Advanced Installation Options of Anaconda</figcaption></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image is-resized"><img decoding="async" src="https://docs.anaconda.com/_images/win-install-complete.png" alt="Install Screen During Anaconda Setup" width="478" height="371"/><figcaption class="wp-element-caption">Anaconda Installation Completed</figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading" id="h-step-3-starting-the-anaconda-python-environment">Step #3 Starting the Anaconda Python Environment</h3>



<p class="wp-block-paragraph">Once the installation process is complete, you can launch the Anaconda Navigator, which provides access to all the tools and CLIs you will be working on within your data science projects. </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1668" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/image-14-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/image-14.png" data-orig-size="1939,1012" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image-14" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/image-14.png" src="https://www.relataly.com/wp-content/uploads/2020/05/image-14-1024x534.png" alt="Anaconda Navigator" class="wp-image-1668" width="512" height="267" srcset="https://www.relataly.com/wp-content/uploads/2020/05/image-14.png 1024w, https://www.relataly.com/wp-content/uploads/2020/05/image-14.png 300w, https://www.relataly.com/wp-content/uploads/2020/05/image-14.png 768w, https://www.relataly.com/wp-content/uploads/2020/05/image-14.png 1536w, https://www.relataly.com/wp-content/uploads/2020/05/image-14.png 1939w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">Anaconda Navigator of the Anaconda Distribution Platform</figcaption></figure>



<p class="wp-block-paragraph">Anaconda comes with several Python packages preinstalled. The <a href="https://docs.anaconda.com/anaconda/packages/pkg-docs/" target="_blank" rel="noreferrer noopener">Anaconda website</a> provides an overview of these packages. To display a list of the packages in your Anaconda python environment, use the CMD command: </p>



<pre class="wp-block-preformatted">pip list</pre>



<p class="wp-block-paragraph">Before starting with your machine learning projects, you should ensure that you have the essential packages installed. Anaconda installation includes many packages, but some of the commonly used packages in machine learning still require a manual installation. In the relataly articles, we will be working with the following non-preinstalled packages:  </p>



<ul class="wp-block-list">
<li><a href="https://geopandas.org/" target="_blank" rel="noreferrer noopener">Geopandas</a>: GeoPandas is an open-source project to make working with geospatial data in Python easier.</li>



<li><a href="https://keras.io/getting_started/intro_to_keras_for_engineers/" target="_blank" rel="noreferrer noopener">Tensorflow (Keras):</a> Deep learning library used for neural networks.</li>



<li><a href="https://seaborn.pydata.org/" target="_blank" rel="noreferrer noopener">Seaborn</a>: A package for creating nice visualizations with lots of customization options.</li>



<li><a href="https://scikit-learn.org/stable/install.html">Scikit-learn</a>: Different tools and algorithms for predictive data analysis.</li>
</ul>



<p class="wp-block-paragraph">You can add these packages to your Anaconda environment by running the following conda install commands from the CMD prompt:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;null&quot;,&quot;mime&quot;:&quot;text/plain&quot;,&quot;theme&quot;:&quot;3024-day&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Plain Text&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;text&quot;}"># Tensorflow
conda install tensorflow
# or: pip install Tensorflow

# Scikitlearn
pip install sklearn

# GeoPandas
conda install geopandas
# or:pip install geopandas

# Pandas Data_Reader
conda install pandas-datareader
# or:pip install pandas-datareader

# Keras
pip install keras</pre></div>



<p class="wp-block-paragraph">With the conda install package command, you can access a cloud-based repository to find and install over 7,500 data science and machine learning packages. To download additional packages from the conda repository, use the command: &#8220;conda install package name&#8221;</p>



<h3 class="wp-block-heading" id="h-step-4-create-a-new-python-environment">Step #4 Create a New Python Environment</h3>



<p class="wp-block-paragraph">A key feature of Anaconda is its support for multiple virtual isolated programming environments. Virtual environments allow you to work with specific versions of libraries or Python. ThPythonhelpful because, from my experience, putting everything into a single environment leads to compatibility issues sooner or later.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph">Virtual environments have their packages and paths. Therefore, you don&#8217;t have to worry about the effect of packages on other Python environments. The best way to solve compatibility issues is by creating a new environment where you install these specific libraries that you need for your current project.</p>



<p class="wp-block-paragraph">The preferred way to create and manage environments in Anaconda is by using CMD terminal commands. You can launch the CMD prompt from the Anaconda Navigator, as shown below. There is also a graphical interface for managing environments, but I find its use rather tedious.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1729" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/bild2-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png" data-orig-size="1443,1125" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Bild2" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png" src="https://www.relataly.com/wp-content/uploads/2020/05/Bild2-1024x798.png" alt="Anaconda Welcome Screen" class="wp-image-1729" width="346" height="269" srcset="https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png 1024w, https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png 300w, https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png 768w, https://www.relataly.com/wp-content/uploads/2020/05/Bild2.png 1443w" sizes="(max-width: 346px) 100vw, 346px" /><figcaption class="wp-element-caption">The Anaconda Navigator</figcaption></figure>
</div>
</div>



<p class="wp-block-paragraph">From the Anaconda Navigator, you can create new environments and install packages. To create a new environment, click on the &#8220;Environments&#8221; tab, then click the &#8220;Create&#8221; button. Give your environment a name and select the version of Python that you want to use. You can also select any additional packages that you want to be installed in the environment.</p>



<p class="wp-block-paragraph">Below is a list of essential CMD commands for creating and managing environments in Anaconda:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:false,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;null&quot;,&quot;mime&quot;:&quot;text/plain&quot;,&quot;theme&quot;:&quot;3024-day&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Plain Text&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;text&quot;}"># Display a list of all environments
conda env list

# Create a new Environment with a specific Python version
conda create -n yourenvname python=x.x anaconda

# Create an exact copy of an existing environment
conda create --clone py35 --name py35-2

# Update Anaconda
conda update conda

# Activates the environment, so that all subsequent activities affect this environment
source activate yourenvname

# Install a new package into a specific environment
conda install -n yourenvname [package]

# Deactivate an environment
source deactivate

# Remove an environment including all packages
conda remove -n yourenvname -all</pre></div>



<p class="wp-block-paragraph">For additional commands, you can look at this <a href="https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf" target="_blank" rel="noreferrer noopener">Conda cheat sheet.</a></p>



<h3 class="wp-block-heading" id="h-step-5-create-a-jupyter-notebook">Step #5 Create a Jupyter Notebook</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph">Next, we create a new Python Jupyter notebook. You can launch Jupyter Notebooks from the Anaconda Navigator. The Jupyter Python environment will launch in a new browser window. Be aware that the notebook will use the virtual Anaconda environment that is currently active. The standard virtual environment is the &#8220;base&#8221; environment. </p>



<p class="wp-block-paragraph">If you want to create a new environment, you can do this by launching the command prompt and typing the following command:</p>



<pre class="wp-block-preformatted">conda create --name &lt;env name&gt; &lt;possible packages, e.g., keras, numpy, etc.&gt;</pre>



<p class="wp-block-paragraph">Once you have created a new environment, you can activate it with the following command:</p>



<pre class="wp-block-preformatted">conda activate &lt;env name&gt;</pre>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="5530" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/image-1-16/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2021/07/image-1.png" data-orig-size="1034,820" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image-1" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2021/07/image-1.png" src="https://www.relataly.com/wp-content/uploads/2021/07/image-1-1024x812.png" alt="Anaconda Navigator: Launch JupyterNotebook" class="wp-image-5530" width="512" height="406" srcset="https://www.relataly.com/wp-content/uploads/2021/07/image-1.png 1024w, https://www.relataly.com/wp-content/uploads/2021/07/image-1.png 300w, https://www.relataly.com/wp-content/uploads/2021/07/image-1.png 768w, https://www.relataly.com/wp-content/uploads/2021/07/image-1.png 1034w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">Anaconda Navigator: Launch JupyterNotebook</figcaption></figure>
</div>
</div>



<p class="wp-block-paragraph">Once you have launched the Jupyter notebook environment, you should see the standard folder path. In the folder path, you can choose a workspace folder that will contain all the Python code and the resources of your python projects. I have located my workspace at <em>C:\Users\Username\My_Jupyter_Workspace.</em></p>



<p class="wp-block-paragraph">To create a new Python notebook, click the &#8220;New&#8221; tab and select Python. A Pythonndow will open, and you can start to code.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1734" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/bild3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png" data-orig-size="1867,1005" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Bild3" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png" src="https://www.relataly.com/wp-content/uploads/2020/05/Bild3-1024x551.png" alt="File Management of the Jupyter Python Environment" class="wp-image-1734" width="768" height="413" srcset="https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png 1024w, https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png 300w, https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png 768w, https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png 1536w, https://www.relataly.com/wp-content/uploads/2020/05/Bild3.png 1867w" sizes="(max-width: 768px) 100vw, 768px" /><figcaption class="wp-element-caption">File Management of the Jupyter Python Environment</figcaption></figure>



<p class="wp-block-paragraph">That&#8217;s it. You have brought your Python infrastructure in place and can start coding.</p>



<h2 class="wp-block-heading" id="h-summary">Summary</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="wp-block-paragraph">This article has provided a comprehensive guide on setting up the Anaconda Python Environment for machine learning projects. By following the steps outlined in this article, you have successfully installed and configured the Anaconda Python environment, which is an essential tool for any data scientist or machine learning engineer.</p>



<p class="wp-block-paragraph">One of the key takeaways from this article is learning how to manage virtual environments, which is an essential practice for any data scientist or machine learning engineer. By creating separate virtual environments for different projects, you can ensure that each project has the necessary dependencies and libraries without interfering with other projects. This also helps to avoid version conflicts and ensures reproducibility.</p>



<p class="wp-block-paragraph">Another important aspect covered in this article is package installation. By using Anaconda&#8217;s built-in package manager, Conda, you can easily install and manage the necessary packages and libraries for your machine learning projects. Conda also makes it easy to switch between different versions of packages and manage dependencies.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<figure class="wp-block-image size-full"><img decoding="async" width="510" height="509" data-attachment-id="12455" data-permalink="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/anaconda-python-environment-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png" data-orig-size="510,509" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="anaconda-python-environment-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png" src="https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png" alt="" class="wp-image-12455" srcset="https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png 510w, https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/anaconda-python-environment-min.png 140w" sizes="(max-width: 510px) 100vw, 510px" /><figcaption class="wp-element-caption">Now that you have your Anaconda Python environment in place, you are ready to tackle exciting machine-learning projects. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>



<p class="wp-block-paragraph"></p>
</div>
</div>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="h-sources-and-further-reading">Sources and Further Reading</h2>



<ul class="wp-block-list">
<li><a href="https://www.anaconda.com/" target="_blank" rel="noreferrer noopener">anaconda.com</a></li>



<li><a href="https://jupyter.org/" target="_blank" rel="noreferrer noopener">jupyter.org</a></li>
</ul>



<p class="wp-block-paragraph">If you still need ideas for your first projects, the following tutorials may offer some inspiration:</p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/simple-cluster-analysis-using-k-means-with-python/5070/" target="_blank" rel="noreferrer noopener">Simple Cluster Analysis using K-Means with Python</a></li>



<li><a href="https://www.relataly.com/simple-sentiment-analysis-using-naive-bayes-and-logistic-regression/2007/" target="_blank" rel="noreferrer noopener">Simple Sentiment Analysis using Naive Bayes and Logistic Regression</a></li>



<li><a href="https://www.relataly.com/building-a-movie-recommender-using-collaborative-filtering/4376/" target="_blank" rel="noreferrer noopener">Building a Movie Recommender using Collaborative Filtering in Python</a></li>



<li><a href="https://www.relataly.com/image-classification-with-deep-learning/2485/" target="_blank" rel="noreferrer noopener">Getting Started with Image Recognition: Classifying Cats and Dogs using Neural Networks with Python</a></li>



<li>Images created with Midjourney</li>



<li>ChatGPT helped to revise certain parts of this article.</li>
</ul>
<p>The post <a href="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/">Getting Started with the Anaconda Python Environment for Machine Learning</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/anaconda-python-environment-machine-learning/1663/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1663</post-id>	</item>
		<item>
		<title>Flight Delay Prediction using Azure Machine Learning</title>
		<link>https://www.relataly.com/predict-flight-delays-azure/57/</link>
					<comments>https://www.relataly.com/predict-flight-delays-azure/57/#comments</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Tue, 15 Oct 2019 18:10:23 +0000</pubDate>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Azure Machine Learning]]></category>
		<category><![CDATA[Classification (two-class)]]></category>
		<category><![CDATA[Decision Trees]]></category>
		<category><![CDATA[Logistics]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Risk Management]]></category>
		<category><![CDATA[Use Cases]]></category>
		<category><![CDATA[AI in Logistics]]></category>
		<category><![CDATA[Beginner Tutorials]]></category>
		<category><![CDATA[Classic Machine Learning]]></category>
		<category><![CDATA[Data Pipelines]]></category>
		<category><![CDATA[Supervised Learning]]></category>
		<guid isPermaLink="false">http://www.relataly.com/?p=57</guid>

					<description><![CDATA[<p>If you travel a lot, you&#8217;ve probably already experienced this &#8211; you&#8217;re in a hurry on your way to the airport trying to catch a flight, only to find out that your flight is delayed. Wasn&#8217;t it great to know when a flight will be delayed in advance? We can use past flight delay data ... <a title="Flight Delay Prediction using Azure Machine Learning" class="read-more" href="https://www.relataly.com/predict-flight-delays-azure/57/" aria-label="Read more about Flight Delay Prediction using Azure Machine Learning">Read more</a></p>
<p>The post <a href="https://www.relataly.com/predict-flight-delays-azure/57/">Flight Delay Prediction using Azure Machine Learning</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph" id="h-if-you-travel-a-lot-you-ve-probably-already-experienced-this-you-re-in-a-total-hurry-on-your-way-to-the-airport-trying-to-catch-a-flight-only-to-find-out-at-the-airport-that-your-flight-is-delayed-anyway-wasn-t-it-great-to-know-in-advance-when-a-flight-is-going-to-be-delayed-this-would-make-travelling-more-relaxed-well-there-is-a-solution-and-it-is-based-on-machine-learning-we-can-use-past-data-on-delayed-flights-to-develop-a-classification-model-that-predicts-flight-delays-more-specifically-we-speak-of-a-statistical-model-that-calculates-the-probability-of-a-certain-flight-being-delayed-or-on-time-in-this-blog-post-on-flight-delay-prediction-i-show-how-to-develop-a-prediction-model-in-the-azure-ml-studio-classic-workbench-that-predicts-whether-a-flight-will-be-more-or-less-than-30-minutes-late-all-you-need-is-a-microsoft-live-account-and-about-30-40-minutes-of-your-time">If you travel a lot, you&#8217;ve probably already experienced this &#8211; you&#8217;re in a hurry on your way to the airport trying to catch a flight, only to find out that your flight is delayed. Wasn&#8217;t it great to know when a flight will be delayed in advance? We can use past flight delay data to develop a classification model that predicts whether a flight will be on time or delayed in the future. This tutorial shows how this works by creating a flight-delay prediction model&nbsp;in the Azure Machine Learning Studio workbench. </p>



<p class="wp-block-paragraph" id="h-if-you-travel-a-lot-you-ve-probably-already-experienced-this-you-re-in-a-total-hurry-on-your-way-to-the-airport-trying-to-catch-a-flight-only-to-find-out-at-the-airport-that-your-flight-is-delayed-anyway-wasn-t-it-great-to-know-in-advance-when-a-flight-is-going-to-be-delayed-this-would-make-travelling-more-relaxed-well-there-is-a-solution-and-it-is-based-on-machine-learning-we-can-use-past-data-on-delayed-flights-to-develop-a-classification-model-that-predicts-flight-delays-more-specifically-we-speak-of-a-statistical-model-that-calculates-the-probability-of-a-certain-flight-being-delayed-or-on-time-in-this-blog-post-on-flight-delay-prediction-i-show-how-to-develop-a-prediction-model-in-the-azure-ml-studio-classic-workbench-that-predicts-whether-a-flight-will-be-more-or-less-than-30-minutes-late-all-you-need-is-a-microsoft-live-account-and-about-30-40-minutes-of-your-time">The model uses a <a href="https://www.relataly.com/category/machine-learning-algorithms/decision-trees/" target="_blank" rel="noreferrer noopener">decision tree algorithm</a> to predict whether a flight will be more or less than 30 minutes late. In this approach, the algorithm searches for patterns in the data of past flight connections and applies these patterns to classify flights into two classes: delayed and not delayed. Travel service providers use similar models to warn customers when a flight is likely to be delayed.</p>



<h2 class="wp-block-heading">What is Flight Delay Prediction?</h2>



<p class="wp-block-paragraph">Flight delay prediction is the use of data and analytics to forecast whether a flight is likely to be delayed. This information can be used by airlines, airports, and passengers to plan and prepare for potential delays and to make informed decisions about travel plans. Models for predicting flight punctuality typically consider a range of factors, including historical data on past flight delays, weather conditions, the performance of the airline and the specific aircraft involved, and other relevant information. Machine learning algorithms are often used to analyze and process this data, and to generate predictions about the likelihood and duration of flight delays. These predictions can be made in real-time, as the flight is in progress, or in advance, based on the scheduled departure time and other factors.</p>



<h2 class="wp-block-heading">Developing a Flight Prediction Model in Azure Machine Learning</h2>



<p class="wp-block-paragraph">In the following hands-on tutorial, we will develop a flight prediction model in Azure Machine Learning. To develop the  model, we will carry out the following steps:</p>



<ol class="wp-block-list">
<li><strong>Gather and prepare the data:</strong> We will load data on past flights, including information on their departure and arrival times, the airlines and aircraft involved, the airports and routes, and other relevant factors. This data needs to be cleaned and preprocessed to remove any errors or inconsistencies and to format it in a way that can be used by the machine learning model.</li>



<li><strong>Explore and analyze the data: </strong>This involves using tools and techniques, such as data visualization and statistical analysis, to understand the patterns and trends in the data and to identify any factors that may be associated with flight delays. </li>



<li><strong>Train a machine learning algorithm: </strong>We train a decision forest algorithm on the data to learn the patterns and relationships that exist in the data. </li>



<li><strong>Evaluate the model: </strong>We test our trained model on a separate set of data to see how accurately it can predict flight delays. This can be done using a range of metrics, such as accuracy, precision, and recall, to measure the performance of the model and to identify any areas for improvement.</li>



<li><strong>Deploy and use the model:</strong> We don&#8217;t cover this step explicitly. However, we broadly discuss how we could deploy the model into production. </li>
</ol>



<h2 class="wp-block-heading">Prerequisites: Signing Up for a Free Azure Account</h2>



<p class="wp-block-paragraph">In order to use the azure machine learning studio, you require access to a valid Azure subscription. Don&#8217;t worry, you can sign up for a free Azure account that offers beginners a sufficient number of credits. Simply follow these steps:</p>



<ol class="wp-block-list">
<li>Go to the Azure website (<a href="https://azure.microsoft.com/" target="_blank" rel="noreferrer noopener">https://azure.microsoft.com/</a>).</li>



<li>Click on the &#8220;Try azure for free&#8221; button in the middle of the page. Then select &#8220;start free&#8221; on the next page.</li>



<li>Enter your email address and password, and create a new Microsoft account, if you don&#8217;t already have one.</li>



<li>Follow the on-screen instructions to complete the sign-up process, including verifying your email address and phone number.</li>



<li>Once your account has been created, you can log in to the Azure portal (<a href="https://portal.azure.com/" target="_blank" rel="noreferrer noopener">https://portal.azure.com/</a>) using your Microsoft account credentials.</li>



<li>From the Azure portal, you can access a range of services and resources, including machine learning, data analytics, and other cloud-based tools and services.</li>
</ol>



<p class="wp-block-paragraph">Note that the free Azure account includes a limited amount of free credit and services, which you can use to try out Azure and learn more about its capabilities. Once your free credit has been used up, you can choose to upgrade to a paid subscription to continue using Azure.</p>



<h3 class="wp-block-heading" id="h-step-1-access-microsoft-azure-machine-learning-studio">Step #1 Access Microsoft Azure Machine Learning Studio</h3>



<p class="wp-block-paragraph">This article uses Microsoft&#8217;s data science workbench Azure Machine Learning Studio (classic). There is also a new version of the Machine Learning Studio available, which provides more functionality but works in a similar way. The classic workbench provides comprehensive functions such as creating data pipelines, training and testing machine learning models, and publishing trained models as a web service via an API. </p>



<p class="wp-block-paragraph">The studio is available via free trial access. You can create a free test account (8h valid) via &#8220;Sign up here&#8221; on <a href="https://azure.microsoft.com/de-de/services/machine-learning-studio/" target="_blank" rel="noreferrer noopener">Azure Machine Learning</a> <a href="https://azure.microsoft.com/de-de/services/machine-learning-studio/" target="_blank" rel="noreferrer noopener">Studio</a> or log in with an existing Microsoft Live account. After the successful login, you will see the experiments section: </p>



<figure class="wp-block-image is-resized"><img decoding="async" data-attachment-id="59" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/image-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2019/10/image.png" data-orig-size="1452,675" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2019/10/image.png" src="http://www.relataly.com/wp-content/uploads/2019/10/image-1024x476.png" alt="Welcome Screen in Azure ML Studio Classic" class="wp-image-59" width="768" height="357" srcset="https://www.relataly.com/wp-content/uploads/2019/10/image.png 1024w, https://www.relataly.com/wp-content/uploads/2019/10/image.png 300w, https://www.relataly.com/wp-content/uploads/2019/10/image.png 768w, https://www.relataly.com/wp-content/uploads/2019/10/image.png 1452w" sizes="(max-width: 768px) 100vw, 768px" /><figcaption class="wp-element-caption">Experiments section of the Azure Machine Learning Studio </figcaption></figure>



<h3 class="wp-block-heading" id="h-step-2-importing-training-data-into-azure-ml">Step #2 Importing Training Data into Azure ML</h3>



<p class="wp-block-paragraph">This tutorial will work with the CSV dataset <a href="http://www.relataly.com/wp-content/uploads/2019/10/FlightDelayData.csv">FlightDelayData.csv</a></p>



<p class="wp-block-paragraph">After downloading the dataset, you can import it into Azure Machine Learning Studio. Navigate to &#8220;Experiments&#8221; and click on &#8220;+ New&#8221; at the bottom left. On the following page, select &#8220;Dataset&#8221; on the left and then &#8220;Upload Local File.&#8221; Select the file FlightDelayData and confirm the upload. </p>



<figure class="wp-block-image size-large is-resized"><a href="https://ipt.jiveon.com/servlet/JiveServlet/showImage/38-1690-65776/pastedImage_1.png"><img decoding="async" data-attachment-id="1109" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/prediction1/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png" data-orig-size="2004,956" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="prediction1" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png" src="https://www.relataly.com/wp-content/uploads/2019/10/prediction1-1024x488.png" alt="Uploading a new dataset" class="wp-image-1109" width="768" height="366" srcset="https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png 1024w, https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png 300w, https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png 768w, https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png 1536w, https://www.relataly.com/wp-content/uploads/2019/10/prediction1.png 2004w" sizes="(max-width: 768px) 100vw, 768px" /></a><figcaption class="wp-element-caption">Uploading a new dataset</figcaption></figure>



<p class="wp-block-paragraph">Confirm the dialog to access the experiment workspace. Here, you will find a list of different modules (highlighted in light blue) to the left of the workspace. The modules provide all central functions in Azure Machine Learning Studio, such as transforming and exploring the data and using them in machine learning.</p>



<figure class="wp-block-image size-large is-resized"><a href="https://ipt.jiveon.com/servlet/JiveServlet/showImage/38-1690-65777/pastedImage_3.png"><img decoding="async" data-attachment-id="1110" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/prediction2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png" data-orig-size="1128,617" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="prediction2" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png" src="https://www.relataly.com/wp-content/uploads/2020/05/prediction2-1024x560.png" alt="The modul tab of Azure ML" class="wp-image-1110" width="768" height="420" srcset="https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png 1024w, https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png 300w, https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png 768w, https://www.relataly.com/wp-content/uploads/2020/05/prediction2.png 1128w" sizes="(max-width: 768px) 100vw, 768px" /></a><figcaption class="wp-element-caption">The module tab of Azure Machine Learning</figcaption></figure>



<h3 class="wp-block-heading" id="h-step-3-exploring-the-data">Step #3 Exploring the Data</h3>



<p class="wp-block-paragraph">Now that the data set is available in Azure Machine Learning, we will prepare it for its use in our flight delay prediction model. First, we will drag and drop the FlightDelayData dataset from &#8220;Saved Datasets&#8221; into the grey workspace of the experiment. Next, we will visualize the data by right-clicking on FlightDelayData &#8211;&gt; &#8220;dataset&#8221; &#8211;&gt; &#8220;Visualize&#8221; in the grey work area. </p>



<p class="wp-block-paragraph">Clicking on the individual columns will give you an overview of the data sets&#8217; characteristics and distribution. In the upper left corner, you can see that the dataset contains 135970 entries for flight connections. Each entry or line represents one flight. All flights took place in 2013. Furthermore, the data includes the departure and arrival locations of flights, time and day of departure and arrival, the airline, and the deviation from the planned take-off and landing time.  </p>



<h3 class="wp-block-heading" id="h-step-4-creating-a-data-pipeline">Step #4 Creating a Data Pipeline</h3>



<p class="wp-block-paragraph">Before we can train the model, we need to split the data into two parts: train and test. We will use the first part of the data to train the Machine Learning model and the second to evaluate its predictions. This approach is known as supervised learning. Search for the &#8220;Split Data module&#8221; in the search list on the left and drag and drop it into the grey workspace to split the data. After this, you can connect the two modules by clicking on the output of the data set (FlightDelayData) and dragging it to the input of the &#8220;Split Data module&#8221; (see screenshot). </p>



<p class="wp-block-paragraph"> Next, we configure the Split Data module. Click on the module and make the following settings on the right side under &#8220;Properties&#8221;: Fraction of rows in the first output dataset: 0.7&nbsp;and Random seed: 123. </p>



<p class="wp-block-paragraph">In this way, we divide the data randomly in a 70/30 ratio. You can leave the others as they are. </p>



<figure class="wp-block-image size-large is-resized"><a href="https://ipt.jiveon.com/servlet/JiveServlet/showImage/38-1690-65779/pastedImage_1.png"><img decoding="async" data-attachment-id="1112" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/prediction3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/prediction3.png" data-orig-size="628,354" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="prediction3" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/prediction3.png" src="https://www.relataly.com/wp-content/uploads/2020/05/prediction3.png" alt="Splitting the data into train and test" class="wp-image-1112" width="758" height="428" srcset="https://www.relataly.com/wp-content/uploads/2020/05/prediction3.png 628w, https://www.relataly.com/wp-content/uploads/2020/05/prediction3.png 300w" sizes="(max-width: 758px) 100vw, 758px" /></a><figcaption class="wp-element-caption">Splitting the data into train and test</figcaption></figure>



<p class="wp-block-paragraph">(In practice, the compilation and preparation of the data are much more complex. I have already carried out some steps in advance.)</p>



<h3 class="wp-block-heading" id="h-step-5-creating-a-classification-model">Step #5 Creating a Classification Model</h3>



<p class="wp-block-paragraph">Now we will create a classification model. Therefore, we will pull further models into the grey area of the workbench. Our model will use a boosted decision tree classifier. We can use this algorithm by dragging the module &#8220;Two-Class Boosted Decision Tree&#8221; into the grey workspace below the other modules. You can leave the settings of the module unchanged. </p>



<p class="wp-block-paragraph">Next, we select the module &#8220;Train Model&#8221; and drag it into the grey workspace under the other modules. In the workspace, connect the output of the &#8220;Two-Class Boosted Decision Tree&#8221; module to the left input of the &#8220;Train Model&#8221; module.</p>



<p class="wp-block-paragraph">Remember, we want to predict whether flights will be more or less than 15 minutes late. Select &#8220;Train Model&#8221; in the grey workspace and click on &#8220;Launch Column Selector&#8221; under Properties on the right. In the Column Selector, enter &#8220;ArrDel15&#8221; under &#8220;Column Name&#8221;. This column contains the so-called &#8220;prediction label,&#8221; which is the information on whether flights were more or less than 15 minutes late. Don&#8217;t forget to connect the left output of the Split Data module to the right input of the Train Model. </p>



<p class="wp-block-paragraph">To evaluate the model&#8217;s predictions later, we will add a &#8220;Score Model.&#8221; We do this by selecting the module &#8220;Score Model&#8221; and dragging it into the workspace below the other modules. Finally, we need to create two connections. First, connect the left input of the &#8220;Score Model&#8221; with the left output of the &#8220;Train Model.&#8221; Second, connect the input node on the right of the &#8220;Score Model&#8221; to the output on the right of &#8220;Split Data,&#8221; which is the 30% of the original data set we use to test the model. </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1129" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/pastedimage_31/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_31.png" data-orig-size="705,361" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="pastedImage_31" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_31.png" src="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_31.png" alt="Selecting the prediction label" class="wp-image-1129" width="882" height="452" srcset="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_31.png 705w, https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_31.png 300w" sizes="(max-width: 882px) 100vw, 882px" /><figcaption class="wp-element-caption">Selecting the prediction label</figcaption></figure>



<h3 class="wp-block-heading" id="h-step-6-training-the-model">Step #6 Training the Model</h3>



<p class="wp-block-paragraph">Before we can train the model, we add the module &#8220;Evaluate Model&#8221; by searching it in the module tab and dragging it into the workspace. Finally, we connect the (left) input of the &#8220;Evaluate Model&#8221; with the output of the &#8220;Score Model.&#8221; </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1133" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/pastedimage_22/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_22.png" data-orig-size="620,325" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="pastedImage_22" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_22.png" src="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_22.png" alt="" class="wp-image-1133" width="769" height="404" srcset="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_22.png 620w, https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_22.png 300w" sizes="(max-width: 769px) 100vw, 769px" /><figcaption class="wp-element-caption">Creating a machine learning model</figcaption></figure>



<p class="wp-block-paragraph">Once we have created the data transformation pipelines, we are ready to train the model. Start the training process by clicking the &#8220;Run button&#8221; in the dark bar at the bottom. It may take a few minutes until the process has finished. Meanwhile, you can monitor the processing progress by the green checkmarks shown on the modules.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1132" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/pastedimage_2-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_2-2.png" data-orig-size="620,541" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="pastedImage_2-2" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_2-2.png" src="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_2-2.png" alt="Model after successfull training" class="wp-image-1132" width="617" height="539" srcset="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_2-2.png 620w, https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_2-2.png 300w" sizes="(max-width: 617px) 100vw, 617px" /><figcaption class="wp-element-caption">Model after successful training</figcaption></figure>



<h3 class="wp-block-heading" id="h-step-7-evaluating-model-performance">Step #7 Evaluating Model Performance </h3>



<p class="wp-block-paragraph">So far, we have built a statistical model for flight delay prediction. Of course, we want to know how often our model is right or wrong with the predictions. Evaluating the performance of prediction models is thus an essential step in their development. To evaluate the model performance, right-click on &#8220;Evaluate Model&#8221; -> &#8220;Evaluation results&#8221; -> &#8220;Visualize.&#8221; Below you will find the <em>receiver operating characteristic</em> (ROC) of the trained model:</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="1134" data-permalink="https://www.relataly.com/predict-flight-delays-azure/57/pastedimage_3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_3.png" data-orig-size="619,564" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="pastedImage_3" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_3.png" src="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_3.png" alt="ROC Curve and Results of the Flight Prediction Classifier" class="wp-image-1134" width="464" height="423" srcset="https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_3.png 619w, https://www.relataly.com/wp-content/uploads/2020/05/pastedImage_3.png 300w" sizes="(max-width: 464px) 100vw, 464px" /><figcaption class="wp-element-caption">Metrics used to evaluate the performance of a classification model</figcaption></figure>



<p class="wp-block-paragraph">Let&#8217;s look at the different metrics at the bottom. </p>



<ul class="wp-block-list">
<li>The test data set contains 40791 flights, 30% of the original data.</li>



<li>The model correctly predicted for 2098 flights that, they would have more than 15 delays (true positives). </li>



<li>The model was wrong in 1310 cases (false positives).</li>



<li>According to the model&#8217;s prediction, six thousand eight hundred twenty-five flights were more than 15 minutes delayed (false negatives). </li>



<li>The model was correct in 30558 cases, estimating that these flights will have less than 15 minutes delays. </li>



<li>Overall, the model is correct in about 80% of the cases (Accuracy = 0.801).</li>
</ul>



<p class="wp-block-paragraph">Finally, we look at the ROC curve. The curve illustrates the reliability of the model depending on the prediction threshold. The larger the area under the curve, the better the prediction model. The curve is sloped upwards and lies above the grey line, which means that the model works better than random assumptions. The gray diagonal line corresponds to a 50% chance to lie correctly, i.e., easy to guess. With a perfect correct model for every flight, the area would be 1.0. </p>



<h3 class="wp-block-heading">Step #8 Deploying the Model as a Web Service</h3>



<p class="wp-block-paragraph">Now that we have our model available, of course, we would like to make it accessible to others. Let&#8217;s quickly discuss how we could deploy our model as a web service from the designer.</p>



<p class="wp-block-paragraph">We won&#8217;t go into too much detail here and will only cover the basic steps for deploying a model. To deploy a machine learning pipeline in Azure Machine Learning, you need to convert the training pipeline into an inference pipeline. The pipeline can process prediction requests in real time or in batch mode. Deploying the model from the designer involves removing the training components, such as the Train Model and Split Data modules, and adding web service inputs and outputs to handle user requests. When you create an inference pipeline, azure ml stores the trained model as a Dataset component in the component palette. From there, you can access it under &#8220;My Datasets.&#8221; The saved trained model is then added to the pipeline, along with the web service input and output components. These components define the points where user data enters the pipeline and where the pipeline returns the results. Once you have deployed the model, other applications and systems can access it via a REST API.</p>



<h2 class="wp-block-heading" id="h-summary">Summary</h2>



<p class="wp-block-paragraph">We have created a flight delay prediction model in Azure Machine Learning Studio in this article. The model can predict with 80% certainty whether flights on specific routes will be more or less than 15 minutes late. This can help airlines, airports, and passengers to plan and prepare for potential delays and to make informed decisions about travel plans. We have also discussed how we can use the studio designer to deploy our model as web services to provide predictions in real-time or batch mode.</p>



<p class="wp-block-paragraph">The prediction model is only the first version and still offers room for optimization. One option to further improve the model would be to add features such as the weather, the aircraft type, etc. Another option would be to test different algorithms and hyperparameters. </p>



<p class="wp-block-paragraph">I hope this article was helpful. If you have remarks or questions, please write them in the comments.</p>
<p>The post <a href="https://www.relataly.com/predict-flight-delays-azure/57/">Flight Delay Prediction using Azure Machine Learning</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/predict-flight-delays-azure/57/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">57</post-id>	</item>
	</channel>
</rss>
