<?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>Machine Learning in Manufacturing</title>
	<atom:link href="https://www.relataly.com/category/manufacturing/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.relataly.com/category/manufacturing/</link>
	<description>The Business AI Blog</description>
	<lastBuildDate>Sat, 27 May 2023 10:29:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.relataly.com/wp-content/uploads/2023/04/cropped-AI-cat-Icon-White.png</url>
	<title>Machine Learning in Manufacturing</title>
	<link>https://www.relataly.com/category/manufacturing/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">175977316</site>	<item>
		<title>How Far are Swiss Enterprises in Adopting OpenAI&#8217;s GPT Models?</title>
		<link>https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/</link>
					<comments>https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/#respond</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Sun, 23 Apr 2023 21:03:03 +0000</pubDate>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Generative AI]]></category>
		<category><![CDATA[Healthcare]]></category>
		<category><![CDATA[Insurance]]></category>
		<category><![CDATA[Logistics]]></category>
		<category><![CDATA[Manufacturing]]></category>
		<category><![CDATA[Natural Language Processing]]></category>
		<category><![CDATA[Telecommunications]]></category>
		<category><![CDATA[AI in E-Commerce]]></category>
		<category><![CDATA[AI in Finance]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=13486</guid>

					<description><![CDATA[<p>OpenAI&#8217;s large language models, such as GPT-4 and ChatGPT, have the potential to revolutionize customer experience and boost economic productivity to a new level. With its ability to automate processes, provide predictive insights, and enhance decision-making capabilities, OpenAI will also impact companies in Switzerland. The question remains: how far along is Switzerland in adopting OpenAI? ... <a title="How Far are Swiss Enterprises in Adopting OpenAI&#8217;s GPT Models?" class="read-more" href="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/" aria-label="Read more about How Far are Swiss Enterprises in Adopting OpenAI&#8217;s GPT Models?">Read more</a></p>
<p>The post <a href="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/">How Far are Swiss Enterprises in Adopting OpenAI&#8217;s GPT Models?</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-9d6595d7 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>OpenAI&#8217;s large language models, such as GPT-4 and ChatGPT, have the potential to revolutionize customer experience and boost economic productivity to a new level. With its ability to automate processes, provide predictive insights, and enhance decision-making capabilities, OpenAI will also impact companies in Switzerland. The question remains: how far along is Switzerland in adopting OpenAI? In this article, we will explore the journey of OpenAI adoption and discuss the different stages organizations undergo in adopting ChatGPT and Co. </p>



<p>With over five years of experience as a former Data and AI consultant in Switzerland, I&#8217;ve witnessed a significant shift from traditional machine learning to deep learning and, more recently, OpenAI. Since the beginning of the year, the hype around ChatGPT has continued to grow. As a result, I&#8217;ve been engaging in frequent discussions with consultancies, startups, and large corporates about how they can leverage OpenAI. Through these conversations, I&#8217;ve gained valuable insights into the current market and varying levels of adoption among organizations.</p>



<p>It is crucial to mention that the opinions shared in this article are my personal views and not based on extensive research. Nonetheless, they aim to provide you with an understanding of Switzerland&#8217;s progress in OpenAI adoption. This perspective can help you gauge and compare your organization&#8217;s advancement with others. So, join me on a journey towards AI-driven innovation and discover Switzerland&#8217;s stance in adopting OpenAI. I will not differentiate between the variations of GenerativeAI &#8211; because most companies are interested in using OpenAI GPT models such as GPT-4 and ChatGPT.</p>



<p><strong>Also: </strong></p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/eliminating-friction-how-openais-gpt-streamlines-online-experiences-and-reduces-the-need-for-google-searches/13171/" target="_blank" rel="noreferrer noopener">Eliminating Friction: How LLMs such as OpenAI’s ChatGPT Streamline Digital Experiences and Reduce the Need for Search</a></li>



<li><a href="https://hai.stanford.edu/news/2023-state-ai-14-charts" target="_blank" rel="noreferrer noopener">Stanford.edu 2023 State of AI in 14 Charts</a> </li>
</ul>
</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">Adopting OpenAI &#8211; A Question of Risk and Reward</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>With the rapid evolution of AI, it is crucial for organizations to keep up with the latest developments in their respective industries. In Switzerland, Generative AI is gaining traction, and many businesses have begun evaluating their own strategy toward adoption.</p>



<p>In my opinion, it is inevitable that organizations will need to integrate AI and Generative AI into their products and services to remain competitive in the market. The main question for these organizations is how quickly they want to embark on this journey and how much first-mover risk they are willing to take.</p>



<p>As organizations begin to adopt AI technologies such as Generative AI, it&#8217;s important to acknowledge that mistakes and challenges may occur in the process. For instance, a Swiss insurance company launched a ChatGPT-powered chatbot, one of the first of its kind in the Swiss insurance industry. However, the initial service allowed users to jailbreak the bot and manipulate its responses.</p>



<p>While these situations should ideally be avoided, they can serve as valuable learning experiences for organizations, helping them refine their strategies and improve AI capabilities. Despite the risks, I firmly believe that the benefits of early adoption outweigh the potential drawbacks. Being an early adopter can provide a significant competitive advantage over laggards, who may struggle to keep up with evolving customer expectations and technological advancements.</p>



<p>On the other hand, there&#8217;s also a considerable risk in not taking action. Once customers become accustomed to OpenAI-powered service experiences, laggards may need to follow suit or risk losing market share. Failing to invest in new technologies can also hinder cost efficiency and negatively impact competitiveness. In other words, there&#8217;s always a degree of risk involved, whether you choose to adopt early or late.</p>



<p>Also: <a href="https://www.relataly.com/chatgpt-style-guide-understanding-voice-and-tone-options-for-engaging-conversations/13065/" target="_blank" rel="noreferrer noopener">ChatGPT Style Guide: Understanding Voice and Tone Prompt Options for Engaging Conversations</a> </p>



<h2 class="wp-block-heading">Assessing the State of the Swiss Economy in Generative AI Adoption</h2>



<p>The Swiss market is very heterogeneous when it comes to OpenAI adoption. On one side, there are companies that hesitate to take the first steps with OpenAI, with some even blocking ChatGPT internally. On the other side, some innovative players have already introduced OpenAI-powered services within just a few months. So, the question remains: How far is Switzerland in adopting Generative AI? In the following, we&#8217;ll explore the journey of OpenAI adoption in Switzerland and discuss the different stages organizations undergo in adopting Generative AI.</p>



<p>We will structure the discussion along five maturity levels organizations go through when adopting this technology. I believe these levels are suitable for understanding where companies stand in their journey toward AI-driven innovation and provide a useful framework for mapping out future strategies. The framework ranges from Level 0 (What is OpenAi) to Level 5 (Proven Track Record) and discusses how companies can move towards AI-driven innovation.</p>



<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" data-attachment-id="13515" data-permalink="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/image-4-6/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/04/image-4.png" data-orig-size="2080,409" 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-4" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/04/image-4.png" src="https://www.relataly.com/wp-content/uploads/2023/04/image-4.png" alt="" class="wp-image-13515" width="765" height="150" srcset="https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 2080w, https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 300w, https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 512w, https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 768w, https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 1536w, https://www.relataly.com/wp-content/uploads/2023/04/image-4.png 2048w" sizes="(max-width: 765px) 100vw, 765px" /><figcaption class="wp-element-caption">Qualitative Assessment of the State of the Swiss Economy for OpenAi Adoption &#8211; April 2023 &#8211; Bubble size corresponds to the percentage of organizations in the different states.</figcaption></figure>
</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 is-resized"><img decoding="async" data-attachment-id="13490" data-permalink="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/colorful_popart_of_programmers_working_on_generative_ai/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png" data-orig-size="1026,1020" 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="Colorful_popart_of_programmers_working_on_generative_AI" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png" src="https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI-512x509.png" alt="" class="wp-image-13490" width="383" height="380" srcset="https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png 512w, https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png 300w, https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png 140w, https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png 768w, https://www.relataly.com/wp-content/uploads/2023/04/Colorful_popart_of_programmers_working_on_generative_AI.png 1026w" sizes="(max-width: 383px) 100vw, 383px" /><figcaption class="wp-element-caption">As AI continues to evolve, it is becoming increasingly important for organizations to understand the state of AI adoption in their respective industries. </figcaption></figure>
</div>
</div>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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%">
<h3 class="wp-block-heading">Level 0 &#8211; Unaware</h3>



<p>It may come as a surprise, but not every decision maker is aware of OpenAI&#8217;s existence, despite the hype surrounding AI and OpenAI. Even those who have heard of OpenAI may lack a full understanding of its capabilities and potential impact. Some may mistakenly believe it to be just another AI tool or software, and fail to recognize its unique features and advantages. As a result, decision-makers may question the relevance of OpenAI for their organization, miss out on opportunities to improve their operations, or even enter a state of neglect.</p>



<p>If this situation applies to your organization, it indicates that you have not yet begun your OpenAI journey and are at level 0. </p>



<h3 class="wp-block-heading" id="h-level-1-observing">Level 1 &#8211; Observing</h3>



<p>The first step in adopting OpenAI is understanding its potential benefits and what it means for your organization. Most decision-makers have heard of OpenAI, but not all fully comprehend this technology&#8217;s significance. Level one companies are aware of OpenAI&#8217;s potential but have not taken direct action. They may prefer to wait for competitors to make the first step and observe how they do before taking their own action. </p>



<p>In Switzerland, many business decision-makers hesitate to be the first in the market. There are various reasons, for example, due to concerns such as data privacy or uncertainty around AI services. However, it is crucial to recognize the importance of OpenAI in today&#8217;s competitive landscape and its potential advantages in terms of productivity, automation, and decision-making capabilities.</p>



<h3 class="wp-block-heading">Level 2 &#8211; Exploring </h3>



<p>Many organizations have moved beyond the initial stage of understanding OpenAI and are now focused on identifying suitable use cases. However, this can be challenging as OpenAI enables entirely new applications that were not previously possible. In a recent article, I explored the <a href="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/" target="_blank" rel="noreferrer noopener">value proposition of OpenAI</a> and provided guidance on understanding what makes it unique. This can help organizations prioritize use cases and maximize the potential benefits of the technology.</p>



<p>Early adopters who experiment and learn about the technology will likely have an advantage and be better equipped to develop effective implementation strategies. While risks are associated with adopting new technologies, there are also potential rewards. Companies should consider their competitive position and the risks and benefits of adopting OpenAI in their decision-making process.</p>



<h3 class="wp-block-heading">Level 3 &#8211; Building</h3>



<p>Many organizations in Switzerland have already gained their first hands-on experience with OpenAI. These companies are at level two in their OpenAI journey. They have identified specific use cases for AI and are actively working on developing AI-driven solutions for their customers. Many of the companies at this stage are consulting firms that have participated in Proof of Concepts or built technology demos. </p>



<p>At this stage of their AI journey, organizations are tasked with demonstrating the value of Generative AI to their customers and internal decision-makers. Decision makers want to see that their decision to take the risk with innovation is worth the risk and can provide substantial value. Nonetheless, Level 2 companies are making progress and are working towards incorporating AI into their solutions to drive productivity, automation, and decision-making capabilities.</p>



<h3 class="wp-block-heading">Level 4 &#8211; Gaining Traction</h3>



<p>The fourth level of OpenAI organizations comprises those who have successfully completed their initial OpenAI projects and gained invaluable experience in developing and deploying OpenAI-driven solutions. These organizations have gone beyond experimentation and have started to reap the benefits of OpenAI technologies. By deploying OpenAI use cases, they have been able to obtain feedback from users and stakeholders, allowing them to learn and improve their solutions further.</p>



<p>The feedback obtained from users and stakeholders is essential in the development of new solutions, especially in the case of emerging technologies such as Generative AI. The feedback enables organizations to directly learn from their mistakes, identify areas for improvement, and address any issues that may have arisen after go live.</p>



<p>Organizations on level four are eager to build upon their knowledge and often incorporate OpenAI into their products or services. While they may have some employees with experience in OpenAI, they are still learning and refining their skills on a smaller scale. Consulting providers at this level have successfully navigated the complexities of Generative AI for their clients. They are now in high demand, as OpenAI experience is a valuable resource in the market.</p>



<p>Only a few organizations in Switzerland have reached this level, but many more are expected to follow soon.</p>



<h3 class="wp-block-heading">Level 5 &#8211; Proven Track Record</h3>



<p>The fifth level of OpenAI adoption includes those organizations that are advanced in their adoption journey. They have integrated AI into various aspects of their products or professional services and have a proven track record of successfully implementing AI solutions for their customers. Equipped with extensive experience in Generative AI, these organizations will likely be looking to scale their capabilities even further. </p>



<p>At this stage, the focus is no longer solely on implementation but on using the OpenAI experience to create a competitive advantage. This can be achieved in various ways, such as providing an exceptional customer experience, which allows organizations to charge a premium. Or by increasing productivity, allowing organizations to capitalize on significantly lower costs than their competition.</p>



<p>I would argue that almost no company in Switzerland is at this level, but I am confident we may see some emerge in the coming months.</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">Outlook &#8211; Accelerating OpenAI Adoption in Switzerland and Beyond</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Looking ahead, it is clear that the trend toward Generative AI adoption will continue accelerating in the Swiss economy. In the coming months, more organizations will incorporate OpenAI into their products and services, with a growing number of companies launching GPT-powered applications. As a result, organizations that have not yet begun their AI journey may soon feel pressure to catch up, especially as the public becomes increasingly aware of the value that Generative AI can bring to customers and internal operations. Staying ahead of the curve is crucial to remain competitive in today&#8217;s fast-paced business environment, but it will require investments in AI-driven innovation. </p>



<p>At the same time, we see governments stepping up their efforts to use Ai to remain competitive on a global level.</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="512" height="505" data-attachment-id="13491" data-permalink="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png" data-orig-size="1026,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="Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png" src="https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9-512x505.png" alt="" class="wp-image-13491" srcset="https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png 512w, https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png 300w, https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png 768w, https://www.relataly.com/wp-content/uploads/2023/04/Flo7up_colorful_popart_of_the_swiss_economy_adoption_generative_5787da25-9d15-4578-ab31-4356ad1811b9.png 1026w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">Looking ahead, it is clear that the trend toward OpenAI adoption will continue accelerating in the Swiss economy.</figcaption></figure>
</div>
</div>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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%">
<h2 class="wp-block-heading" id="h-summary">Summary</h2>



<p>This article has discussed the state of OpenAI adoption in the Swiss economy. We have outlined different levels of adoption and experience in OpenAI &#8211; specifically with large language models such as ChatGPT. In summary, some organizations are just starting to explore the potential of AI, while a few leaders already have a proven track record implementing it. Many organizations are still looking for ways to leverage AI to enhance their business processes, provide predictive insights, and drive better decision-making capabilities. With OpenAI&#8217;s advanced technology and supportive community, the possibilities for AI-driven innovation are endless.</p>



<p>I hope this article was helpful. I am curious &#8211; where is your organization standing? Does the situation in your country look different? Let me know in the comments!</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">Sources and Further Reading</h2>



<ul class="wp-block-list">
<li>ChatGPT helped to revise this article. </li>



<li>Images generated with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></li>



<li><a href="https://hai.stanford.edu/news/2023-state-ai-14-charts" target="_blank" rel="noreferrer noopener">Stanford.edu 2023 State of AI in 14 Charts</a> </li>
</ul>
<p>The post <a href="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/">How Far are Swiss Enterprises in Adopting OpenAI&#8217;s GPT Models?</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">13486</post-id>	</item>
		<item>
		<title>What is the Business Value of ChatGPT and other Large Generative Language Models?</title>
		<link>https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/</link>
					<comments>https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/#respond</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Sat, 25 Feb 2023 17:30:59 +0000</pubDate>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Healthcare]]></category>
		<category><![CDATA[Insurance]]></category>
		<category><![CDATA[Language Generation]]></category>
		<category><![CDATA[Logistics]]></category>
		<category><![CDATA[Manufacturing]]></category>
		<category><![CDATA[OpenAI]]></category>
		<category><![CDATA[Sentiment Analysis]]></category>
		<category><![CDATA[Topic Modelling]]></category>
		<category><![CDATA[Use Cases]]></category>
		<category><![CDATA[AI in E-Commerce]]></category>
		<category><![CDATA[AI in Finance]]></category>
		<category><![CDATA[AI in Insurance]]></category>
		<category><![CDATA[AI in Logistics]]></category>
		<category><![CDATA[AI in Marketing]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=12282</guid>

					<description><![CDATA[<p>OpenAI&#8217;s GPT models, such as Davinci and ChatGPT, have gained recognition for their impressive language generation abilities. However, many of the tasks that GPT models can perform are not entirely new and could have been accomplished by traditional neural network models for some time. In specific tasks such as sentiment analysis, more specialized models could ... <a title="What is the Business Value of ChatGPT and other Large Generative Language Models?" class="read-more" href="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/" aria-label="Read more about What is the Business Value of ChatGPT and other Large Generative Language Models?">Read more</a></p>
<p>The post <a href="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/">What is the Business Value of ChatGPT and other Large Generative Language Models?</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-9d6595d7 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>OpenAI&#8217;s GPT models, such as Davinci and ChatGPT, have gained recognition for their impressive language generation abilities. However, many of the tasks that GPT models can perform are not entirely new and could have been accomplished by traditional neural network models for some time. In specific tasks such as sentiment analysis, more specialized models could outperform GPT-3. So, what distinguishes GPT from other models, and why is it creating so much hype? This question is particularly significant to business stakeholders who are curious about generative AI but are still seeking relevant applications. Understanding GPT&#8217;s value proposition will enable them to articulate the significance of generative AI use cases.</p>



<p>This article aims to dismantle the value proposition of generative language models such as ChatGPT by discussing it along four dimensions: capabilities (1), versatility (2), simplification (3), and ease of use (4). So if you want to understand why your business should care about GPT, this article is for you!</p>



<p>It is worth mentioning that this article does not differentiate between the different GPT models. The term GPT, in this article, refers to ChatGPT and Davinci, which have comparable capabilities. A key difference is that ChatGPT considers the conversation history, while Davinci treats requests entirely isolated from one another.</p>



<h4 class="wp-block-heading">Related articles </h4>



<p>Also: </p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/" target="_blank" rel="noreferrer noopener">9 Powerful Applications of OpenAI’s ChatGPT and Davinci for Your Business</a> </li>



<li><a href="https://www.relataly.com/exploring-the-journey-of-the-swiss-economy-in-adopting-openai-chatgpt-and-co/13486/" target="_blank" rel="noreferrer noopener">Exploring the Journey of the Swiss Economy in Adopting OpenAI&#8217;s ChatGPT and Co</a></li>
</ul>



<p>And if you are interested in implementing OpenAI, check out these Python tutorials:</p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/using-chatgpt-and-other-openai-models-via-apis-in-python/12068/" target="_blank" rel="noreferrer noopener">Using OpenAI GPT with Python</a></li>



<li><a href="https://www.relataly.com/automated-prompt-generation-for-dall-e-using-chatgpt-in-python-a-step-by-step-api-tutorial/12143/" target="_blank" rel="noreferrer noopener">Integrating Dall-E with GPT for Prompt Generation using Python</a></li>
</ul>
</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="507" data-attachment-id="12502" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/diamond-value-business-proposition-python-machine-learning-relataly/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png" data-orig-size="510,507" 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="diamond value business proposition python machine learning relataly" data-image-description="&lt;p&gt;What&amp;#8217;s the value proposition of OpenAI GPT-3? Midjourney relataly.com &lt;/p&gt;
" data-image-caption="&lt;p&gt;What&amp;#8217;s the value proposition of OpenAI GPT-3? Midjourney relataly.com &lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png" src="https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png" alt="What's the value proposition of OpenAI GPT-3? Midjourney relataly.com " class="wp-image-12502" srcset="https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png 510w, https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/diamond-value-business-proposition-python-machine-learning-relataly.png 140w" sizes="(max-width: 510px) 100vw, 510px" /><figcaption class="wp-element-caption">What&#8217;s the value proposition of OpenAI GPT? Image created with <a href="http://www.Midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>
</div>
</div>



<h2 class="wp-block-heading">What&#8217;s the Deal with Large Generative Language Models á la ChatGPT?</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>To understand the value proposition of large generative models, it can be helpful to compare them to Bidirectional Encoder Representations from Transformers <a href="https://towardsdatascience.com/bert-explained-state-of-the-art-language-model-for-nlp-f8b21a9b6270" target="_blank" rel="noreferrer noopener">(BERT) and its variations (ROBERTA, etc.)</a>. </p>



<p>BERT is a powerful and widely used pre-trained language model in natural language processing (NLP). It was developed by Google and released in 2018, and it quickly became one of the most influential NLP models in the field. We can consider it the predecessor of ChatGPT.</p>



<p>One key difference between the two models is in how they process data. GPT&#8217;s sequential processing of input sequences, one token at a time, gives it an advantage over BERT in handling longer and more complex input sequences. This makes GPT better suited for tasks requiring more intricate outputs, such as language translation and dialogue systems. Consequently, GPT is better equipped than BERT for tasks that require generating lengthier and more complex outputs.</p>



<h2 class="wp-block-heading">Generative vs. Discriminative Models</h2>



<p>Generative models like GPT and discriminative models like BERT <a href="https://symbl.ai/blog/gpt-3-versus-bert-a-high-level-comparison/" target="_blank" rel="noreferrer noopener">have fundamental differences in their approach to language processing</a>. While GPT is a large generative language model that generates new text based on input, BERT is a discriminative model that classifies text into predefined categories. While both models have unique strengths and weaknesses, their performance varies based on the task and dataset.</p>



<p>BERT is particularly adept at question answering, text classification, and sentiment analysis, but it may not perform as well at generating new text. On the other hand, GPT is better suited for generating new text and capturing complex language dependencies. This makes it ideal for content generation, language translation, summarization, and question-answering. </p>



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



<p>Another important aspect of GPT&#8217;s training methodology is pre-training. Before being fine-tuned for specific tasks, GPT is pre-trained on a vast amount of data, learning to generate text by predicting the next word in a sentence. </p>



<p>This pre-training phase helps GPT learn grammar, facts about the world, and gives the model even reasoning abilities. This general language understanding serves as a strong foundation for GPT when it comes to solving specific natural language tasks later on. By leveraging this pre-training, GPT can easily adapt to new tasks with relatively less task-specific data. This process, called transfer learning, enables GPT to perform better than other models in various tasks.</p>



<h2 class="wp-block-heading">Performance vs. Capabilities</h2>



<p>Performance and capabilities are distinct factors when evaluating language models. While BERT excels in some applications, GPT&#8217;s strengths lie in its capabilities across various fields, particularly with few-shot or zero-shot learning. By fine-tuning GPT to specific tasks, its performance can be further improved and may likely outperform BERT.</p>



<p>Although GPT is proficient at basic NLP tasks like sentiment analysis and text classification, <a href="https://analyticsindiamag.com/gpt-3-vs-bert-for-nlp-tasks/" target="_blank" rel="noreferrer noopener">performance comparisons</a> show that BERT can achieve similar or better results with less computational complexity in fundamental NLP tasks. However, the performance of GPT-4, which is yet to be seen, may likely outperform BERT in almost any discipline, even without fine-tuning.</p>



<h2 class="wp-block-heading">Unmantling GPTs Value Proposition</h2>



<p>Despite the impressive capabilities of generative language models like ChatGPT, examining their value proposition in more detail is essential. Therefore, this article aims to provide a more nuanced understanding of the value that these models can provide.</p>



<p>Also: <a href="https://www.relataly.com/eliminating-friction-how-openais-gpt-streamlines-online-experiences-and-reduces-the-need-for-google-searches/13171/" target="_blank" rel="noreferrer noopener">Eliminating Friction: How OpenAI’s GPT Streamlines Online Experiences and Reduces the Need for Traditional Search</a></p>
</div>



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



<h3 class="wp-block-heading">#1 Performance</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Large generative language models like ChatGPT offer valuable benefits to businesses through their ability to generate natural language responses similar to those produced by humans. This technology can be used in various ways, such as content generation, customer service, and marketing.</p>



<p>Businesses can use generative language models to produce high-quality content quickly and efficiently. For example, a news organization could use ChatGPT to generate news articles or summaries based on current events. Similarly, a company could use this technology to create product descriptions, emails, or even social media posts.</p>



<p>Generative language models can also be employed to provide customers with instant responses to their queries, which could be particularly useful for businesses that receive a high volume of customer inquiries or support requests. ChatGPT can be trained to provide accurate and helpful responses to frequently asked questions or to engage in more complex conversations with customers.</p>



<p>In marketing, generative language models can be used to create personalized content for customers by analyzing customer data to generate customized marketing messages or entire campaigns that resonate with individual customers&#8217; preferences and interests.</p>



<p>ChatGPT&#8217;s ability to handle longer input sequences enables it to maintain context and understand the sentiment behind a piece of text more effectively. The use of self-attention mechanisms allows ChatGPT to focus on the most relevant parts of the input when generating its predictions, leading to more accurate results in tasks like sentiment analysis. Additionally, ChatGPT&#8217;s increased capacity allows it to learn more complex patterns and representations, resulting in improved performance across various natural language tasks.</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="502" height="512" data-attachment-id="13200" data-permalink="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/flo7up_a_running_robot_winning_a_marathon/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png" data-orig-size="1008,1028" 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="Flo7up_a_running_robot_winning_a_marathon" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png" src="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon-502x512.png" alt="Generative language models such as ChatGPT have several advantages over traditional machine learning approaches, including their ability to handle longer inputs." class="wp-image-13200" srcset="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png 502w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png 294w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png 768w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_running_robot_winning_a_marathon.png 1008w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption class="wp-element-caption">Generative language models such as ChatGPT have several advantages over traditional machine learning approaches, including their ability to handle longer inputs. Created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading">#2 Versatility</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>For smaller organizations with limited data science resources, implementing AI in their processes can be a significant challenge. Developing specialized models for tasks such as summarization, classification, and translation requires substantial expertise and training data. In many organizations, these resources are not readily available, which can slow down development processes and hinder innovation.</p>



<p>GPT&#8217;s versatility addresses this challenge by offering a single API that can perform <a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/" target="_blank" rel="noreferrer noopener">these tasks and more</a>. This enables smaller organizations to benefit from AI without the need to invest in extensive data science resources. By automating and streamlining their workflows, these organizations can save time and resources, allowing them to focus on their core activities. </p>



<p>A lot of the versatility comes from GPT, allowing for zero-shot or few-shot predictions. Zero-shot learning is a technique where a model is able to perform a task without any explicit training examples. This is possible because GPT was pre-trained on almost the entire text available from the public internet. It allows the model to make inferences based on the patterns it has learned from the data. Few-shot learning, on the other hand, involves training a model on a small amount of data. </p>



<p>It&#8217;s important to note that using GPT also poses potential risks, such as biases and inaccuracies. Smaller organizations may lack the resources to address these risks and, therefore, must evaluate GPT&#8217;s performance carefully before integrating it into their processes. Nonetheless, the availability of GPT represents a significant opportunity for smaller organizations to leverage AI in their operations and remain competitive in their respective markets.</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="512" height="283" data-attachment-id="13243" data-permalink="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-copy-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png" data-orig-size="1426,788" 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="Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min-512x283.png" alt="OpenAI GPT-3 is highly versatile and makes it easy to leverage the power of AI for various tasks. Image Source: Created with Midjourney - An AI that creates images using text." class="wp-image-13243" srcset="https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png 512w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png 768w, https://www.relataly.com/wp-content/uploads/2023/03/Flo7up_a_robot_octopus_wielding_tools_in_his_various_hands_in_f_27e54910-2ee1-431c-96e5-0845e0415ffe-Copy-min.png 1426w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">OpenAI GPT is highly versatile and makes it easy to leverage the power of AI for various tasks. Image Source: Created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading" id="h-3-simplifying-complex-processes">#3 Simplifying Complex Processes</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>One of the major benefits of ChatGPT and Davinci is their ability to perform multiple tasks within a single request. For instance, a prompt to a GPT model that asks for a summary in five sentences and a German translation can effectively combine the tasks of summarization and translation. This multi-tasking capability streamlines the development process and simplifies complex procedures.</p>



<h4 class="wp-block-heading">GPT &#8211; the Swiss Army Knife of AI</h4>



<p>Imagine a situation where a process involves several tasks like translating customer requests, checking specific information, categorizing, and summarizing them. Traditional models would need the creation, integration, security, and maintenance of four separate models. However, a multi-purpose language model like GPT can handle all these tasks in just one request all at once.</p>



<p>While other models like BERT can perform tasks such as language translation and text classification, the ability of ChatGPT and Davinci to execute multiple tasks at once sets them apart. By moving some of the complexity into a prompt for a model, organizations can adapt more easily to changing requirements and become more agile.</p>



<p>ChatGPT and Davinci can be seen as the Swiss Army Knives of AI language models. They offer versatile and adaptable solutions for a wide range of tasks. Much like a Swiss Army Knife, these multi-purpose models provide organizations with a valuable tool that simplifies and streamlines complex procedures, making them an essential asset in today&#8217;s rapidly evolving world.</p>



<h4 class="wp-block-heading">An Ongoing shift Toward AI</h4>



<p>As generative AI technology continues to advance, an increasing number of organizations are likely to rely on these models to help simplify their complex processes. This shift can lead to improved efficiency, cost savings, and enhanced accuracy, enabling businesses to focus on their strategic objectives. However, this transition also brings potential risks and challenges, such as ensuring ethical AI usage and addressing the possibility of job displacement. Organizations must carefully consider these factors as they integrate AI into their operations.</p>



<p>The multi-tasking abilities of ChatGPT and Davinci offer a distinct advantage for organizations aiming to streamline intricate processes and boost efficiency. By delegating some of the process complexity to these models, businesses can adapt more rapidly to evolving requirements and improve their overall agility. Nevertheless, it is essential for organizations to assess the potential challenges, ethical considerations, and workforce implications as they incorporate AI into their operations. By doing so, they can make well-informed decisions and develop a balanced approach to harnessing the power of generative AI models, ultimately ensuring sustainable growth and responsible AI integration.</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="837" height="837" data-attachment-id="12234" data-permalink="https://www.relataly.com/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee/" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png" data-orig-size="837,837" 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="flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png" src="https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png" alt="OpenAI GPT-3 offers a unique value proposition that sets it apart from other models. Image created with Midjourney - An AI that creates images using text." class="wp-image-12234" srcset="https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png 837w, https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png 140w, https://www.relataly.com/wp-content/uploads/2023/02/flip7up_a_craftsman_robot_with_a_hammer_striking_a_nail_3c6f0c2e-4c35-4ff0-bb8c-cc7552d74cee.png 768w" sizes="(max-width: 837px) 100vw, 837px" /><figcaption class="wp-element-caption">OpenAI GPT offers a unique value proposition that sets it apart from other models. Image created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney</a> &#8211; An AI that creates images using text.</figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading" id="h-4-ease-of-use">#4 Ease of Use</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>A major advantage of OpenAI, including GPT, is its ability to lower the entry barrier for organizations using AI. GPT is accessible to developers and data scientists of all skill levels, making it easier for organizations to automate activities without extensive expertise. Its capacity to generalize to new cases (zero or few-shot learning) allows users to start with OpenAI even with little or no data. This is particularly beneficial for smaller customers. They may lack resources for in-house predictive model development, as well as larger customers who can speed up their development processes using a single multi-purpose AI.</p>



<p>Moreover, OpenAI operates as a cloud service, eliminating the need for organizations to build and maintain their own AI infrastructure for GPT model development and hosting. Instead, they can utilize the cloud-based service provided by OpenAI, making it more convenient and cost-effective to begin using AI. This approach allows businesses to concentrate on their core competencies while leveraging GPT&#8217;s power to enhance operations and drive innovation.</p>



<p>The scalability of Azure OpenAI also empowers businesses to start with a proof-of-concept project and scale up as required. This approach enables organizations to experiment with AI without committing to a large initial investment. Utilizing a single model for various purposes significantly accelerates the creation of POCs. Once a solution demonstrates its value, organizations can later fine-tune the process using more specialized models.</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="511" height="511" data-attachment-id="12304" data-permalink="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png" data-orig-size="511,511" 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="gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png" src="https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png" alt="Getting started with OpenAI GPT-3 is easy, as it allows developers to interact with the models using natural language prompts. Image created with Midjourney - An AI that creates images using text." class="wp-image-12304" srcset="https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png 511w, https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/gilgerardo_web_designer_working_on_a_laptop_on_a_desk_in_the_ci_d4742d61-651b-4ccc-83be-402cce11cc35.png 140w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption class="wp-element-caption">Getting started with OpenAI GPT is easy, as it allows developers to interact with the models using natural language prompts. Image created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney </a>&#8211; An AI that creates images using text.</figcaption></figure>
</div>
</div>



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



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>This article has explored the unique value proposition of OpenAI&#8217;s GPT in a business context, highlighting its enhanced language capabilities (1), versatility in use (2), complexity reduction (3), and lower entry barriers for AI adoption (4). These aspects make GPT a groundbreaking development in the field of artificial intelligence, particularly within natural language processing (NLP).</p>



<p>GPT has demonstrated impressive performance across a wide array of applications, such as chatbots, personalized content generation, question-answering systems, and intricate data interpretation. While other NLP models can accomplish some tasks carried out by GPT, its extensive pre-training on large data sets and ability to manage various domains and tasks render it more flexible and powerful. Consequently, GPT&#8217;s potential to streamline workflows and reduce costs is indisputable.</p>



<p>As OpenAI continues to advance and refine its technology, we can anticipate even more innovative use cases for GPT in the future. This ongoing evolution will undoubtedly contribute to the growing significance of GPT in shaping the AI landscape and revolutionizing the way businesses harness the power of artificial intelligence.</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="1024" data-attachment-id="12307" data-permalink="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/openai-sets-sail-for-wide-spread-adoption-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png" data-orig-size="1024,1024" 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="OpenAI-sets-sail-for-wide-spread-adoption-2" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png" src="https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2-1024x1024.png" alt="OpenAI sets sail to transform various industries, as it offers a strong value proposition. " class="wp-image-12307" srcset="https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png 1024w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png 140w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAI-sets-sail-for-wide-spread-adoption-2.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">OpenAI&#8217;s GPT offers businesses a substantial value proposition, thus setting sail for massive adoption in various industries. Image Source: Created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>
</div>
</div>



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



<ul class="wp-block-list">
<li><a href="https://www.reuters.com/technology/chatgpt-sets-record-fastest-growing-user-base-analyst-note-2023-02-01/" target="_blank" rel="noreferrer noopener">Reuter.com/chatgpt-sets-record-fastest-growing-user-base-analyst/</a></li>



<li><a href="http://analyticsindiamag.com/gpt-3-vs-bert-for-nlp-tasks/" target="_blank" rel="noreferrer noopener">Analyticsindiamag.com/gpt-vs-bert-for-nlp-tasks/</a></li>



<li><a href="https://symbl.ai/blog/gpt-3-versus-bert-a-high-level-comparison/" target="_blank" rel="noreferrer noopener">Symbl.ai/blog/gpt-versus-bert-a-high-level-comparison/</a></li>



<li><a href="https://platform.openai.com/docs/guides/completion/prompt-design" target="_blank" rel="noreferrer noopener">OpenAI.com/prompt-design</a></li>



<li><a href="https://www.relataly.com/using-chatgpt-and-other-openai-models-via-apis-in-python/12068/" target="_blank" rel="noreferrer noopener">Relataly.com &#8211; Using OpenAI GPT-3 with Python</a></li>



<li>OpenAI ChatGPT was used to revise this article</li>



<li><a href="https://www.relataly.com/automated-prompt-generation-for-dall-e-using-chatgpt-in-python-a-step-by-step-api-tutorial/12143/" target="_blank" rel="noreferrer noopener">Relataly.com &#8211; Integrating Dall-E with GPT-3 for Prompt Generation using Python</a></li>



<li>Images generated with <a href="https://www.midjourney.com/app/">Midjourney</a> </li>
</ul>
<p>The post <a href="https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/">What is the Business Value of ChatGPT and other Large Generative Language Models?</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/openai-gpt-chatgpt-in-a-business-context-whats-the-value-proposition/12282/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12282</post-id>	</item>
		<item>
		<title>9 Business Use Cases of OpenAI&#8217;s ChatGPT</title>
		<link>https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/</link>
					<comments>https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/#respond</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Sat, 25 Feb 2023 16:30:48 +0000</pubDate>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Healthcare]]></category>
		<category><![CDATA[Insurance]]></category>
		<category><![CDATA[Language Generation]]></category>
		<category><![CDATA[Logistics]]></category>
		<category><![CDATA[Manufacturing]]></category>
		<category><![CDATA[Natural Language Processing]]></category>
		<category><![CDATA[OpenAI]]></category>
		<category><![CDATA[Retail]]></category>
		<category><![CDATA[Telecommunications]]></category>
		<category><![CDATA[Use Cases]]></category>
		<category><![CDATA[AI in E-Commerce]]></category>
		<category><![CDATA[AI in Finance]]></category>
		<category><![CDATA[Beginner Tutorials]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=12200</guid>

					<description><![CDATA[<p>You haven&#8217;t had enough of the recent hype about OpenAI? Fantastic! Let&#8217;s explore the business use cases for ChatGPT and other Large Language Models (LLMs). ChatGPT is often considered the beginning of a new era of AI adoption. A growing number of ChatGPT users are now using AI in their personal workflows. However, adoption in ... <a title="9 Business Use Cases of OpenAI&#8217;s ChatGPT" class="read-more" href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/" aria-label="Read more about 9 Business Use Cases of OpenAI&#8217;s ChatGPT">Read more</a></p>
<p>The post <a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/">9 Business Use Cases of OpenAI&#8217;s ChatGPT</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-9d6595d7 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>You haven&#8217;t had enough of the recent hype about OpenAI? Fantastic! Let&#8217;s explore the business use cases for ChatGPT and other Large Language Models (LLMs). ChatGPT is often considered the beginning of a new era of AI adoption. A growing number of <a href="https://www.reuters.com/technology/chatgpt-sets-record-fastest-growing-user-base-analyst-note-2023-02-01/" target="_blank" rel="noreferrer noopener">ChatGPT users</a> are now using AI in their personal workflows. However, adoption in a business context is lagging behind. Although decision-makers around the globe are highly interested in using OpenAI&#8217;s LLMs, their knowledge of use cases and implementation strategies is often vague. This article aims to offer some guidance on the topic and inspire by sharing insights from recent conversations with decision-makers and industry experts. We present nine Applications for GPT for which we can expect to see increasing adoption in the coming month:</p>





<p>Let&#8217;s discuss these cases in more detail. </p>



<p>Also: <a href="https://www.relataly.com/mastering-prompt-engineering-for-chatgpt-a-practical-guide-for-businesses/13134/" target="_blank" rel="noreferrer noopener">Mastering Prompt Engineering for ChatGPT for Business Use</a></p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<div class="wp-block-kadence-infobox kt-info-box_d5a753-ee"><span class="kt-blocks-info-box-link-wrap info-box-link kt-blocks-info-box-media-align-top kt-info-halign-center"><div class="kt-blocks-info-box-media-container"><div class="kt-blocks-info-box-media kt-info-media-animate-none"><div class="kadence-info-box-image-inner-intrisic-container"><div class="kadence-info-box-image-intrisic kt-info-animate-none"><div class="kadence-info-box-image-inner-intrisic"><img decoding="async" data-attachment-id="12485" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/chatgpt-logo-02afa704b5-seeklogo-com/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/chatgpt-logo-02AFA704B5-seeklogo.com_.png" data-orig-size="296,300" 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="chatgpt-logo-02AFA704B5-seeklogo.com" data-image-description="&lt;p&gt;chatGPT logo&lt;/p&gt;
" data-image-caption="&lt;p&gt;chatGPT logo&lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/chatgpt-logo-02AFA704B5-seeklogo.com_.png" src="https://www.relataly.com/wp-content/uploads/2023/02/chatgpt-logo-02AFA704B5-seeklogo.com_.png" alt="chatGPT logo" width="296" height="300" class="kt-info-box-image wp-image-12485"/></div></div></div></div></div><div class="kt-infobox-textcontent"><h5 class="kt-blocks-info-box-title">What is it with OpenAI and ChatGPT?</h5><p class="kt-blocks-info-box-text">If you&#8217;ve been frozen in Carbonite for the past six months, you may have missed the whole hype on OpenAI and ChatGPT. Let&#8217;s bring you up to speed!<br/><br/>ChatGPT is a member of the family of GPT language models, which were developed by OpenAI. GPT stands for &#8220;Generative Pretrained Transformers.&#8221; These models are known for their ability to understand and generate human-like text. One of the key strengths of ChatGPT is its ability to understand the context of a conversation and generate appropriate responses. Although it&#8217;s not perfect and can sometimes make mistakes, it is a very powerful tool for generating and interpreting natural language text. </p></div></span></div>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Top Business Applications for Generative Language Models</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>The coming month will be exciting as we can expect to see the first wave of OpenAI use cases being implemented. So what can we expect? In the current economic situation, cost reduction is top of mind for many decision-makers. Business efforts will, therefore, likely focus on improving and optimizing the existing business processes rather than exploring new applications.</p>



<p>One of the critical reasons for this approach is that organizations need to gain experience with generative models to lay the foundation for working on more innovative solutions in the future. While traditional machine learning techniques are valuable for many applications, they have limitations when it comes to implementing OpenAI&#8217;s generative language models. </p>



<p>OpenAI&#8217;s GPT models are a form of general-purpose AI that uses a different approach to machine learning. Implementing these models requires new skills and knowledge. For example, prompt design and rethinking existing processes are crucial for effectively using OpenAI&#8217;s capabilities. This means that organizations need to invest in training and develop new expertise to leverage the new technology fully. </p>



<p>Before delving into use cases, it&#8217;s important to note that the categories were deliberately chosen to be generic and relevant across various industries. Additionally, to make the use cases as practical as possible, we&#8217;ve included examples for prompts and responses. For simplicity, this article doesn&#8217;t differentiate between various GPT-3 models but rather focuses on the use cases for ChatGPT and Davinci, which have similar capabilities. The primary distinction between the two models is that ChatGPT keeps track of conversation history, while Davinci treats each request separately.</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 is-style-default"><img decoding="async" width="1024" height="730" data-attachment-id="12257" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/openai-business-use-cases-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png" data-orig-size="1111,792" 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="OpenAi business use cases-min" data-image-description="&lt;p&gt;OpenAI ChatGPT Business Use Cases&lt;/p&gt;
" data-image-caption="&lt;p&gt;OpenAI ChatGPT Business Use Cases&lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png" src="https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min-1024x730.png" alt="OpenAI ChatGPT Business Use Cases" class="wp-image-12257" srcset="https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png 1024w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png 768w, https://www.relataly.com/wp-content/uploads/2023/02/OpenAi-business-use-cases-min.png 1111w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">OpenAI ChatGPT has various business use cases; not all are new. Image Source: Created with <a href="https://www.midjourney.com/app/" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-1-text-summarization">1. Text Summarization</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Today&#8217;s fast-paced business environment confronts organizations with an overwhelming amount of text and documents to process. From customer requests to contracts and product information, employees often spend countless hours sifting through information to understand and extract relevant insights. The inability to efficiently process text-based data can cause delays in critical business processes, leading to reduced productivity and increased costs. </p>



<p>OpenAI&#8217;s text summarization capabilities are a game-changer for businesses that need to process large amounts of text. By summarizing dense documents into a few key points or even a single title, businesses can increase process efficiency and improve decision-making. </p>



<p>Text summarization is helpful in various areas. For example, customer service, where customer inquiries via email can be numerous and time-consuming to address. In many cases, only a part of a conversation is relevant to the business, and employees spend a lot of time sifting through customer emails and chat messages. By using OpenAI, customer service representatives can quickly summarize the content of customer emails and identify the key issues that need to be addressed. This form of summarization can lay the foundation for delegating tasks to teams and individuals effectively. </p>
</div>



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



<h4 class="wp-block-heading">Example of GPT-3 Based Summarization</h4>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong><strong>Prompt</strong></strong><br>Summarize the following text into three sentences, each with a maximum of 20 words: <a href="https://en.wikipedia.org/wiki/Reinforcement_learning" target="_blank" rel="noreferrer noopener">https://en.wikipedia.org/wiki/Reinforcement_learning</a></p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>Reinforcement learning is an area of machine learning concerned with how software agents ought to take actions in an environment so as to maximize some notion of cumulative reward. Reinforcement learning is different from supervised learning as there is no labelled input/output pair. It can be applied to various real-world scenarios such as game playing, robotics, recommendation systems, and even in autonomous driving</p>
</div>



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



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-2-message-triage-and-other-types-of-text-classification">2. Message Triage and Other Types of Text Classification</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>The modern work environment is characterized by work sharing and specialization. However, this often leads to tasks landing on someone&#8217;s desk who may not be the best person to handle them, leading to delays in completing the task. This is where GPT models can be particularly useful. These models can classify text into categories, allowing organizations to automate the routing of incoming messages to the appropriate person or department. Prediction accuracy will benefit when the models are fine-tuned for a particular domain or industry. </p>



<p>Implementing GPT models for classification can yield significant benefits for organizations, enabling them to save time and resources while ensuring that messages and tasks are directed to the right person or department. For instance, organizations can use generative AI for email triage and prioritization by categorizing incoming messages and assigning them to specialized service teams, such as contract inquiries, relocations, claim-related issues, and general complaints. </p>



<p>In addition, sentiment analysis can be employed to gauge customer satisfaction or dissatisfaction in social media statements. Organizations can start with a semi-automated process, where they use OpenAI to assign labels to text, and a human then makes the final decision on who should handle the task. This can lead to increased efficiency and accuracy, as well as reduced response times and improved customer satisfaction.</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="761" height="506" data-attachment-id="12500" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/tiny_construction_workers_working_on_piles_of_huge_documents-2-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/tiny_construction_workers_working_on_piles_of_huge_documents-2-min.png" data-orig-size="761,506" 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="tiny_construction_workers_working_on_piles_of_huge_documents (2)-min" data-image-description="&lt;p&gt;tiny_construction_workers_working_on_piles_of_huge_documents relataly midjourney&lt;/p&gt;
" data-image-caption="&lt;p&gt;tiny_construction_workers_working_on_piles_of_huge_documents relataly midjourney&lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/tiny_construction_workers_working_on_piles_of_huge_documents-2-min.png" src="https://www.relataly.com/wp-content/uploads/2023/02/tiny_construction_workers_working_on_piles_of_huge_documents-2-min.png" alt="tiny_construction_workers_working_on_piles_of_huge_documents relataly midjourney chatGPT OpenAI GPT-3" class="wp-image-12500" srcset="https://www.relataly.com/wp-content/uploads/2023/02/tiny_construction_workers_working_on_piles_of_huge_documents-2-min.png 761w, https://www.relataly.com/wp-content/uploads/2023/02/tiny_construction_workers_working_on_piles_of_huge_documents-2-min.png 300w" sizes="(max-width: 761px) 100vw, 761px" /><figcaption class="wp-element-caption">Processing large amounts of documents and text is a major pain point in many organizations. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<h4 class="wp-block-heading">Example of GPT-3 Based Message Triage</h4>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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="has-contrast-3-color has-base-3-background-color has-text-color has-background has-medium-font-size"><strong><strong>Prompt</strong></strong><br>Classify the following news article into 1 of the following categories: categories: [Business, Tech, Politics, Sport, Entertainment] news article: Donna Steffensen Is Cooking Up a New Kind of Perfection. The Internet’s most beloved cooking guru has a buzzy new book and a fresh new perspective: Classified category:</p>



<div style="height:0px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>Entertainment</p>
</div>



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



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">3. Completeness of Information Checks</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Another challenge that many businesses face when processing natural language is incomplete information. For example, companies receive customer inquiries and orders via email or telephone. Customers may submit requests via email, social media, or telephone, and while it is convenient for them to state their issue in natural language, the messages may lack the necessary information to process their request further. This may include missing product or service information when the customer states his order, address changes where the new address is missing, or inquiries with missing order or ticket numbers. In these cases, a person must first reach out to the customer to collect the missing information and then again check if the information has been completed. </p>



<p>OpenAI can help to identify missing information and streamline information processing. For example, when a customer submits an order request via email, social media, or telephone, OpenAI can analyze the message and identify any missing product or service information, address changes, or order and ticket numbers. This can help customer service teams quickly address the issue and fulfill the request, ultimately improving customer satisfaction and loyalty. </p>



<p>If the AI identifies missing information, it can directly reach out to the customer to request it, enhancing the process efficiency even further. Additionally, combining OpenAI&#8217;s capabilities with text classification can streamline the process by automatically categorizing and prioritizing requests.</p>



<h4 class="wp-block-heading">Example of GPT-3 Based Completeness of Information Checks</h4>



<div class="wp-block-kadence-column kadence-column_3ae8f6-68"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong>Prompt</strong><br>Determine if the numeric 5-digit claim number is present in the text below. Limit your answer to one of the following categories: [Yes, No] Text: &#8220;Awful airline! I have emailed you over 5 times over the past few months regarding my lost bag claim. I’ve included claim number, and details and I simply never get an answer. What a joke.&#8221; Classified category:</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>No.</p>
</div></div>
</div>



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



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-4-personalized-communication">4. Personalized Communication</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Personalized communication is key for businesses to achieve customer experience and satisfaction because it demonstrates that the company values each customer as an individual with unique needs and preferences. By customizing communication, businesses can provide targeted messages and recommendations that are relevant to each customer, making them feel seen and understood. This can lead to increased engagement, loyalty, and improved customer satisfaction. However, creating personalized communication usually takes a lot of time and resources. This is where GPT models can step in. </p>



<p>ChatGPT offers businesses the opportunity to enhance customer satisfaction, engagement, and sales through personalized communication. The model can generate individualized email campaigns, social media posts, and website/app experiences, creating a tailored and unique interaction for each customer. </p>



<p>As businesses begin to implement personalized communication, it may be beneficial to conduct a test phase during which humans review generated messages to ensure accuracy and relevance. Additionally, businesses can provide ChatGPT with additional information on customers, such as past purchases or preferences, to personalize messages further and increase the effectiveness of the communication strategy.</p>



<h4 class="wp-block-heading">Example of a GPT Prompt for Personalized Communication</h4>



<div class="wp-block-kadence-column kadence-column_b0b3a0-4b"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong>Prompt</strong><br>Write a gentle answer to this customer request: Mr. Jong: I can’t believe I thought this was a quality company &#8211; I’m still waiting for my order despite being told over and over again that it would be delivered within 24 hours, only for me to have to chase again. So disappointed, don’t trust this company to fulfil orders as they say they will, and customer service haven’t helped at all.</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background has-medium-font-size"><strong>Response</strong> <br>Dear Mr. Jong,<br><br>I am sorry to hear that you have had a negative experience with our company. I can understand your frustration with the delay in receiving your order despite being promised a 24-hour delivery.<br><br>Please know that this is not the level of service that we strive to provide our customers. We take pride in ensuring that all our orders are fulfilled promptly and efficiently.<br><br>I would like to assure you that we are investigating this matter, and we will take the necessary steps to ensure that this doesn&#8217;t happen again in the future.<br><br>We value your business and appreciate your feedback. Our customer service team is always available to help and address any concerns you may have. Please don&#8217;t hesitate to reach out to us if you need any assistance.<br><br>Thank you for bringing this to our attention, and I hope we can earn back your trust and continue to serve you in the future.<br><br>Best regards,<br><br>[Your Name]<br></p>
</div></div>
</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="504" height="503" data-attachment-id="12949" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png" data-orig-size="504,503" 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="a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png" src="https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png" alt="" class="wp-image-12949" srcset="https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png 504w, https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/a_happy_grandpa_receiving_a_personalized_letter_white-relataly-gpt3-openai-personalzed-communicationi.png 140w" sizes="(max-width: 504px) 100vw, 504px" /><figcaption class="wp-element-caption">Organizations can use GPT-3 to personalize customer interactions, which is crucial in delivering remarkable experiences. Image generated with Midjourney. </figcaption></figure>
</div>
</div>



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-5-document-comparison">5. Document Comparison</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>ChatGPT can help businesses to identify differences and similarities between two documents. This feature can be particularly useful in situations where businesses need to ensure the authenticity of important documents or when multiple collaborators work on the same document. For instance, a law firm can use ChatGPT to compare two versions of a contract and highlight any discrepancies or unusual changes. Additionally, ChatGPT can group similar documents together and identify instances of plagiarism, redundant information, or conflicting statements, which can save time and improve accuracy. </p>



<p>Areas, where document comparison with GPT models is particularly useful, include underwriting, purchasing, and contract management, especially in legal and contractual matters such as comparing versions of contracts, identifying unauthorized changes or unusual deviations from the norm, and ensuring compliance with regulations. </p>



<p>For example, in the insurance industry, underwriters can use ChatGPT to compare policy documents and ensure that there are no inconsistencies or errors in coverage. Purchasers can use ChatGPT to compare supplier contracts and ensure that prices, terms, and conditions are consistent across multiple agreements. In contract management, ChatGPT can help businesses track changes made to a contract over time and ensure that all parties are adhering to the agreed-upon terms. By utilizing ChatGPT for document comparison, businesses can maintain document integrity and improve their overall efficiency.</p>



<h4 class="wp-block-heading">Example of a Prompt for Document Comparison</h4>



<div class="wp-block-kadence-column kadence-column_80cf9d-5f"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong><strong>Prompt</strong></strong><br>Compare the following two privacy statements and explain the difference:<br>Text 1: This website uses cookies, as do many other websites. Cookies are used to store information about visitors, including their preferences and which pages they have accessed or visited on the website. This information is used to optimize the user experience by customizing the content of our web pages based on the visitor&#8217;s browser type and other information.<br>Text 2: Like any other website, this website uses ‘cookies.’ These cookies are used to store information, including visitors’ preferences and the pages on the website that the visitor accessed or visited. The information is used to optimize the users’ experience by customizing our web page content based on visitors&#8217; browser type and/or other information.<br>We will definitely sell your information.</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong><strong>Response</strong></strong><br>There is a clear difference between the two privacy statements. Text 1 does not mention anything about selling the visitor&#8217;s information, while Text 2 includes the sentence &#8220;We will definitely sell your information.&#8221; This indicates that the website may not have ethical or lawful practices when it comes to handling visitor information, and it could potentially violate privacy laws. Additionally, Text 1 appears to be more professional and straightforward, while Text 2 includes a grammatical error in the first sentence. However, both texts mention the use of cookies to store visitor information and optimize the user experience.<br></p>
</div></div>
</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="512" height="510" data-attachment-id="13186" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/openai-robot-comparing-documents-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png" data-orig-size="1024,1020" 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="openai-robot-comparing-documents-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min-512x510.png" alt="Generative AI can compare documents and spot differences or deviations from the norm. ChatGPT robot colorful pop art" class="wp-image-13186" srcset="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png 512w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png 140w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png 768w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-comparing-documents-min.png 1024w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">Generative AI can compare documents and spot differences or deviations from the norm.</figcaption></figure>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-6-reasoning-and-question-answering-over-a-knowledge-base">6. Reasoning and Question Answering over a Knowledge Base</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>OpenAI&#8217;s advanced machine learning models, such as the GPT series, have proven to be powerful tools for analyzing complex information. These can be either structured or unstructured data in individual documents or a comprehensive knowledge base. </p>



<p>Take financial data, for example. Balance statements can be a nightmare to interpret manually, but with OpenAI&#8217;s natural language processing, companies can automatically pinpoint trends and crucial information, making it easier to digest and act on financial data. And that&#8217;s just the beginning. By enhancing their solutions with techniques for summarization or advanced prompt engineering, organizations can generate complete reports with tables, further simplifying the digestion of complex information.</p>



<p>But OpenAI&#8217;s power extends beyond finance. In IoT (Internet of Things), analyzing sensor data can be a mind-bending challenge. OpenAI can help companies make sense of this data in real-time, identifying patterns and anomalies that might have otherwise gone unnoticed. This can be especially valuable in manufacturing, where even minor sensor data variations can significantly impact product quality and efficiency.</p>



<p>Also: <a href="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/" target="_blank" rel="noreferrer noopener">Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python</a> </p>



<p>In short, OpenAI&#8217;s ability to analyze and reason over complex information is nothing short of revolutionary. With this technology, companies can make faster, more informed decisions based on large volumes of data. As technology continues to improve and evolve, the possibilities for AI are limitless. We can expect to see organizations using AI to interpret and analyze even more complex information in the years ahead, paving the way for a brighter, smarter future.</p>



<h4 class="wp-block-heading">Sample Prompt for Reasoning over Structured and Unstructured Data</h4>



<div class="wp-block-kadence-column kadence-column_8145a6-c2"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong>Prompt</strong><br>Assess the financial situation of an enterprise with the following income statement: Income Statement All numbers in thousands Date 9/29/2022 9/29/2021 Total Revenue 387,537,000 394,328,000 Cost of Revenue 220,666,000 223,546,000 Gross Profit 166,871,000 170,782,000 Operating Expense 52,906,000 51,345,000 Operating Income 113,965,000 119,437,000 Total Operating Income as Reported 113,965,000 119,437,000 Total Expenses 273,572,000 274,891,000 Interest Income 3,043,000 2,825,000 Interest Expense 3,240,000 2,931,000 EBIT 116,725,000 122,034,000</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>To assess the financial situation of the enterprise, we need to analyze the income statement and calculate the key financial ratios.<br>First, let&#8217;s look at the income statement. We can see that the company&#8217;s revenue has decreased slightly from 2021 to 2022. However, the cost of revenue has also decreased, resulting in a stable gross profit. Operating expenses have increased slightly, but the operating income remains relatively stable. Interest income has increased slightly, but interest expenses have also increased.<br><br>Now let&#8217;s calculate some financial ratios:<br><br>Gross Profit Margin = (Gross Profit / Total Revenue) x 100<br>= (166,871,000 / 387,537,000) x 100<br>= 43.0%<br>The gross profit margin measures how much profit the company makes after accounting for the cost of goods sold. A gross profit margin of 43.0% indicates that the company is able to generate a decent profit from its sales.<br><br>Operating Profit Margin = (Operating Income / Total Revenue) x 100<br>= (113,965,000 / 387,537,000) x 100<br>= 29.4%<br>The operating profit margin measures how much profit the company makes after accounting for all operating expenses. A margin of 29.4% indicates that the company is able to generate a good amount of profit from its operations.<br><br>&#8230;</p>
</div></div>
</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="508" height="504" data-attachment-id="12931" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/gpt-3-5-can-reason-over-complex-data-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png" data-orig-size="508,504" 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="GPT-3.5-can-reason-over-complex-data-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png" alt="GPT-3.5 can reason over complex data." class="wp-image-12931" srcset="https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png 508w, https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/GPT-3.5-can-reason-over-complex-data-min.png 140w" sizes="(max-width: 508px) 100vw, 508px" /><figcaption class="wp-element-caption">GPT-3.5 can reason over complex data like no other AI before.</figcaption></figure>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-7-query-generation">7. Query Generation </h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>OpenAI ChatGPT can also assist businesses with SQL query generation. This is especially useful for non-technical users, who may not be familiar with SQL syntax or the structure of the database. With ChatGPT, users can simply ask natural language questions about the data they are interested in, and the model can generate the appropriate SQL queries to extract the relevant information.</p>



<p>This has the potential to greatly expand the user base that can directly interact with a database. Additionally, more advanced solutions can provide question-answering functionality based on the data residing in data warehouses (DWH). This can help businesses quickly extract insights and make data-driven decisions without the need for extensive technical knowledge. More advanced solutions will be able to provide question-answering functionality based on the data residing in a DWH, that are often perceived as black boxes by non-tech guys. This will expand the user base that can directly interact with a database and leverage the existing information. </p>



<h4 class="wp-block-heading">Sample Prompt for SQL Query Generation</h4>



<div class="wp-block-kadence-column kadence-column_d778a6-ee"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong>Prompt</strong><br>Tables in the database: Customers, Purchases, Addresses. Tables are linked through a customer_id, which is present in all tables. Given an input question, respond with syntactically correct PostgreSQL. Input: Get the names and addresses of customers who made a purchase in the past week.</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>Here&#8217;s the PostgreSQL query to get the names and addresses of customers who made a purchase in the past week: SELECT c.name, a.address FROM Customers c JOIN Purchases p ON c.customer_id = p.customer_id JOIN Addresses a ON c.customer_id = a.customer_id WHERE p.purchase_date &gt; now() &#8211; interval &#8216;1 week&#8217;; This query uses a JOIN operation to link the Customers, Purchases, and Addresses tables together using the customer_id field. It selects the name and address columns from the Customers and Addresses tables, respectively, and filters the results to include only purchases made in the past week using the WHERE clause with a date comparison.</p>
</div></div>
</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="506" height="512" data-attachment-id="13189" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png" data-orig-size="1024,1036" 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="openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min-506x512.png" alt="openai robot working with a sql database colorful pop art midjourney relataly. If ChatGPT can generate SQL queries, why not use these queries to return a result to the user directly?  " class="wp-image-13189" srcset="https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png 506w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png 297w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png 768w, https://www.relataly.com/wp-content/uploads/2023/03/openai-robot-working-with-a-sql-database-colorful-pop-art-midjourney-relataly-min.png 1024w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption class="wp-element-caption">If ChatGPT can generate SQL queries, why not use these queries to return a result to the user directly?  </figcaption></figure>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-8-language-translation">8. Language Translation</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Another powerful feature is ChatGPT&#8217;s language translation capacity. It can translate text in near real-time, allowing businesses to communicate with customers in their preferred language. While language translation is nothing but new, what sets ChatGPT apart is its ability to seamlessly integrate with any process by simply adding a &#8220;translate to&#8221; command to a prompt. As a result, ChatGPT has the potential to significantly lower language barriers and facilitate communication across international teams and channels.</p>



<p>By using ChatGPT for language translation, businesses can enhance their reach and improve customer satisfaction. ChatGPT&#8217;s language translation capabilities can be used to translate various types of content, such as customer service interactions, website content, and other communication channels. What&#8217;s even more impressive is that ChatGPT supports regional dialects like Swiss-German, making it a versatile tool for organizations operating in multilingual regions. </p>



<h4 class="wp-block-heading">Example of GPT-3 Based Language Translation</h4>



<div class="wp-block-kadence-column kadence-column_e5dfb5-a0 kb-section-dir-vertical"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong><strong>Prompt</strong></strong><br>Translate to Swiss-German: ChatGPT can translate text in real-time, making it possible to communicate with customers in their preferred language. This can help businesses expand their reach and improve customer satisfaction. ChatGPT&#8217;s language translation capabilities are highly accurate and can be used to translate customer service interactions, website content, and other types of communication. By using ChatGPT for language translation, businesses can improve their ability to communicate with a global audience.</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong><br>ChatGPT cha verwendet werde, um Text in Echtzeit z&#8217;übersetze und ermöglicht so d&#8217;Kommunikation mit Kunden in ihre bevorzugte Sprach. Das cha Unternehme helfe, ihre Reichwiti z&#8217;vergrössere und d&#8217;Kundenzufriedeheit z&#8217;verbessere. ChatGPT&#8217;s Sprachübersetzigsfähigkeit isch hochpräzis und cha verwendt werde, um Kundeservice-Interaktione, Website-Inhalte und ander Arten vo Kommunikation z&#8217;übersetze. Durch d&#8217;Verwendig vo ChatGPT für d&#8217;Sprachübersetzig cha d&#8217;Kommunikationsfähigkeit vo Unternehme mit ere globale Zielgruppe verbessert werde.</p>
</div></div>
</div>



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



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-9-content-generation">9. Content Generation</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Content generation is a critical aspect of modern business. It is vital in attracting and engaging customers, building brand awareness, and establishing thought leadership in a particular industry. As such, businesses invest significant resources in creating high-quality content that can capture the attention of their target audience. Such content ranges from blog posts and social media updates to product descriptions and website copy.</p>



<p>However, creating compelling and engaging content is not always easy. Businesses need to produce a large volume of content while ensuring that it is high-quality and relevant to their target audience. This is where OpenAI ChatGPT can assist.</p>



<p>ChatGPT can assist businesses with content generation in a variety of ways. For instance, it can generate unique and engaging content based on specific topics or keywords provided by the user, saving businesses time and resources. Moreover, ChatGPT can be trained to understand a business&#8217;s unique tone and voice. In this way, businesses can ensure that the generated content aligns with their brand and values.</p>



<p>Another way that ChatGPT can assist with content generation is by automating the content curation process. By analyzing and organizing vast amounts of data from various sources, including social media, blogs, news articles, and research papers, ChatGPT can generate curated content that is highly relevant and valuable to a business&#8217;s target audience. Some examples are product recommendations, email campaigns, or chatbot interactions that are tailored to each customer&#8217;s preferences and needs.</p>



<h4 class="wp-block-heading">Example of GPT-3 Based Content Generation</h4>



<div class="wp-block-kadence-column kadence-column_2cfc14-b4"><div class="kt-inside-inner-col">
<p class="has-contrast-3-color has-base-3-background-color has-text-color has-background"><strong>Prompt</strong><br>Generate three creative advertisement slogans for Cereals for the Japanese market. Be as creative as possible. Put in some Pokemon references.</p>



<p class="has-global-color-8-color has-base-3-background-color has-text-color has-background"><strong>Response</strong> <br>&#8220;Gotta catch &#8217;em all, starting with your breakfast bowl! Our cereals are the perfect fuel for your daily adventures!&#8221;<br>&#8220;Our cereals are so delicious, even Pikachu would choose them over berries!&#8221;<br>&#8220;Power up your mornings with our cereals, just like how trainers power up their Pokemon with berries!&#8221;</p>
</div></div>
</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="506" height="512" data-attachment-id="12830" data-permalink="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-midjourney-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min.png" data-orig-size="508,514" 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="orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min-506x512.png" alt="" class="wp-image-12830" srcset="https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min.png 506w, https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min.png 296w, https://www.relataly.com/wp-content/uploads/2023/03/orca-swimming-in-candy-content-generation-gpt-3-openai-relataly-Midjourney-min.png 508w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption class="wp-element-caption">GPT-3 is great at content creation and can also come up with really creative content. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



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



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>This article has outlined nine business applications that are likely to be the focus of the first wave of OpenAI adoption. While some of these applications, such as sentiment analysis, are not entirely new and can be accomplished with traditional NLP models, others like content generation are groundbreaking and were not previously possible.</p>



<p>The hype surrounding GPT models stems from their combination of versatility and performance. Unlike traditional models, generative AI can handle a variety of tasks simultaneously without requiring extensive training data. As a result, businesses can leverage generative AI to develop new use cases, as well as upgrade their existing processes and become more agile by outsourcing some of their decision logic to generative AI.</p>



<p>It will be fascinating to witness the development of generative AI and how it will transform how we work and communicate in the future. The emergence of generative AI is often compared to the introduction of the iPhone, and just as the iPhone has evolved over time, so too will generative AI. If we think of GPT-3 as the third generation of the iPhone, we can only imagine what the future holds.</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">Sources and Further Reading</h2>



<ul class="has-contrast-color has-text-color wp-block-list">
<li><a href="https://www.reuters.com/technology/chatgpt-sets-record-fastest-growing-user-base-analyst-note-2023-02-01/" target="_blank" rel="noreferrer noopener">Reuter.com/chatgpt-sets-record-fastest-growing-user-base-analyst/</a></li>



<li><a href="https://platform.openai.com/docs/guides/completion/prompt-design" target="_blank" rel="noreferrer noopener">OpenAI.com/prompt-design</a></li>



<li>ChatGPT helped to revise some sections of this article.</li>



<li>Images are generated with Midjourney, an AI that generates images from<a href="https://www.midjourney.com/app/"> text.</a></li>



<li><a href="https://www.relataly.com/category/use-case/sentiment-analysis-use-case/" target="_blank" rel="noreferrer noopener">Performing traditional sentiment analysis using Python</a></li>
</ul>



<div class="wp-block-query is-layout-flow wp-block-query-is-layout-flow"></div>



<p>Articles on the practical implementation of OpenAI GPT-3 models via the public API</p>



<ul class="has-contrast-color has-text-color wp-block-list">
<li><a href="https://www.relataly.com/using-chatgpt-and-other-openai-models-via-apis-in-python/12068/" target="_blank" rel="noreferrer noopener">Relataly.com &#8211; Using OpenAI GPT-3 with Python</a></li>



<li><a href="https://www.relataly.com/automated-prompt-generation-for-dall-e-using-chatgpt-in-python-a-step-by-step-api-tutorial/12143/" target="_blank" rel="noreferrer noopener">Relataly.com &#8211; Integrating Dall-E with GPT-3 for Prompt Generation using Python</a></li>
</ul>



<div class="wp-block-query is-layout-flow wp-block-query-is-layout-flow"></div>
<p>The post <a href="https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/">9 Business Use Cases of OpenAI&#8217;s ChatGPT</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/business-use-cases-for-openai-gpt-models-chatgpt-davinci/12200/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12200</post-id>	</item>
		<item>
		<title>Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python</title>
		<link>https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/</link>
					<comments>https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/#comments</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Sun, 08 Jan 2023 20:34:44 +0000</pubDate>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Classification (multi-class)]]></category>
		<category><![CDATA[Cross-Validation]]></category>
		<category><![CDATA[Data Visualization]]></category>
		<category><![CDATA[Exploratory Data Analysis (EDA)]]></category>
		<category><![CDATA[Gradient Boosting]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Manufacturing]]></category>
		<category><![CDATA[Plotly]]></category>
		<category><![CDATA[Predictive Maintenance]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scikit-Learn]]></category>
		<category><![CDATA[Seaborn]]></category>
		<category><![CDATA[Yahoo Finance API]]></category>
		<category><![CDATA[AI in Manufacturing]]></category>
		<category><![CDATA[Classic Machine Learning]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[Multivariate Models]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=10618</guid>

					<description><![CDATA[<p>Predictive maintenance is a game-changer for the modern industry. Still, it is based on a simple idea: By using machine learning algorithms, businesses can predict equipment failures before they happen. This approach can help businesses improve their operations by reducing the need for reactive, unplanned maintenance and by enabling them to schedule maintenance activities during ... <a title="Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python" class="read-more" href="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/" aria-label="Read more about Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python">Read more</a></p>
<p>The post <a href="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/">Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python</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-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Predictive maintenance is a game-changer for the modern industry. Still, it is based on a simple idea: By using machine learning algorithms, businesses can predict equipment failures before they happen. This approach can help businesses improve their operations by reducing the need for reactive, unplanned maintenance and by enabling them to schedule maintenance activities during planned downtime. In this article, we&#8217;ll explore the use of machine learning algorithms to predict machine failures using the robust XGBoost algorithm in Python. By the end of this tutorial, you&#8217;ll have the knowledge and skills to start implementing predictive maintenance in your organization. So, let&#8217;s get started!</p>



<p>We begin by discussing the concept of predictive maintenance and show different ways to implement it. Then we will turn to the coding part in python and implement the prediction model based on machine sensor data. We train a classification model that predicts different types of machine failure using XGBoost.</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="509" height="467" data-attachment-id="12909" data-permalink="https://www.relataly.com/robot-factory-machine-learning-predictive-maintenance-min/" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/robot-factory-machine-learning-predictive-maintenance-min.png" data-orig-size="509,467" 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="robot factory machine learning predictive maintenance-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/robot-factory-machine-learning-predictive-maintenance-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/robot-factory-machine-learning-predictive-maintenance-min.png" alt="Predictive maintenance is a game-changer for the modern industry. Image generated with Midjourney." class="wp-image-12909" srcset="https://www.relataly.com/wp-content/uploads/2023/03/robot-factory-machine-learning-predictive-maintenance-min.png 509w, https://www.relataly.com/wp-content/uploads/2023/03/robot-factory-machine-learning-predictive-maintenance-min.png 300w" sizes="(max-width: 509px) 100vw, 509px" /><figcaption class="wp-element-caption">Predictive maintenance is a game-changer for the modern industry. Image generated with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>
</div>
</div>



<h2 class="wp-block-heading">What is Predictive Maintenance?</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Predictive maintenance is a data-driven approach that uses predictive modeling to assess the state of equipment and determine the optimal timing for maintenance activities. This technique is particularly beneficial in industries that heavily rely on equipment for their operations, such as manufacturing, transportation, energy, and healthcare. Depending on the requirements and challenges of an organization, predictive maintenance may contribute to one or several of the following goals:</p>



<ul class="wp-block-list">
<li><strong>Improve equipment reliability</strong>: By proactively identifying and addressing potential problems with equipment, predictive maintenance can help improve the reliability of the equipment, reducing the risk of unexpected downtime or failure.</li>



<li><strong>Increase efficiency</strong>: Predictive maintenance can help improve the efficiency of equipment by identifying and fixing problems before they cause equipment failure or downtime. This can help reduce maintenance costs and increase productivity.</li>



<li><strong>Improve safety:</strong> Predictive maintenance can help improve safety by identifying and addressing potential problems with equipment before they occur. This can help prevent accidents and injuries caused by equipment failure.</li>



<li><strong>Reduce maintenance costs</strong>: By proactively identifying and fixing potential problems with equipment, predictive maintenance can help reduce the overall cost of maintenance by minimizing the need for unscheduled downtime.</li>



<li><strong>Improve asset management</strong>: Predictive maintenance can help improve asset management by providing data and insights into the condition and performance of equipment. This can help organizations decide when to replace or upgrade equipment.</li>
</ul>



<p>Next, we look at the different ways organizations can implement predictive maintenance.</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="511" height="510" data-attachment-id="12380" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/monitoring-predictive-maintenance-safety-manufacturing-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png" data-orig-size="511,510" 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="monitoring-predictive-maintenance-safety-manufacturing-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png" src="https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png" alt="" class="wp-image-12380" srcset="https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png 511w, https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/monitoring-predictive-maintenance-safety-manufacturing-min.png 140w" sizes="(max-width: 511px) 100vw, 511px" /><figcaption class="wp-element-caption">Utilities and manufacturing are only two of the many industries that use predictive maintenance. Image generated with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a>.</figcaption></figure>



<p></p>
</div>
</div>
</div>
</div>



<h2 class="wp-block-heading">Approaches to Predictive Maintenance</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>There are several approaches to implementing a predictive maintenance solution, depending on the type of equipment being monitored and the resources available. These approaches include:</p>



<ul class="wp-block-list">
<li><strong>Condition-based monitoring:</strong> This involves continuously monitoring the condition of the equipment using sensors. When certain thresholds or conditions are met, an alert is triggered, or corrective measures are launched. The goal is to reduce the risk of failure. For example, if the temperature of a motor exceeds a certain level, this may indicate that the motor is about to fail.</li>



<li><strong>Predictive modeling:</strong> This approach involves using machine learning algorithms to analyze historical lifetime data about the equipment to identify patterns that may indicate an impending failure. This can be done using data from sensors, as well as operational data and maintenance records. When historical or failure data is not available, a degradation model can be created to estimate failure times based on a threshold value. This approach is often used when there is limited data available.</li>



<li><strong>Prognostic algorithms: </strong>By using data from sensors and other sources, prognostic algorithms can predict the remaining useful life of a piece of equipment. This information can help organizations determine the likelihood of a breakdown and plan for replacements or maintenance activities. By understanding the equipment better, organizations can potentially extend maintenance cycles, which can reduce costs for replacements and maintenance.</li>
</ul>



<p>It is important to choose an approach that is appropriate for the specific equipment and maintenance challenges faced by the organization. </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">Data Requirements</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>When implementing predictive maintenance, it is important to consider that each approach comes with its own set of data requirements. Types of data include the following:</p>



<ul class="wp-block-list">
<li><strong>Current condition data</strong> includes information about the state of the equipment, such as its temperature, pressure, vibration, and other physical parameters.</li>



<li><strong>Operating data </strong>includes information about how the equipment is being used, such as its load, speed, and other operating parameters.</li>



<li><strong>Maintenance history data</strong> includes information about past maintenance activities that have been performed on the equipment.</li>



<li><strong>Failure history data</strong> includes information about past equipment failures, such as the date of the failure, the cause of the failure, and the impact on operations.</li>
</ul>



<p>Collecting these data requires investing in sensors and other data collection infrastructure and ensuring that data collection is accurate and storage is proper. By combining various data types, organizations can create a comprehensive view of equipment condition and performance and use it to predict maintenance requirements.</p>



<p>The specific types of data needed will depend on the implementation approach. Organizations must ensure they have access to the necessary data to implement the selected approach effectively. Some specific data requirements for each approach include the following:</p>



<figure class="wp-block-table"><table><thead><tr><th>Approach</th><th>Data Requirements</th></tr></thead><tbody><tr><td>Condition-based monitoring</td><td>Sensor data from the equipment being monitored. </td></tr><tr><td>Predictive modeling</td><td>A combination of sensor data, operational data, and maintenance records. </td></tr><tr><td>Prognostic algorithms</td><td>Sensor data, as well as data about past failures and maintenance events. </td></tr></tbody></table><figcaption class="wp-element-caption">Data requirements per implementation approach</figcaption></figure>
</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="1018" height="856" data-attachment-id="12379" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png" data-orig-size="1018,856" 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="jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png" src="https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png" alt="Predictive maintenance - Machine learning can make maintenance cycles more cost-efficient. Image generated using Midjourney" class="wp-image-12379" srcset="https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png 1018w, https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/02/jejimga_a_factory_using_technology_for_safety_efficiency_qualit_5daef8a5-5ab0-49d2-9821-4588049635a2-min.png 768w" sizes="(max-width: 1018px) 100vw, 1018px" /><figcaption class="wp-element-caption">Predictive maintenance &#8211; Machine learning can make maintenance cycles more cost-efficient. Image generated using&nbsp;<a href="http://www.Midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<h2 class="wp-block-heading">Predicting Failures in Milling Machines using XGBoost in Python</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Now that we have a basic understanding of predictive maintenance, it&#8217;s time to get hands-on with Python. We will use sensor data and machine learning to predict failures in milling machines. But why do these machines break down in the first place? Milling machines have many moving parts that can suffer from wear and tear over time, leading to failures. Additionally, improper maintenance can cause issues with machine operation and lead to costly damage. Efficient maintenance can be challenging due to the varying loads that milling machines are subjected to. However, by implementing a predictive maintenance solution with Python, we can proactively identify and address issues to prevent costly downtime and ensure the smooth operation of our milling machines. Our goal is to predict one of five failure types, which corresponds to a predictive modeling approach. Let&#8217;s get started on building our predictive maintenance solution.</p>



<p>The code is available on the GitHub repository.</p>



<div class="wp-block-kadence-advancedbtn kb-buttons-wrap kb-btns_c6038a-a9"><a class="kb-button kt-button button kb-btn_614436-7b 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/blob/master/02%20Classification/022%20Predicting%20Machine%20Malfunction%20of%20Milling%20Machines%20in%20Python.ipynb" 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-btn_a119d2-89 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-API-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>
</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 is-resized"><img decoding="async" data-attachment-id="12384" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/cnc_milling_machine_cyberpunk/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/02/cnc_milling_machine_cyberpunk.png" data-orig-size="253,253" 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="cnc_milling_machine_cyberpunk" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/02/cnc_milling_machine_cyberpunk.png" src="https://www.relataly.com/wp-content/uploads/2023/02/cnc_milling_machine_cyberpunk.png" alt="Image of a CNC milling machine. Image created with Midjourney" class="wp-image-12384" width="375" height="375" srcset="https://www.relataly.com/wp-content/uploads/2023/02/cnc_milling_machine_cyberpunk.png 253w, https://www.relataly.com/wp-content/uploads/2023/02/cnc_milling_machine_cyberpunk.png 140w" sizes="(max-width: 375px) 100vw, 375px" /><figcaption class="wp-element-caption">Image of a CNC milling machine. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading">Prerequisites</h3>



<p>Before starting the coding part, make sure that you have set up your <a href="https://www.python.org/downloads/" target="_blank" rel="noreferrer noopener">Python 3</a> environment and required packages. </p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p><strong>Python Environment</strong></p>



<p>Before diving into the FairLearn Python tutorial, it is important to take the necessary steps to ensure that your Python environment is properly set up and that you have all the required packages installed. This will ensure a seamless learning experience and prevent any potential roadblocks or issues that may arise due to an improperly configured environment.</p>



<p>If you don&#8217;t have an environment, follow&nbsp;<a href="https://www.relataly.com/anaconda-python-environment-machine-learning/1663/" target="_blank" rel="noreferrer noopener">this tutorial</a>&nbsp;to set up the&nbsp;<a href="https://www.anaconda.com/products/individual" target="_blank" rel="noreferrer noopener">Anaconda environment</a>.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p><strong>Python Packages</strong></p>



<p>Make sure you install all required packages. In this tutorial, we will be working with the following packages:&nbsp;</p>



<ul class="wp-block-list">
<li>Pandas</li>



<li>NumPy</li>



<li>Matplotlib</li>



<li>Seaborn</li>



<li>Plotly</li>
</ul>



<p>In addition, we will be using the machine learning library <strong><em>Scikit-learn</em></strong> and the XGBoost library, which is a popular library for training gradient-boosting models.</p>



<p>You can install packages using console commands:</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;:true,&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;}">pip install &lt;package name&gt;
conda install &lt;package name&gt; (if you are using the anaconda packet manager)</pre></div>
</div>
</div>



<h3 class="wp-block-heading">About the Sensor Dataset</h3>



<p>In this tutorial, we will work with a synthetic sensor dataset from the <a href="https://archive.ics.uci.edu/ml/datasets/AI4I+2020+Predictive+Maintenance+Dataset" target="_blank" rel="noreferrer noopener">UCL ML archives</a> that simulates the typical life cycle of a milling machine. The dataset contains the following fields:</p>



<p>The dataset consists of 10 000 data points stored as rows with 14 features in columns:</p>



<ul class="wp-block-list">
<li>UID: unique identifier ranging from 1 to 10000</li>



<li>productID: consisting of a letter L, M, or H for low (50% of all products), medium (30%), and high (20%) as product quality variants and a variant-specific serial number</li>



<li>air temperature [K]</li>



<li>process temperature [K]</li>



<li>rotational speed [rpm]</li>



<li>torque [Nm]</li>



<li>tool wear [min]</li>



<li>machine failure. A label that indicates whether the machine has failed or not</li>



<li>Failure type (prediction label). The label contains five failure types: tool wear failure (TWF), heat dissipation failure (HDF), power failure (PWF), overstrain failure (OSF), random failures (RNF)</li>
</ul>



<p>Source: <a href="https://archive.ics.uci.edu/ml/datasets/AI4I+2020+Predictive+Maintenance+Dataset" target="_blank" rel="noreferrer noopener">UCL ML Repository</a></p>



<p>You can download the dataset from <a href="https://www.kaggle.com/code/potongpasir/predicting-machine-malfunction/data" target="_blank" rel="noreferrer noopener">Kaggle.com</a>. Unzip the file predictive_maintenance.csv and save it under the following file path: &#8220;/data/iot/classification/&#8221;</p>



<h3 class="wp-block-heading">Step #1 Load the Data</h3>



<p>We begin by importing the required libraries. This also includes the XGBoost library, which is a popular library for training gradient-boosting models. In addition, we will load the dataset using the pandas library. Then we define our target variable as Failure Type. The dataset contains a second target column, which only contains the binary information of machine failures. We will drop this column, as our goal is to predict the specific type of failure. Then we print the first three rows of the loaded dataset. </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;}"># A tutorial for this file is available at www.relataly.com
# Tested with Python 3.9.13, Matplotlib 3.6.2, Scikit-learn 1.2, Seaborn 0.12.1, numpy 1.21.5, xgboost 1.7.2

import pandas as pd 
import matplotlib.pyplot as plt 
import numpy as np
import seaborn as sns
import plotly.express as px
sns.set_style('white', { 'axes.spines.right': False, 'axes.spines.top': False})
from sklearn.metrics import classification_report, confusion_matrix, precision_recall_fscore_support as score, roc_curve
from sklearn.model_selection import cross_val_score, train_test_split, cross_validate
from sklearn.utils import compute_sample_weight
from xgboost import XGBClassifier

# load the train data
path = '/data/iot/classification/'
df = pd.read_csv(path + &quot;predictive_maintenance.csv&quot;) 

# define the target
target_name='Failure Type'

# drop a redundant columns
df.drop(columns=['Target'], inplace=True)

# print a summary of the train data
print(df.shape[0])
df.head(3)</pre></div>



<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;}">	UDI	Product ID	Type	Air temperature [K]	Process temperature [K]	Rotational speed [rpm]	Torque [Nm]	Tool wear [min]	Failure Type
0	1	M14860		M		298.1				308.6				1551						42.8		0				No Failure
1	2	L47181		L		298.2				308.7				1408						46.3		3				No Failure
2	3	L47182		L		298.1				308.5				1498						49.4		5				No Failure</pre></div>



<h3 class="wp-block-heading">Step #2 Clean the Data</h3>



<p>Next, we quickly check the data quality of our dataset. The following code block checks if there are any missing values in our dataset. If there are missing values, it creates a barplot showing the number of missing values for each column, along with the percentage of missing values. If there are no missing values, it prints a message saying &#8220;no missing values.&#8221;</p>



<p>The function then drops any columns with more than 5% missing values from the DataFrame. Finally, it prints the names of the remaining columns in the DataFrame. This function can be used to identify and handle missing values in a dataset before applying machine learning algorithms to it.</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;}"># check for missing values
def print_missing_values(df):
    null_df = pd.DataFrame(df.isna().sum(), columns=['null_values']).sort_values(['null_values'], ascending=False)
    fig = plt.subplots(figsize=(16, 6))
    ax = sns.barplot(data=null_df, x='null_values', y=null_df.index, color='royalblue')
    pct_values = [' {:g}'.format(elm) + ' ({:.1%})'.format(elm/len(df)) for elm in list(null_df['null_values'])]
    ax.set_title('Overview of missing values')
    ax.bar_label(container=ax.containers[0], labels=pct_values, size=12)

if df.isna().sum().sum() &gt; 0:
    print_missing_values(df)
else:
    print('no missing values')

# drop all columns with more than 5% missing values
for col_name in df.columns:
    if df[col_name].isna().sum()/df.shape[0] &gt; 0.05:
        df.drop(columns=[col_name], inplace=True) 

df.columns</pre></div>



<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;}">no missing values
Index(['UDI', 'Product ID', 'Type', 'Air temperature [K]',
       'Process temperature [K]', 'Rotational speed [rpm]', 'Torque [Nm]',
       'Tool wear [min]', 'Failure Type'],
      dtype='object')</pre></div>



<p>Next, we will drop two unnecessary columns and rename the remaining ones to make them easier to work with. The original column names are quite long and contain special characters that could cause errors during the training process. Once the columns are renamed, we will print the updated DataFrame to verify the changes.</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;}"># drop id columns
df_base = df.drop(columns=['Product ID', 'UDI'])

# adjust column names
df_base.rename(columns={'Air temperature [K]': 'air_temperature', 
                        'Process temperature [K]': 'process_temperature', 
                        'Rotational speed [rpm]':'rotational_speed', 
                        'Torque [Nm]': 'torque', 
                        'Tool wear [min]': 'tool_wear'}, inplace=True)
df_base.head()</pre></div>



<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;}">	Type	air_temperature	process_temperature	rotational_speed	torque	tool_wear	Failure Type
0	M		298.1			308.6				1551				42.8	0			No Failure
1	L		298.2			308.7				1408				46.3	3			No Failure
2	L		298.1			308.5				1498				49.4	5			No Failure
3	L		298.2			308.6				1433				39.5	7			No Failure
4	L		298.2			308.7				1408				40.0	9			No Failure</pre></div>



<p>Everything looks as expected: Our dataset contains six features and the target column with the five failure types.</p>



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



<p>Next, let&#8217;s explore the dataset. </p>



<h4 class="wp-block-heading">Target Class Distribution</h4>



<p>The following code uses the plotly express library to create a histogram showing the class distribution of the &#8220;Failure Type&#8221; column in a DataFrame called &#8220;df_base.&#8221; The histogram will have one bar for each unique value in the &#8220;Failure Type&#8221; column, and the height of each bar will represent the number of occurrences of that value in the column. This can be useful for understanding the imbalance in the distribution of classes in a classification problem.</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;}"># display class distribution of the target variable
px.histogram(df_base, y=&quot;Failure Type&quot;, color=&quot;Failure Type&quot;) </pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11828" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot.png" data-orig-size="2042,450" 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="newplot" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-1024x226.png" alt="Target class distribution in our predictive maintenance dataset" class="wp-image-11828" width="1115" height="246" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot.png 1536w, https://www.relataly.com/wp-content/uploads/2023/01/newplot.png 2042w" sizes="(max-width: 1115px) 100vw, 1115px" /></figure>



<p>Our dataset is highly imbalanced, with the vast majority of cases having a &#8220;No Failure&#8221; label. If the dataset is highly imbalanced, with a disproportionate number of cases in one class compared to the others, it can impact the performance of machine learning models. This is because imbalanced datasets can lead to models that are biased towards the majority class, and may not perform well on the minority class. In order to improve model performance on imbalanced datasets, we will later adjust the model hyperparameters accordingly. </p>



<h4 class="wp-block-heading">Feature Pairplots</h4>



<p>Next, let&#8217;s construct pair plots to explore feature relations with the target variable. Pair plots, also known as scatter plots, are a type of plot that shows the relationship between two variables. In the context of a predictive maintenance dataset, pair plots can be useful for exploring the relationships between different features and the target variable (e.g., the likelihood of a machine failure). By creating pair plots and visualizing the relationships between different features and the target variable, you can gain insights into which features might be most useful for building a predictive model.</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;}"># pairplots on failure type
sns.pairplot(df_base, height=2.5, hue='Failure Type')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11829" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/image-3-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/image-3.png" data-orig-size="1476,1226" 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-3" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/image-3.png" src="https://www.relataly.com/wp-content/uploads/2023/01/image-3-1024x851.png" alt="feature plot for our predictive maintenance dataset" class="wp-image-11829" width="874" height="726" srcset="https://www.relataly.com/wp-content/uploads/2023/01/image-3.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/image-3.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/image-3.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/image-3.png 1476w" sizes="(max-width: 874px) 100vw, 874px" /></figure>



<p>The pair plots reveal valuable patterns in our features that can inform the predictions of our model. For instance, we see that Power Failures tend to be correlated with torque values that are either close to the maximum or minimum. Such patterns should allow our predictive model to make solid predictions. </p>



<h4 class="wp-block-heading">Feature Correlation</h4>



<p>Next, we will look at feature correlation. The following code block creates a heatmap using the seaborn library that shows the correlation between all pairs of columns in a DataFrame called &#8220;df_base&#8221;. The heatmap is plotted using a color scale, with warmer colors indicating stronger correlations and cooler colors indicating weaker correlations. The correlation values are also displayed in the cells of the heatmap, with values ranging from -1 (perfect negative correlation) to 1 (perfect positive correlation). By creating a heatmap, you can quickly see which variables are positively or negatively correlated with each other, and to what degree. This can be helpful for identifying which features might be most useful for building a predictive model.</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;}"># correlation plot
plt.figure(figsize=(6,4))
sns.heatmap(df_base.corr(), cbar=True, fmt='.1f', vmax=0.8, annot=True, cmap='Blues')</pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" data-attachment-id="11830" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/image-4-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/image-4.png" data-orig-size="649,506" 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-4" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/image-4.png" src="https://www.relataly.com/wp-content/uploads/2023/01/image-4.png" alt="Feature correlation for our predictive maintenance dataset" class="wp-image-11830" width="689" height="537" srcset="https://www.relataly.com/wp-content/uploads/2023/01/image-4.png 649w, https://www.relataly.com/wp-content/uploads/2023/01/image-4.png 300w" sizes="(max-width: 689px) 100vw, 689px" /></figure>



<p>From the table, it looks like there is a strong positive correlation between &#8220;air_temperature&#8221; and &#8220;process_temperature&#8221; (0.87). This makes sense since a high process temperature will naturally also heat up the air around the machine. In addition, there is a strong negative correlation between &#8220;rotational_speed&#8221; and &#8220;torque&#8221; (-0.87). The other correlations are weaker and closer to 0, indicating weaker relationships.</p>



<p>Understanding the correlations between different variables in a dataset can be helpful for building predictive models, as it can give you an idea of which features might be most important for predicting a given target. It can also help you identify any redundant features that might not add much value to your model. Since our dataset only contains six features, we will keep all of them. </p>



<h4 class="wp-block-heading">Feature Boxplots</h4>



<p>Box plots are a useful visualization tool for understanding the distribution of values in a dataset. They show the minimum, first quartile, median, third quartile, and maximum values for each group, as well as any outliers. By creating box plots separated by a categorical variable, you can compare the distributions of values between different groups and see if there are any significant differences. This can be useful for identifying trends or patterns in the data that might be useful for building a predictive model.</p>



<p>If there are significant differences between the boxplots for different categories, it could be a good sign for building a predictive model. For example, if the boxplots for one category tend to have higher values for a particular feature than the boxplots for another category, it could indicate that the feature is related to the target variable and could be useful for making predictions.</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;}"># create histograms for feature columns separated by target column
def create_histogram(column_name):
    plt.figure(figsize=(16,6))
    return px.box(data_frame=df_base, y=column_name, color='Failure Type', points=&quot;all&quot;, width=1200)

create_histogram('air_temperature')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11831" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-1/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png" data-orig-size="1200,450" 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="newplot-1" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-1-1024x384.png" alt="feature boxplot for different failure types in predictive maintenance dataset. feature: air temperature" class="wp-image-11831" width="1078" height="405" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-1.png 1200w" sizes="(max-width: 1078px) 100vw, 1078px" /></figure>



<p>Feature boxplot for process_temperature.</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;}">create_histogram('process_temperature')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11832" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png" data-orig-size="1200,450" 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="newplot-2" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-2-1024x384.png" alt="feature boxplot for different failure types in predictive maintenance dataset. feature: air temperature" class="wp-image-11832" width="1087" height="408" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-2.png 1200w" sizes="(max-width: 1087px) 100vw, 1087px" /><figcaption class="wp-element-caption">Feature boxplot for rotational speed.</figcaption></figure>



<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;}">create_histogram('rotational_speed')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11833" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png" data-orig-size="1200,450" 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="newplot-3" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-3-1024x384.png" alt="feature boxplot for different failure types in predictive maintenance dataset. feature: rotational speed" class="wp-image-11833" width="1110" height="417" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-3.png 1200w" sizes="(max-width: 1110px) 100vw, 1110px" /></figure>



<p>Feature boxplot for torque.</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;}">create_histogram('torque')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11834" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-4/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png" data-orig-size="1200,450" 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="newplot-4" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-4-1024x384.png" alt="feature boxplot for different failure types in predictive maintenance dataset. feature: torque" class="wp-image-11834" width="1082" height="406" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-4.png 1200w" sizes="(max-width: 1082px) 100vw, 1082px" /></figure>



<p>Feature boxplot for tool wear.</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;}">create_histogram('tool_wear')</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="11835" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-5/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png" data-orig-size="1200,450" 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="newplot-5" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-5-1024x384.png" alt="feature boxplot for different failure types in predictive maintenance dataset. feature: tool wear" class="wp-image-11835" width="1097" height="411" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png 1024w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png 768w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-5.png 1200w" sizes="(max-width: 1097px) 100vw, 1097px" /></figure>



<p>Now that we have a good understanding of our dataset, we can prepare the data for model training. </p>



<h3 class="wp-block-heading" id="h-step-4-data-preparation">Step #4 Data Preparation</h3>



<p>To prepare the data for model training, we will need to split our dataset and make additional modifications. </p>



<p>The following code block contains a reusable function called data_preparation. The purpose of this function is to prepare the data in a way that is suitable for building and evaluating machine learning models. It performs several preprocessing steps, such as encoding categorical variables and splitting the data into training and test sets. </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 data_preparation(df_base, target_name):
    df = df_base.dropna()

    df['target_name_encoded'] = df[target_name].replace({'No Failure': 0, 'Power Failure': 1, 'Tool Wear Failure': 2, 'Overstrain Failure': 3, 'Random Failures': 4, 'Heat Dissipation Failure': 5})
    df['Type'].replace({'L': 0, 'M': 1, 'H': 2}, inplace=True)
    X = df.drop(columns=[target_name, 'target_name_encoded'])
    y = df['target_name_encoded'] #Prediction label

    # split the data into x_train and y_train data sets
    X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.7, random_state=0)

    # print the shapes: the result is: (rows, training_sequence, features) (prediction value, )
    print('train: ', X_train.shape, y_train.shape)
    print('test: ', X_test.shape, y_test.shape)
    return X, y, X_train, X_test, y_train, y_test

# remove target from training data
X, y, X_train, X_test, y_train, y_test = data_preparation(df_base, target_name)</pre></div>



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



<p>Now that we have prepared the dataset, we can train the XGBoost classification model. The basic idea behind XGBoost is to train a series of weak models, such as decision trees, and then combine their predictions using gradient boosting. During training, XGBoost uses an optimization algorithm to adjust the weight of each model in the ensemble in order to improve the overall prediction accuracy. XGBoost also includes a number of additional features and techniques that help to improve the performance of the model, such as regularization, feature selection, and handling missing values.</p>



<p>XGboost provides several configuration options that we can use to finetune performance and adjust the training process to our dataset. For a complete list of hyperparameters, please see the <a href="https://xgboost.readthedocs.io/en/stable/python/index.html" target="_blank" rel="noreferrer noopener">library documentation</a>.</p>



<p>Remember that our class labels are imbalanced. Therefore, we will provide the model with sample weights. The following code creates a weight array for the training and test sets using the &#8220;compute_sample_weight&#8221; function from scikit-learn. We calculate the weight array based on the &#8220;balanced&#8221; mode. This means that the weights are calculated such that the class distribution in the sample is balanced. This can be useful when working with imbalanced datasets, as it helps to mitigate the effects of class imbalance on the model.</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;}">weight_train = compute_sample_weight('balanced', y_train)
weight_test = compute_sample_weight('balanced', y_test)

xgb_clf = XGBClassifier(booster='gbtree', 
                        tree_method='gpu_hist', 
                        sampling_method='gradient_based', 
                        eval_metric='aucpr', 
                        objective='multi:softmax', 
                        num_class=6)
# fit the model to the data
xgb_clf.fit(X_train, y_train.ravel(), sample_weight=weight_train)</pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="842" height="270" data-attachment-id="11836" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/image-5-3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/image-5.png" data-orig-size="842,270" 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-5" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/image-5.png" src="https://www.relataly.com/wp-content/uploads/2023/01/image-5.png" alt="summary of our XGBoost classifier of our predictive maintenance solution" class="wp-image-11836" srcset="https://www.relataly.com/wp-content/uploads/2023/01/image-5.png 842w, https://www.relataly.com/wp-content/uploads/2023/01/image-5.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/image-5.png 768w" sizes="(max-width: 842px) 100vw, 842px" /></figure>



<p>We can see that the blue box summarizes the configuration of our model and indicates that the training process has been successful. Now that we have the classifier, we can use it to make predictions on new data.</p>



<h3 class="wp-block-heading" id="h-step-6-model-evaluation">Step #6 Model Evaluation</h3>



<p>Finally, we will evaluate the model&#8217;s performance. This will involve three steps:</p>



<ul class="wp-block-list">
<li>Model scoring</li>



<li>Cross-validation</li>



<li>Confusion matrix</li>
</ul>



<h4 class="wp-block-heading">Model Scoring</h4>



<p>First, we calculate the accuracy of the classifier on the test set using the &#8220;score&#8221; method. To account for the imbalance of class labels, we pass in the weight array for the test set as an additional parameter. This returns the fraction of correct predictions made by the classifier. Next, the code uses the classifier to make predictions on the test set using the &#8220;predict&#8221; method. It then generates a classification report using the &#8220;classification_report&#8221; function from scikit-learn. The report displays a summary of the model&#8217;s performance in terms of various evaluation metrics such as precision, recall, and f1-score.</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;}"># score the model with the test dataset
score = xgb_clf.score(X_test, y_test.ravel(), sample_weight=weight_test)

# predict on the test dataset
y_pred = xgb_clf.predict(X_test)

# print a classification report
results_log = classification_report(y_test, y_pred)
print(results_log)</pre></div>



<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;}">precision    recall  f1-score   support

           0       0.99      0.98      0.99      2903
           1       0.64      0.88      0.74        24
           2       0.04      0.08      0.06        12
           3       0.77      0.89      0.83        27
           4       0.00      0.00      0.00         4
           5       0.76      0.97      0.85        30

    accuracy                           0.98      3000
   macro avg       0.53      0.63      0.58      3000
weighted avg       0.98      0.98      0.98      3000</pre></div>



<p>The classification report shows the performance of our XGBoost classifier on the test dataset. The model appears to perform well, with a high accuracy of 0.98 and a high weighted average f1-score of 0.98. </p>



<p>However, there are a few classes where the model&#8217;s performance is not as strong. Class 1 has a relatively low precision of 0.64 and a low f1-score of 0.74, while class 2 has a very low precision of 0.04 and a low f1-score of 0.06. Class 4 has a precision and f1-score of 0.00, which suggests that the model is not making any correct predictions for this class.</p>



<p>It is also worth noting that the support for some classes is much lower than for others. Class 1 has a support of 24, while class 0 has a support of 2903. This is due to the fact that there are relatively few instances of class 1 in the test dataset compared to class 0, which affects the model&#8217;s performance on class 1.</p>



<h4 class="wp-block-heading">Confusion Matrix</h4>



<p>Next, we create a confusion matrix. We input the true labels of the test set (y_test) and the predicted labels produced by the model (y_pred) to generate the matrix. The matrix shows us the number of correct and incorrect predictions made by the model for each class.</p>



<p>We then create a DataFrame from the confusion matrix and use the seaborn library to visualize the matrix as a heatmap. The heatmap allows us to easily see which classes are being predicted correctly and which are being misclassified. </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;}"># create predictions on the test dataset
y_pred = xgb_clf.predict(X_test)

# print a multi-Class Confusion Matrix
cnf_matrix = confusion_matrix(y_test, y_pred)
df_cm = pd.DataFrame(cnf_matrix, columns=np.unique(y_test), index=np.unique(y_test))
df_cm.index.name = 'Actual'
df_cm.columns.name = 'Predicted'
plt.figure(figsize = (8, 5))
sns.set(font_scale=1.1) #for label size
sns.heatmap(df_cm, cbar=True, cmap= &quot;inferno&quot;, annot=True, fmt='.0f') </pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" data-attachment-id="11837" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/image-6-2/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/image-6.png" data-orig-size="668,456" 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-6" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/image-6.png" src="https://www.relataly.com/wp-content/uploads/2023/01/image-6.png" alt="Evaluating the performance of our predictive maintenance solution using a confusion matrix" class="wp-image-11837" width="663" height="452" srcset="https://www.relataly.com/wp-content/uploads/2023/01/image-6.png 668w, https://www.relataly.com/wp-content/uploads/2023/01/image-6.png 300w" sizes="(max-width: 663px) 100vw, 663px" /></figure>



<p>The color scale of the heatmap indicates the magnitude of the values in the matrix. In this case, the darker the color, the higher the number of predictions. This visualization helps us to understand the performance of the model and identify areas for improvement. </p>



<p>Here are a few things that we can learn from this matrix:</p>



<ul class="wp-block-list">
<li>The model made a total of 2902 correct predictions and 67 incorrect predictions.</li>



<li>For the &#8220;No Failure&#8221; class, the model made 2854 correct predictions and 29 incorrect predictions. The majority of the incorrect predictions were false negatives.</li>



<li>For the &#8220;Power Failure&#8221; class, the model made 21 correct predictions and three incorrect predictions. </li>



<li>For the &#8220;Tool Wear Failure&#8221; class, the model made 1 correct prediction and 1 incorrect prediction. </li>



<li>For the &#8220;Overstrain Failure&#8221; class, the model made 24 correct predictions and 2 incorrect predictions. </li>



<li>For the &#8220;Random Failures&#8221; class, the model made 29 correct predictions and 4 incorrect predictions. </li>



<li>For the &#8220;Heat Dissipation Failure&#8221; class, the model made 29 correct predictions and 1 incorrect prediction. </li>
</ul>



<p>Overall, the model seems to be performing relatively well, but it is making a lot of false negatives for some classes. </p>



<h4 class="wp-block-heading">Cross Validation</h4>



<p>Finally, we perform cross-validation on the training set using the &#8220;cross_validate&#8221; function from scikit-learn. Cross-validation is a technique for evaluating the performance of a machine learning model by training it on different subsets of the data and evaluating it on the remaining data. </p>



<p>In this case, we will train and evaluate our model 10 times using different splits of the data (specified by the &#8220;cv&#8221; parameter). We also specify that the evaluation metric should be the weighted f1-score (specified by the &#8220;scoring&#8221; parameter). We then pass the weight array for the training set to the classifier.</p>



<p>The &#8220;cross_validate&#8221; function returns a dictionary containing various evaluation metrics for each fold of the cross-validation. We will convert the dictionary to a DataFrame and create a bar plot using the plotly express library to visualize the results. This helps us to understand the consistency and stability of the model&#8217;s performance.</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;}"># cross validation
scores  = cross_validate(xgb_clf, X_train, y_train, cv=10, scoring=&quot;f1_weighted&quot;, fit_params={ &quot;sample_weight&quot; :weight_train})
scores_df = pd.DataFrame(scores)
px.bar(x=scores_df.index, y=scores_df.test_score, width=800)</pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" data-attachment-id="11838" data-permalink="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/newplot-6/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png" data-orig-size="800,450" 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="newplot-6" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png" src="https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png" alt="Evaluation the performance of our predictive maintenance solution. cross validation scores for the XGBoost model. " class="wp-image-11838" width="644" height="362" srcset="https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png 800w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png 300w, https://www.relataly.com/wp-content/uploads/2023/01/newplot-6.png 768w" sizes="(max-width: 644px) 100vw, 644px" /></figure>



<p>The model performance remains consistent across all folds. </p>



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



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>In this article, we have presented the concept of predictive maintenance and demonstrated how organizations can use this approach to improve their maintenance cycles. The second part of the article provided a hands-on tutorial showing how to implement a predictive maintenance solution for predicting different failure types of a milling machine. We trained a classification model using the XGBoost algorithm and sensor data from the machine. </p>



<p>While the model demonstrated good performance overall, we observed that it was not able to predict all classes with the same level of accuracy. This suggests that there may be opportunities to improve the model&#8217;s performance. One potential approach is to balance the dataset by up or down-sampling the data to achieve a more even distribution of classes. By doing so, we can mitigate the effects of class imbalance and potentially improve the model&#8217;s predictions for all classes.</p>



<p>By implementing such a predictive maintenance approach, organizations can improve their operational efficiency and ensure the smooth running of their machinery.</p>



<p>I hope this article was helpful. If you have any questions or feedback, let me know in the comments. </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="497" height="493" data-attachment-id="12901" data-permalink="https://www.relataly.com/smart-factory-iot-sensors-relataly-midjourney-min/" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png" data-orig-size="497,493" 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="smart factory iot sensors relataly midjourney-min" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png" alt="" class="wp-image-12901" srcset="https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png 497w, https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/smart-factory-iot-sensors-relataly-midjourney-min.png 140w" sizes="(max-width: 497px) 100vw, 497px" /><figcaption class="wp-element-caption">Predictive maintenance also plays an essential role in a smart factory. Image created with Midjourney. </figcaption></figure>
</div>
</div>



<p></p>



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



<p>There are many books available on the topics of IoT and predictive maintenance. Here are a few recommendations:</p>



<ul class="wp-block-list">
<li><a href="https://amzn.to/3XgrX7L" target="_blank" rel="noreferrer noopener">An Introduction to Predictive Maintenance</a> by R Keith Mobley</li>



<li><a href="https://amzn.to/3CzYL3A" target="_blank" rel="noreferrer noopener">Predictive Analytics: The Secret to Predicting Future Events Using Big Data and Data Science Techniques Such as Data Mining, Predictive Modelling, Statistics, Data Analysis, and Machine</a> by Richard Hurley</li>



<li>Stephan Matzka, <a href="https://ieeexplore.ieee.org/document/9253083" target="_blank" rel="noreferrer noopener">Explainable Artificial Intelligence for Predictive Maintenance Applications</a>, Third International Conference on Artificial Intelligence for Industries (AI4I 2020)</li>



<li><a href="https://amzn.to/3TrBdDY" target="_blank" rel="noreferrer noopener">David Forsyth (2019) Applied Machine Learning Springer</a></li>



<li>ChatGPT was used to revise certain parts of this article</li>



<li>Images created using Midjourney and OpenAI Dall-E</li>
</ul>



<p class="has-contrast-2-color has-base-3-background-color has-text-color has-background"><em>The links above to Amazon are affiliate links. By buying through these links, you support the Relataly.com blog and help to cover the hosting costs. Using the links does not affect the price.</em></p>
<p>The post <a href="https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/">Predictive Maintenance: Predicting Machine Failure using Sensor Data with XGBoost and Python</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/predictive-maintenance-predicting-machine-failure-with-python/10618/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">10618</post-id>	</item>
		<item>
		<title>Forecasting Beer Sales with ARIMA in Python</title>
		<link>https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/</link>
					<comments>https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/#comments</comments>
		
		<dc:creator><![CDATA[Florian Follonier]]></dc:creator>
		<pubDate>Wed, 03 Feb 2021 22:23:08 +0000</pubDate>
				<category><![CDATA[ARIMA]]></category>
		<category><![CDATA[Logistics]]></category>
		<category><![CDATA[Manufacturing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Retail]]></category>
		<category><![CDATA[Sales Forecasting]]></category>
		<category><![CDATA[statsmodels]]></category>
		<category><![CDATA[Stock Market Forecasting]]></category>
		<category><![CDATA[Telecommunications]]></category>
		<category><![CDATA[Time Series Forecasting]]></category>
		<category><![CDATA[Use Cases]]></category>
		<category><![CDATA[AI in Business]]></category>
		<category><![CDATA[AI in E-Commerce]]></category>
		<category><![CDATA[Classic Machine Learning]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[Supervised Learning]]></category>
		<category><![CDATA[Univariate Time Series Forecasting]]></category>
		<guid isPermaLink="false">https://www.relataly.com/?p=2884</guid>

					<description><![CDATA[<p>Time series analysis and forecasting is a tough nut to crack, but the ARIMA model has been cracking it for decades. ARIMA, short for &#8220;Auto-Regressive Integrated Moving Average,&#8221; is a powerful statistical modeling technique for time series analysis. It&#8217;s particularly effective when the time series you&#8217;re analyzing follows a clear pattern, like seasonal changes in ... <a title="Forecasting Beer Sales with ARIMA in Python" class="read-more" href="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/" aria-label="Read more about Forecasting Beer Sales with ARIMA in Python">Read more</a></p>
<p>The post <a href="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/">Forecasting Beer Sales with ARIMA in Python</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-9d6595d7 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>Time series analysis and forecasting is a tough nut to crack, but the ARIMA model has been cracking it for decades. ARIMA, short for &#8220;Auto-Regressive Integrated Moving Average,&#8221; is a powerful statistical modeling technique for time series analysis. It&#8217;s particularly effective when the time series you&#8217;re analyzing follows a clear pattern, like seasonal changes in weather or sales. ARIMA has been used to forecast everything from beer sales to order quantities, and this tutorial will show you how to build your own ARIMA model in Python. You&#8217;ll be making predictions like a pro in no time!</p>



<p>This tutorial proceeds in two parts: The first part covers the concepts behind ARIMA. You will learn how ARIMA works, what Stationarity means, and when it is appropriate to use ARIMA. The second part is a Python hands-on tutorial that applies auto-ARIMA to the Sales Forecasting domain. We&#8217;ll be working with a time series of beer sales, and our goal is to predict how the beer sales quantities will evolve in the coming years. First, we check if the time series is stationary. Then we train an ARIMA forecasting model. Finally, we use the model to produce a sales forecast and measure the model&#8217;s performance.</p>
</div>



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



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">About Sales Forecasting</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Sales forecasting is a crucial business strategy that involves predicting future sales volumes for a product (for example, beer) or service. It leverages sophisticated statistical and analytical techniques, such as time series analysis or machine learning algorithms, to scrutinize historical sales data. By identifying trends and patterns within this data, businesses can make informed predictions about their future sales performance.</p>



<p>This strategic forecasting plays a pivotal role in business operations. It is instrumental in guiding key decisions surrounding production, inventory management, staffing, and various other operational elements. By honing in on accurate sales forecasting, businesses can strike the perfect balance &#8211; maintaining enough inventory to meet customer demand without overproducing or overstocking. This equilibrium ensures a smooth flow in the supply chain and avoids unnecessary costs tied to excess production or storage.</p>



<p>Furthermore, sales forecasting serves as a roadmap for business growth. It aids in identifying potential market opportunities and predicting future sales revenue. This valuable foresight enables businesses to strategically plan their expansion, ensuring resources are optimally utilized and future goals are met. With this in-depth understanding of sales forecasting, businesses can stay ahead of market trends, navigate through business challenges, and ultimately steer towards success.</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="506" height="508" data-attachment-id="12602" data-permalink="https://www.relataly.com/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min/" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png" data-orig-size="506,508" 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="brewery arima beer sales forecasting python tutorial machine learning relataly-min" data-image-description="&lt;p&gt;Businesses rely on sales forecasting to make informed decisions about production, inventory management, staffing, and other key operational aspects.  Image created with Midjourney&lt;/p&gt;
" data-image-caption="&lt;p&gt;Businesses rely on sales forecasting to make informed decisions about production, inventory management, staffing, and other key operational aspects.  Image created with Midjourney&lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png" alt="Businesses rely on sales forecasting to make informed decisions about production, inventory management, staffing, and other key operational aspects.  Image created with Midjourney" class="wp-image-12602" srcset="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png 506w, https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly-min.png 140w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption class="wp-element-caption">Businesses rely on sales forecasting to make informed decisions about production, inventory management, staffing, and other key operational aspects. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="h-introduction-to-arima-time-series-modelling">Introduction to ARIMA Time Series Modelling</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>ARIMA models provide an alternative approach to time series forecasting that differs significantly from machine learning methods. Working with ARIMA requires a good understanding of Stationarity and knowledge of the transformations used to make time-series data stationary. The concept of Stationarity is, therefore, first on our schedule.</p>
</div>



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



<h3 class="wp-block-heading" id="h-the-concept-of-stationarity">The Concept of Stationarity</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Stationarity is an essential concept in stochastic processes that describes the nature of a time series. We consider a time series strictly stationary if its statistical properties do not change over time. In this case, summary statistics, such as the mean and variance, do not change over time. However, the time-series data we encounter in the real world often show a trend or significant irregular fluctuations, making them non-stationary or weakly stationary.</p>



<p>So why is Stationarity such an essential concept for ARIMA? If a time series is stationary, we can assume that the past values of the time series are predictive of future development. In other words, a stationary time series exhibits consistent behavior that makes it predictable. On the other hand, a non-stationary time series is characterized by a kind of random behavior that will be difficult to capture in modeling. Namely, if random movements characterized the past, there is a high probability that the future will be no different.</p>



<p>Fortunately, in many cases, it is possible to transform a time series that is non-stationary into a stationary form and, in this way, build better prediction models.</p>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>
</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="802" height="751" data-attachment-id="8592" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-25-8/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/05/image-25.png" data-orig-size="802,751" 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-25" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/05/image-25.png" src="https://www.relataly.com/wp-content/uploads/2022/05/image-25.png" alt="arima time series forecasting, stationary vs non-stationary data, python tutorial " class="wp-image-8592" srcset="https://www.relataly.com/wp-content/uploads/2022/05/image-25.png 802w, https://www.relataly.com/wp-content/uploads/2022/05/image-25.png 300w, https://www.relataly.com/wp-content/uploads/2022/05/image-25.png 768w" sizes="(max-width: 802px) 100vw, 802px" /><figcaption class="wp-element-caption">A stationary Vs. a non-stationary time series</figcaption></figure>
</div>
</div>



<h3 class="wp-block-heading">How to Test Whether a Time Series is Stationary</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>The first step in the ARIMA modeling approach is determining whether a time series is stationary. There are different ways to determine whether a time series is stationary:</p>



<ul class="wp-block-list">
<li><strong>Plotting:</strong> We can plot the time series and visually check if it shows consistent behavior or changes over a more extended period.</li>



<li><strong>Summary statistics</strong>: We can split the time series into different periods and calculate the summary statistics, such as the variance. If these metrics are subject to significant changes, the time series is non-stationary. However, the results will also depend on the respective periods, leading to false conclusions.</li>



<li><strong>Statistic tests</strong>: There are various tests to determine the stationary of a time series, such as Kwiatkowski–Phillips–Schmidt–Shin, Augmented Dickey-Fuller, or Phillips–Perron. These tests systematically check a time series and measure the results against the null hypothesis, providing an indicator of the trustworthiness of the results.</li>
</ul>
</div>



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



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-what-is-an-s-arima-model">What is an (S)ARIMA Model?</h3>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>As the name implies, ARIMA uses autoregression (AR), integration (differencing), and moving averages (MA) to fit a linear regression model to a time series. </p>



<h4 class="wp-block-heading" id="h-arima-parameters">ARIMA Parameters</h4>



<p>The default notation for ARIMA is a model with parameters p, d, and q, whereby each parameter takes an integer value: </p>



<ul class="wp-block-list">
<li><strong>d (differencing): </strong>In the case of a non-stationary time series, there is a chance to remove a trend from the data by differencing once or several times, thus bringing the data to a stationary state. The model parameter d determines the order of the differentiation. A value of d = 0 simplifies the ARIMA model to an ARMA model, lacking the integration aspect. If this is the case, we do not need to integrate the function because the time series is already stationary.</li>



<li><strong>p (order of the AR terms):</strong> The autoregressive process describes the dependent relationship between an observation and several lagged observations (lags). Predictions are then based on past data from the same time series using linear functions. p = 1 means the model uses values that lag by one period. </li>



<li><strong> q (order of the MA terms):</strong> The parameter q determines the number of lagged forecast errors in the prediction equation. In contrast to the AR process, the MA process assumes that values at a future point in time depend on the errors made by predictions at current and past points in time. This means that it is not previous events that determine the predictions but rather the previous estimation or prediction errors used to calculate the following time series value.</li>
</ul>



<h4 class="wp-block-heading" id="h-sarima">SARIMA</h4>



<p>In the real world, many time series have seasonal effects. Examples are monthly retail sales figures, temperature reports, weekly airline passenger data, etc. To consider this, we can specify a seasonal range (e.g., m=12 for monthly data) and additional seasonal AR or MA components for our model that deal with seasonality. Such a model is also called a SARIMA model, and we can define it as a model(p, d, q)(P, D, Q)[m]. </p>



<h4 class="wp-block-heading" id="h-auto-s-arima">Auto-(S)ARIMA </h4>



<p>When working with ARIMA, we can set the model parameters manually or use auto-ARIMA and let the model search for the optimal parameters. We do this by varying the parameters and then testing against Stationarity. With the seasonal option enabled, the process tries to identify the optimal hyperparameters for the seasonal components of the model. Auto-ARIMA works by conducting differencing tests to determine the order of differencing,&nbsp;<code>d</code> and then fitting models with parameters in defined ranges, e.g., start_<code>p</code>,&nbsp;<code>max_p</code>&nbsp;as well as <code>start_q</code>,&nbsp;<code>max_q</code>. If our model has a seasonal component, we can also define parameter ranges for the seasonal part of the model. </p>
</div>



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



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="h-creating-a-sales-forecast-with-arima-in-python">Creating a Sales Forecast with ARIMA in Python</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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>Having grasped the fundamental concepts behind ARIMA (AutoRegressive Integrated Moving Average), we&#8217;re now ready to dive into the practical aspect of crafting a sales forecasting model in Python. Utilizing ARIMA for forecasting sales data is an esteemed practice owing to the algorithm&#8217;s adeptness in modeling seasonal changes combined with long-term trends &#8211; a characteristic commonly exhibited by sales data.</p>



<p>In this tutorial, we&#8217;ll be employing a dataset representing the monthly beer sales across the United States from 1992 through 2018, recorded in millions of US dollars. Our objective is to construct a robust time series model using ARIMA to accurately predict future sales trends.</p>



<p>When it comes to the technological aspect, we&#8217;ll be using the Python-based &#8216;statsmodels&#8217; and &#8216;pmdarima&#8217; libraries to build our ARIMA sales forecasting model. So, if you&#8217;re ready to harness the power of Python and ARIMA for sales prediction, let&#8217;s get started!</p>



<p>The code is available on the GitHub repository.</p>



<div class="wp-block-kadence-advancedbtn kb-buttons-wrap kb-btns_87ac48-a9"><a class="kb-button kt-button button kb-btn_a01710-14 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/blob/master/01%20Time%20Series%20Forecasting%20%26%20Regression/001%20Forecasting%20US%20Beer%20Sales%20with%20(auto)%20ARIMA.ipynb" 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-btn_ff77d5-62 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-API-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>
</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="512" height="512" data-attachment-id="12612" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/a-car-drinking-beer-after-creating-an-arima-sales-forecast-min-1/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png" data-orig-size="1024,1024" 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="A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png" src="https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1-512x512.png" alt="A fluffy cat drinking beer after creating an ARIMA sales forecast. Image created with Midjourney" class="wp-image-12612" srcset="https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png 512w, https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png 300w, https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png 140w, https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png 768w, https://www.relataly.com/wp-content/uploads/2023/03/A-car-drinking-beer-after-creating-an-ARIMA-sales-forecast-min-1.png 1024w" sizes="(max-width: 512px) 100vw, 512px" /><figcaption class="wp-element-caption">A fluffy cat drinking beer after creating an ARIMA sales forecast. Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div>
</div>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 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%">
<h3 class="wp-block-heading" id="h-prerequisites">Prerequisites</h3>



<p>Before we start coding, ensure you have set up your Python 3 environment and required packages. If you don&#8217;t have an environment, you can follow&nbsp;this tutorial&nbsp;to set up the&nbsp;<a href="https://www.anaconda.com/products/individual" target="_blank" rel="noreferrer noopener">Anaconda environment</a>.</p>



<p>Also, make sure you install all required packages. In this tutorial, we will be working with the following standard packages:&nbsp;</p>



<ul class="wp-block-list">
<li><em><a href="https://pandas.pydata.org/" target="_blank" rel="noreferrer noopener">pandas</a></em></li>



<li><em><a href="https://numpy.org/" target="_blank" rel="noreferrer noopener">NumPy</a></em></li>



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



<p>In addition, we will be using the <a href="https://www.statsmodels.org/stable/index.html" target="_blank" rel="noreferrer noopener">statsmodels </a>library and <a href="https://pypi.org/project/pmdarima/" target="_blank" rel="noreferrer noopener">pmdarima</a>. </p>



<p>You can install packages using console commands:</p>



<ul class="wp-block-list">
<li><em>pip install &lt;package name&gt;</em></li>



<li><em>conda install &lt;package name&gt;</em>&nbsp;(if you are using the anaconda packet manager)</li>
</ul>
</div>



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



<h3 class="wp-block-heading" id="h-step-1-load-the-sales-data-to-our-python-project">Step #1 Load the Sales Data to Our Python Project</h3>



<p>In the initial step of this tutorial, we commence by setting up the necessary Python environment. We import several packages that we&#8217;ll be using for data manipulation, visualization, and implementing machine learning models. We then fetch the dataset we&#8217;ll be working with &#8211; the monthly beer sales in the United States from 1992 through 2018. This data is sourced from a publicly accessible URL and loaded into a pandas DataFrame.</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;}"># A tutorial for this file is available at www.relataly.com
# Tested with Python 3.88

# Setting up packages for data manipulation and machine learning
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pmdarima as pm
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.seasonal import seasonal_decompose
import seaborn as sns
sns.set_style('white', { 'axes.spines.right': False, 'axes.spines.top': False})

# Link to the dataset: 
# https://www.kaggle.com/bulentsiyah/for-simple-exercises-time-series-forecasting

path = &quot;https://raw.githubusercontent.com/flo7up/relataly_data/main/alcohol_sales/BeerWineLiquor.csv&quot;
df = pd.read_csv(path)
df.head()</pre></div>



<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;}">		date	beer
0	1/1/1992	1509
1	2/1/1992	1541
2	3/1/1992	1597
3	4/1/1992	1675
4	5/1/1992	1822</pre></div>



<p>As shown above, the sales figures in this dataset stem from the first day of each month.</p>



<h3 class="wp-block-heading" id="h-step-2-visualize-the-time-series-and-check-it-for-stationarity">Step #2 Visualize the Time Series and Check it for Stationarity</h3>



<p>Before modeling the sales data, we visualize the time series and test it for Stationarity. Visualization helps us choose the parameters for our ARIMA model, thus making it an essential step.</p>



<p>First, we will look at the different components of the time series. We do this by using the seasonal_decompose function of the statsmodels library. </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;}"># Decompose the time series
plt.rcParams[&quot;figure.figsize&quot;] = (10,6)
result = seasonal_decompose(df['beer'], model='multiplicative', period = 12)
result.plot()
plt.show()</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="4890" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-62-3/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2021/06/image-62.png" data-orig-size="712,568" 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-62" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2021/06/image-62.png" src="https://www.relataly.com/wp-content/uploads/2021/06/image-62.png" alt="forecasting us beer sales - time series decomposition" class="wp-image-4890" width="754" height="602" srcset="https://www.relataly.com/wp-content/uploads/2021/06/image-62.png 712w, https://www.relataly.com/wp-content/uploads/2021/06/image-62.png 300w" sizes="(max-width: 754px) 100vw, 754px" /></figure>



<p>To test for Stationarity, we use the ADFuller test. It is common to run this test multiple times throughout a data science project. Therefore, we create a function that we can then reuse later.</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 check_stationarity(df_sales, title_string, labels):
    # Visualize the data
    fig, ax = plt.subplots(figsize=(16, 8))
    plt.title(title_string, fontsize=14)
    if df_sales.index.size &gt; 12:
        df_sales['ma_12_month'] = df_sales['beer'].rolling(window=12).mean()
        df_sales['ma_25_month'] = df_sales['beer'].rolling(window=25).mean()
        sns.lineplot(data=df_sales[['beer', 'ma_25_month', 'ma_12_month']], palette=sns.color_palette(&quot;mako_r&quot;, 3))
        plt.legend(title='Smoker', loc='upper left', labels=labels)
    else:
        sns.lineplot(data=df_sales[['beer']])
    
    plt.show()
    
    sales = df_sales['beer'].dropna()
    # Perform an Ad Fuller Test
    # the default alpha = .05 stands for a 95% confidence interval
    adf_test = pm.arima.ADFTest(alpha = 0.05) 
    print(adf_test.should_diff(sales))
    
df_sales = pd.DataFrame(df['beer'], columns=['beer'])
df_sales.index = pd.to_datetime(df['date']) 
title = &quot;Beer sales in the US between 1992 and 2018 in million US$/month&quot;
labels = ['beer', 'ma_12_month', 'ma_25_month']
check_stationarity(df_sales, title, labels)</pre></div>



<figure class="wp-block-image size-full"><img decoding="async" width="940" height="495" data-attachment-id="8582" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/arima-time-series/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png" data-orig-size="940,495" 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="ARIMA-Time-series" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png" src="https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png" alt="arima plot seaborn beer sales forecasting python" class="wp-image-8582" srcset="https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png 940w, https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png 300w, https://www.relataly.com/wp-content/uploads/2022/05/ARIMA-Time-series.png 768w" sizes="(max-width: 940px) 100vw, 940px" /></figure>



<p>The data does not appear to be stationary. We can see that our time series is steadily increasing and shows annual seasonality. The steady increase indicates a continuous growth in beer consumption over the last decades. The seasonality in the sales data likely results from people drinking more beer in summer than in other seasons.</p>



<h3 class="wp-block-heading" id="h-step-3-exemplary-differencing-and-autocorrelation">Step #3 Exemplary Differencing and Autocorrelation</h3>



<p>The chart from the previous section shows that our time series is non-stationary. The reason is that it follows a clear upward trend. We also know that the time series has a seasonal component. Therefore, we need to define additional parameters and construct a SARIMA model.</p>



<p>Before we use auto-correlation to determine the optimal parameters, we will try manual differencing to make the time series stationary. There is no guarantee that differencing works. It is essential to remember that differencing can sometimes also worsen prediction performance. So be careful, not to overdifference! We could also trust that the auto-ARIMA model chooses the best parameters for us. However, we should always validate the selected parameters.</p>



<p>The ideal differencing parameter is the least number of differencing steps to achieve a stationary time series. We will monitor the results with autocorrelation plots to check whether differencing was successful.</p>



<p>We print the autocorrelation for the original time series and after the first and second-order differencing.</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;}"># 3.1 Non-seasonal part
def auto_correlation(df, prefix, lags):
    plt.rcParams.update({'figure.figsize':(7,7), 'figure.dpi':120})
    
    # Define the plot grid
    fig, axes = plt.subplots(3,2, sharex=False)

    # First Difference
    axes[0, 0].plot(df)
    axes[0, 0].set_title('Original' + prefix)
    plot_acf(df, lags=lags, ax=axes[0, 1])

    # First Difference
    df_first_diff = df.diff().dropna()
    axes[1, 0].plot(df_first_diff)
    axes[1, 0].set_title('First Order Difference' + prefix)
    plot_acf(df_first_diff, lags=lags - 1, ax=axes[1, 1])

    # Second Difference
    df_second_diff = df.diff().diff().dropna()
    axes[2, 0].plot(df_second_diff)
    axes[2, 0].set_title('Second Order Difference' + prefix)
    plot_acf(df_second_diff, lags=lags - 2, ax=axes[2, 1])
    plt.tight_layout()
    plt.show()
    
auto_correlation(df_sales['beer'], '', 10)</pre></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" data-attachment-id="7076" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-8-14/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/04/image-8.png" data-orig-size="826,824" 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-8" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/04/image-8.png" src="https://www.relataly.com/wp-content/uploads/2022/04/image-8.png" alt="ARIMA Python Time Series Forecasting Sales Data, checking for stationarity" class="wp-image-7076" width="561" height="560" srcset="https://www.relataly.com/wp-content/uploads/2022/04/image-8.png 826w, https://www.relataly.com/wp-content/uploads/2022/04/image-8.png 300w, https://www.relataly.com/wp-content/uploads/2022/04/image-8.png 150w, https://www.relataly.com/wp-content/uploads/2022/04/image-8.png 768w" sizes="(max-width: 561px) 100vw, 561px" /></figure>



<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;:true,&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;}">(0.019143247561160443, False)</pre></div>



<p id="block-db542169-554a-4820-a6a7-a0df5b3b9b6e">The charts above show that the time series becomes stationary after one order differencing. However, we can see that the lag goes into the negative very quickly, which indicates overdifferencing.</p>



<p>Next, we perform the same procedure for the seasonal part of our time series.</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;}"># 3.2 Seasonal part

# Reduce the timeframe to a single seasonal period
df_sales_s = df_sales['beer'][0:12]

# Autocorrelation for the seasonal part
auto_correlation(df_sales_s, '', 10)</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="3102" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-20-5/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2021/03/image-20.png" data-orig-size="831,827" 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-20" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2021/03/image-20.png" src="https://www.relataly.com/wp-content/uploads/2021/03/image-20.png" alt="arima time series components" class="wp-image-3102" width="571" height="568" srcset="https://www.relataly.com/wp-content/uploads/2021/03/image-20.png 831w, https://www.relataly.com/wp-content/uploads/2021/03/image-20.png 150w, https://www.relataly.com/wp-content/uploads/2021/03/image-20.png 768w, https://www.relataly.com/wp-content/uploads/2021/03/image-20.png 120w" sizes="(max-width: 571px) 100vw, 571px" /></figure>



<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;}"># Check if the first difference of the seasonal period is stationary
df_diff = pd.DataFrame(df_sales_s.diff())
df_diff.index = pd.date_range(df_sales_s.diff().iloc[1], periods=12, freq='MS') 
check_stationarity(df_diff, &quot;First Difference (Seasonal)&quot;, ['difference'])</pre></div>



<figure class="wp-block-image size-large is-resized"><img decoding="async" data-attachment-id="3010" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-8-9/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2021/03/image-8.png" data-orig-size="1569,441" 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-8" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2021/03/image-8.png" src="https://www.relataly.com/wp-content/uploads/2021/03/image-8-1024x288.png" alt="seasonality after differencing, arima time series forecasting" class="wp-image-3010" width="687" height="193" srcset="https://www.relataly.com/wp-content/uploads/2021/03/image-8.png 1024w, https://www.relataly.com/wp-content/uploads/2021/03/image-8.png 300w, https://www.relataly.com/wp-content/uploads/2021/03/image-8.png 768w, https://www.relataly.com/wp-content/uploads/2021/03/image-8.png 1536w, https://www.relataly.com/wp-content/uploads/2021/03/image-8.png 1569w" sizes="(max-width: 687px) 100vw, 687px" /></figure>



<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;:true,&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;}">(0.99, True)</pre></div>



<p id="block-3731e774-0091-46b9-afa1-2d55e1512fdd">After first order differencing, the seasonal part of the time series is stationary. The autocorrelation plot shows that the values go into the negative but remain within acceptable boundaries. Second-order differencing does not seem to improve these values. Consequently, we conclude that first-order differencing is a good choice for the D parameter. </p>



<h3 class="wp-block-heading" id="h-step-4-finding-an-optimal-model-with-auto-arima">Step #4 Finding an Optimal Model with Auto-ARIMA</h3>



<p>Next, we auto-fit an ARIMA model to our time series. In this way, we ensure that we can later measure the performance of our model against a fresh set of data that the model has not seen so far. We will split our dataset into train and test in preparation for this. </p>



<p>Once we have created the train and test data sets, we can configure the parameters for the auto_arima stepwise optimization. By setting max_d = 1, we tell the model to test no-differencing and first-order differencing. Also, we set max_p and max_q to 3. </p>



<p>To deal with the seasonality in our time series, we set the &#8220;seasonal&#8221; parameter to True and the &#8220;m&#8221; parameter to 12 data points. We turn our model into a SARIMA model that allows us to configure additional D, P, and Q parameters. We define a max value for Q and P of 3. Previously we have already seen that further differencing does not improve the Stationarity. Therefore, we can set the value of D to 1.</p>



<p>After configuring the parameters, we next fit the model to the time series. The model will try to find the optimal parameters and choose the model with the least AIC.</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;}"># split into train and test
pred_periods = 30
split_number = df_sales['beer'].count() - pred_periods # corresponds to a prediction horizion  of 2,5 years
df_train = pd.DataFrame(df_sales['beer'][:split_number]).rename(columns={'beer':'y_train'})
df_test = pd.DataFrame(df_sales['beer'][split_number:]).rename(columns={'beer':'y_test'})

# auto_arima
model_fit = pm.auto_arima(df_train, test='adf', 
                         max_p=3, max_d=3, max_q=3, 
                         seasonal=True, m=12,
                         max_P=3, max_D=2, max_Q=3,
                         trace=True,
                         error_action='ignore',  
                         suppress_warnings=True, 
                         stepwise=True)

# summarize the model characteristics
print(model_fit.summary())</pre></div>



<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;}">Performing stepwise search to minimize aic
 ARIMA(2,0,2)(1,1,1)[12] intercept   : AIC=inf, Time=3.89 sec
 ARIMA(0,0,0)(0,1,0)[12] intercept   : AIC=3383.210, Time=0.02 sec
 ARIMA(1,0,0)(1,1,0)[12] intercept   : AIC=3351.655, Time=0.38 sec
 ARIMA(0,0,1)(0,1,1)[12] intercept   : AIC=3364.350, Time=1.09 sec
 ARIMA(0,0,0)(0,1,0)[12]             : AIC=3604.145, Time=0.02 sec
 ARIMA(1,0,0)(0,1,0)[12] intercept   : AIC=3349.908, Time=0.11 sec
 ARIMA(1,0,0)(0,1,1)[12] intercept   : AIC=3351.532, Time=0.29 sec
 ARIMA(1,0,0)(1,1,1)[12] intercept   : AIC=3353.520, Time=1.24 sec
 ARIMA(2,0,0)(0,1,0)[12] intercept   : AIC=3312.656, Time=0.10 sec
 ARIMA(2,0,0)(1,1,0)[12] intercept   : AIC=3314.483, Time=0.57 sec
 ARIMA(2,0,0)(0,1,1)[12] intercept   : AIC=3314.378, Time=0.30 sec
 ARIMA(2,0,0)(1,1,1)[12] intercept   : AIC=3305.552, Time=3.02 sec
 ARIMA(2,0,0)(2,1,1)[12] intercept   : AIC=3291.425, Time=4.19 sec
 ARIMA(2,0,0)(2,1,0)[12] intercept   : AIC=3306.914, Time=3.06 sec
 ARIMA(2,0,0)(3,1,1)[12] intercept   : AIC=3276.501, Time=4.67 sec
 ARIMA(2,0,0)(3,1,0)[12] intercept   : AIC=3282.240, Time=5.24 sec
 ARIMA(2,0,0)(3,1,2)[12] intercept   : AIC=inf, Time=7.39 sec
 ARIMA(2,0,0)(2,1,2)[12] intercept   : AIC=inf, Time=4.74 sec
 ARIMA(1,0,0)(3,1,1)[12] intercept   : AIC=3313.877, Time=5.17 sec
 ARIMA(3,0,0)(3,1,1)[12] intercept   : AIC=3246.820, Time=5.72 sec
 ARIMA(3,0,0)(2,1,1)[12] intercept   : AIC=3255.313, Time=5.33 sec
 ARIMA(3,0,0)(3,1,0)[12] intercept   : AIC=3249.998, Time=6.77 sec
 ARIMA(3,0,0)(3,1,2)[12] intercept   : AIC=inf, Time=8.39 sec
 ARIMA(3,0,0)(2,1,0)[12] intercept   : AIC=3259.938, Time=3.55 sec
...
===================================================================================

Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).</pre></div>



<p>Auto-ARIMA has determined that the best model is (3,0,0)(3,1,1). These results match the results from section 3, in which we manually performed differencing. </p>



<h3 class="wp-block-heading" id="h-step-5-simulate-the-time-series-using-in-sample-forecasting">Step #5 Simulate the Time Series using in-sample Forecasting</h3>



<p>Now that we have trained our model, we want to use it to simulate the entire time series. We will do this by calling the predict method in the sample function. The prediction will match the same period as the original time series with which we trained the model. Because the model predicts one step, the prediction results will naturally be close to the actual values.</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;}"># Generate in-sample Predictions
# The parameter dynamic=False means that the model makes predictions upon the lagged values.
# This means that the model is trained until a point in the time-series and then tries to predict the next value.
pred = model_fit.predict_in_sample(dynamic=False) # works only with auto-arima
df_train['y_train_pred'] = pred

# Calculate the percentage difference
df_train['diff_percent'] = abs((df_train['x_train'] - pred) / df_train['x_train'])* 100

# Print the predicted time-series
fig, ax1 = plt.subplots(figsize=(16, 8))
plt.title(&quot;In Sample Sales Prediction&quot;, fontsize=14)
sns.lineplot(data=df_train[['x_train', 'y_train_pred']], linewidth=1.0)

# Print percentage prediction errors on a separate axis (ax2)
ax2 = ax1.twinx() 
ax2.set_ylabel('Prediction Errors in %', color='purple', fontsize=14)  
ax2.set_ylim([0, 50])
ax2.bar(height=df_train['diff_percent'][20:], x=df_train.index[20:], width=20, color='purple', label='absolute errors')
plt.legend()
plt.show()</pre></div>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="521" data-attachment-id="11758" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/image-6/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/12/image-6.png" data-orig-size="1620,825" 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-6" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/12/image-6.png" src="https://www.relataly.com/wp-content/uploads/2022/12/image-6-1024x521.png" alt="arima forecast for us bear sales created in python" class="wp-image-11758" srcset="https://www.relataly.com/wp-content/uploads/2022/12/image-6.png 1024w, https://www.relataly.com/wp-content/uploads/2022/12/image-6.png 300w, https://www.relataly.com/wp-content/uploads/2022/12/image-6.png 768w, https://www.relataly.com/wp-content/uploads/2022/12/image-6.png 1536w, https://www.relataly.com/wp-content/uploads/2022/12/image-6.png 1620w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Next, we take a look at the prediction errors.</p>



<h3 class="wp-block-heading" id="h-step-6-generate-and-visualize-a-sales-forecast">Step #6 Generate and Visualize a Sales Forecast</h3>



<p>Now that we have trained an optimal model, we are ready to generate a sales forecast. First, we specify the number of periods that we want to predict. In addition, we create an index from the number of predictions adjacent to the original time series and continue it (prediction_index).</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;}"># Generate prediction for n periods, 
# Predictions start from the last date of the training data
test_pred = model_fit.predict(n_periods=pred_periods, dynamic=False)
df_test['y_test_pred'] = test_pred
df_union = pd.concat([df_train, df_test])
df_union.rename(columns={'beer':'y_test'}, inplace=True)

# Print the predicted time-series
fig, ax = plt.subplots(figsize=(16, 8))
plt.title(&quot;Test/Pred Comparison&quot;, fontsize=14)
sns.despine();
sns.lineplot(data=df_union[['y_train', 'y_train_pred', 'y_test', 'y_test_pred']], linewidth=1.0, dashes=False, palette='muted')
ax.set_xlim([df_union.index[150],df_union.index.max()])
plt.legend()
plt.show()</pre></div>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="539" data-attachment-id="8529" data-permalink="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1/#main" data-orig-file="https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png" data-orig-size="1566,825" 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="arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1" data-image-description="" data-image-caption="" data-large-file="https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png" src="https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1-1024x539.png" alt="time series forecast on us beer sales with arima Test Pred Comparison, python tutorial" class="wp-image-8529" srcset="https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png 1024w, https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png 300w, https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png 768w, https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png 1536w, https://www.relataly.com/wp-content/uploads/2022/05/arima-plot-seaborn-beer-sales-forecasting-python-test-predictions-1.png 1566w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>As shown above, our model&#8217;s forecast continues the seasonal pattern of the beer sales time series. On the one hand, this indicates that US beer sales will continue to rise and, on the other hand, that our model works just fine 🙂</p>



<h3 class="wp-block-heading" id="h-step-7-measure-the-performance-of-the-sales-forecasting-model">Step #7 Measure the Performance of the Sales Forecasting Model</h3>



<p>In this section, we will measure the performance of our ARIMA model. To learn more about this topic, check out <a href="https://www.relataly.com/regression-error-metrics-python/923/" target="_blank" rel="noreferrer noopener">this relataly article measuring regression performance</a>.</p>



<p>The previous section&#8217;s simulation chart shows a few outliers among the prediction errors. Therefore, we focus our analysis on the percentage errors. Two helpful metrics are the mean absolute error (MAPE) and the mean absolute percentage error (MDAPE).</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;}"># Mean Absolute Percentage Error (MAPE)
MAPE = np.mean((np.abs(np.subtract(df_test['y_test'], df_test['y_test_pred'])/ df_test['y_test']))) * 100
print(f'Mean Absolute Percentage Error (MAPE): {np.round(MAPE, 2)} %')

# Median Absolute Percentage Error (MDAPE)
MDAPE = np.median((np.abs(np.subtract(df_test['y_test'], df_test['y_test_pred'])/ df_test['y_test'])) ) * 100
print(f'Median Absolute Percentage Error (MDAPE): {np.round(MDAPE, 2)} %')</pre></div>



<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;}">Mean Absolute Percentage Error (MAPE): 3.94 %  Median Absolute Percentage Error (MDAPE): 3.49 %</pre></div>



<p>The percent errors show that our ARIMA model achieves a decent predictive performance.</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-9d6595d7 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>This Python tutorial has shown how to use SARIMA for sales forecasting. Sales forecasting is important for businesses because it can help them to make informed decisions about production, inventory management, and staffing, among other things. By accurately forecasting sales, businesses can ensure that they have the right amount of product available to meet customer sales, avoid overproduction and excess inventory, and plan for future growth. The use cases presented were forecasting beer sales, and we have used arima to analyze seasonal sales data. </p>



<p>In the first part, we have learned how ARIMA works, what Stationarity is and how to check if a time series is stationary. In the second part, we developed an ARIMA model in Python to create a forecast for US beer sales. For this purpose, we created an in-sample forecast and used Auto-tARIMA to find the optimal parameters for our sales forecasting model.</p>



<p>If you have any questions or suggestions, please let me know in the comments, and I will do my best to answer. </p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%"><div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="506" height="496" data-attachment-id="12603" data-permalink="https://www.relataly.com/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min/" data-orig-file="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min.png" data-orig-size="506,496" 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="Now that we have learned to use ARIMA to forecast beer sales, you really deserved yourself a beer. Cheers! Image created with Midjourney" data-image-description="&lt;p&gt;Now that we have learned to use ARIMA to forecast beer sales, you really deserved yourself a beer. Cheers! Image created with Midjourney&lt;/p&gt;
" data-image-caption="&lt;p&gt;Now that we have learned to use ARIMA to forecast beer sales, you really deserved yourself a beer. Cheers! Image created with Midjourney&lt;/p&gt;
" data-large-file="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min.png" src="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min.png" alt="Now that we have learned to use ARIMA to forecast beer sales, you really deserved yourself a beer. Cheers! Image created with Midjourney" class="wp-image-12603" srcset="https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min.png 506w, https://www.relataly.com/wp-content/uploads/2023/03/brewery-arima-beer-sales-forecasting-python-tutorial-machine-learning-relataly2-min.png 300w" sizes="(max-width: 506px) 100vw, 506px" /><figcaption class="wp-element-caption">Now that you have learned to use ARIMA to forecast beer sales, you really earned yourself a beer. Cheers! Image created with <a href="http://www.midjourney.com" target="_blank" rel="noreferrer noopener">Midjourney</a></figcaption></figure>
</div></div>
</div>



<p></p>



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



<ol class="wp-block-list"><li><a href="https://amzn.to/3MyU6Tj" target="_blank" rel="noreferrer noopener">Charu C. Aggarwal (2018) Neural Networks and Deep Learning</a></li><li><a href="https://amzn.to/3yIQdWi" target="_blank" rel="noreferrer noopener">Jansen (2020) Machine Learning for Algorithmic Trading: Predictive models to extract signals from market and alternative data for systematic trading strategies with Python</a></li><li><a href="https://amzn.to/3S9Nfkl" target="_blank" rel="noreferrer noopener">Aurélien Géron (2019) Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems </a></li><li><a href="https://amzn.to/3EKidwE" target="_blank" rel="noreferrer noopener">David Forsyth (2019) Applied Machine Learning Springer</a></li><li><a href="https://amzn.to/3MAy8j5" target="_blank" rel="noreferrer noopener">Andriy Burkov (2020) Machine Learning Engineering</a></li></ol>



<p class="has-contrast-2-color has-base-3-background-color has-text-color has-background"><em>The links above to Amazon are affiliate links. By buying through these links, you support the Relataly.com blog and help to cover the hosting costs. Using the links does not affect the price.</em></p>



<p>Want to learn more about time series analysis and prediction?<br>Check out these recent relataly tutorials:</p>



<ul class="wp-block-list">
<li><a href="https://www.relataly.com/stock-market-prediction-using-a-recurrent-neural-network/122/" target="_blank" rel="noreferrer noopener">Stock Market Prediction &#8211; Building a&nbsp;Univariate Model using Keras Recurrent Neural Networks in Python</a>.</li>



<li><a href="https://www.relataly.com/stock-market-prediction-with-multivariate-time-series-in-python/1815/" target="_blank" rel="noreferrer noopener">Building Multivariate Time Series Models for Stock Market Prediction with Python</a></li>



<li><a href="https://www.relataly.com/multi-step-time-series-forecasting-a-step-by-step-guide/275/" target="_blank" rel="noreferrer noopener">Time Series Forecasting &#8211; Creating a Multi-Step Forecast in Python</a></li>



<li><a href="https://www.relataly.com/measuring-prediction-errors-in-time-series-forecasting/809/" target="_blank" rel="noreferrer noopener">Python Cheat Sheet: Measuring Prediction Errors in Time Series Forecasting</a></li>



<li><a href="https://www.relataly.com/evaluating-time-series-forecasting-models/923/" target="_blank" rel="noreferrer noopener">Evaluate Time Series Forecasting Models with Python</a></li>
</ul>
<p>The post <a href="https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/">Forecasting Beer Sales with ARIMA in Python</a> appeared first on <a href="https://www.relataly.com">relataly.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.relataly.com/forecasting-beer-sales-with-arima-in-python/2884/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2884</post-id>	</item>
	</channel>
</rss>
