<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kheff</title>
    <description>The latest articles on DEV Community by Kheff (@kevinheng).</description>
    <link>https://dev.to/kevinheng</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F941747%2F68e81164-9537-4ae1-aa26-c9d65114b71a.jpeg</url>
      <title>DEV Community: Kheff</title>
      <link>https://dev.to/kevinheng</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevinheng"/>
    <language>en</language>
    <item>
      <title>Predict Store Sales Data With MindsDB using Machine Learning and SQL</title>
      <dc:creator>Kheff</dc:creator>
      <pubDate>Thu, 13 Oct 2022 16:07:27 +0000</pubDate>
      <link>https://dev.to/kevinheng/predict-store-sales-data-with-mindsdb-using-machine-learning-and-sql-2af8</link>
      <guid>https://dev.to/kevinheng/predict-store-sales-data-with-mindsdb-using-machine-learning-and-sql-2af8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WxxjWg76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kcxb3s7walryp46zmtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WxxjWg76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kcxb3s7walryp46zmtc.png" alt="Image description" width="777" height="428"&gt;&lt;/a&gt;## Introduction&lt;br&gt;
MindsDB is the next step we beginners can take towards learning data science and machine learning. MindsDB has embedded their software with AI and Machine Learning in order to assist us with recognizing the patterns of data, predict trends and train machine learning model in minutes.&lt;/p&gt;

&lt;p&gt;In this tutorial, We will explore how we can use MindsDB Cloud to train a Time Series Model and predict the Store Sales Data. You can download the dataset which we will use in this tutorial &lt;a href="https://www.kaggle.com/datasets/laurinbrechter/store-sales-data?select=Store+632.csv"&gt;here&lt;/a&gt; (The file name is Store 632.csv).&lt;/p&gt;
&lt;h2&gt;
  
  
  Before We Start!!
&lt;/h2&gt;

&lt;p&gt;If you don't have a MindsDB Cloud yet, you can create a free trial account &lt;a href="https://cloud.mindsdb.com/register"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you're logged in, you will be directed to MindsDB Cloud Editor.&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding Data to the Cloud
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; On the top left corner of your screen, you will find 2 buttons 'Query' and 'Add Data'. Click the &lt;code&gt;Add Data&lt;/code&gt; in order to import data into your &lt;strong&gt;MindsDB Cloud Editor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; In the &lt;strong&gt;Datasource&lt;/strong&gt; page select &lt;code&gt;Files&lt;/code&gt; and choose &lt;code&gt;Import File&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fzc8g4vN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nz35ivdyzyxojv2vv26n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fzc8g4vN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nz35ivdyzyxojv2vv26n.png" alt="Image description" width="880" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Select the file you want to import and give a &lt;code&gt;Table name&lt;/code&gt;. Once done, click &lt;code&gt;Save and Continue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MmlkJ5Zv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr6bi51lahh7l018n7qg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MmlkJ5Zv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr6bi51lahh7l018n7qg.png" alt="Image description" width="880" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Once the file is uploaded, you will see 2 queries in the MindsDB Cloud Editor and execute them to see if the is created with proper data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UwONYJGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vm6p8vdg9wyudysmt0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UwONYJGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vm6p8vdg9wyudysmt0c.png" alt="Image description" width="880" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a81fdU2_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8rnuyrxqpxyv4b4zd2m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a81fdU2_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8rnuyrxqpxyv4b4zd2m.png" alt="Image description" width="880" height="408"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Training a Predictor Model
&lt;/h2&gt;

&lt;p&gt;Training a Predictor Model has never been easier, with MindsDB you just need basic SQL knowledge to get the job done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Use &lt;code&gt;CREATE PREDICTOR&lt;/code&gt; syntax, and specify what query to train &lt;code&gt;FROM&lt;/code&gt; and what to &lt;code&gt;PREDICT&lt;/code&gt;. Below is a template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE PREDICTOR mindsdb.[predictor_name]
FROM [integration_name]
    (SELECT [sequential_column], [partition_column], [other_column], [target_column] FROM [table_name])
PREDICT [target_column]

ORDER BY [sequential_column]
GROUP BY [partition_column]

WINDOW [int]
HORIZON [int]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let plugin the parameters into the query and execute it. After execution, we will get a message whether it was successful or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE PREDICTOR mindsdb.nest
FROM files.stores_sales
    (SELECT * FROM files.store_sales)
PREDICT `Dollar Sales`
ORDER BY Date
GROUP BY SKU
WINDOW 20
HORIZON 7;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MsQjOK4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xol6t6cqtdjsnm3vtfyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MsQjOK4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xol6t6cqtdjsnm3vtfyc.png" alt="Image description" width="880" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; If your dataset is large, the Predictor may take a while to train. While it is training, you can check it's status by running this query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * 
FROM mindsdb.predictors
WHERE name='[predictor_name]'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qaOnWQjH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x4v2g09xe348thntwvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qaOnWQjH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x4v2g09xe348thntwvm.png" alt="Image description" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Making Predictions
&lt;/h2&gt;

&lt;p&gt;We can make predictions by simply treating it as a query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT `Dollar Sales`,
        `Dollar Sales_explain`
From mindsdb.nexte
WHERE `Unit Sales` = 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vl-pOkw7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i511ohxlh8o8a5od5ww0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vl-pOkw7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i511ohxlh8o8a5od5ww0.png" alt="Image description" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also make a bulk prediction by join the table with your model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT t.`Dollar Sales` as real_p,
        m.`Dollar Sales` as predicted_p,
        t.`Unit Sales`, t.Date, t.SKU
FROM files.store_sales as t
JOIN mindsdb.example_model as m limit 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5fHPM9xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbyqxdi00zzp9rrrut2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5fHPM9xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbyqxdi00zzp9rrrut2t.png" alt="Image description" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulation, you have just trained your own &lt;code&gt;Time Series Predictive Model&lt;/code&gt;. To recap our tutorial, we setup our own MindsDB Cloud account, uploaded our datasets, created and trained our predictive model and make predictions with our uploaded data.&lt;/p&gt;

&lt;p&gt;Now, I would recommend you to test out other datasets with MindsDB and improve your machine learning and data science skill.''&lt;/p&gt;

&lt;p&gt;Remember, Always to have fun coding!&lt;/p&gt;

</description>
      <category>sql</category>
      <category>tutorial</category>
      <category>mindsdb</category>
      <category>hacktoberfest2022</category>
    </item>
  </channel>
</rss>
