<?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: Jon Wood</title>
    <description>The latest articles on DEV Community by Jon Wood (@jwood803).</description>
    <link>https://dev.to/jwood803</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%2F161201%2Fdf7dcf36-1f9d-49b6-930e-96dffa70d150.jpeg</url>
      <title>DEV Community: Jon Wood</title>
      <link>https://dev.to/jwood803</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jwood803"/>
    <language>en</language>
    <item>
      <title>Use Bing Image Search to Get Training Image Data</title>
      <dc:creator>Jon Wood</dc:creator>
      <pubDate>Wed, 08 Dec 2021 11:36:06 +0000</pubDate>
      <link>https://dev.to/jwood803/use-bing-image-search-to-get-training-image-data-n60</link>
      <guid>https://dev.to/jwood803/use-bing-image-search-to-get-training-image-data-n60</guid>
      <description>&lt;p&gt;When going through the FastAI book, &lt;a href="https://amzn.to/3FIWUsw"&gt;Deep Learning for Coders&lt;/a&gt;, I noticed that in one of the early chapters they mention using the &lt;a href="https://docs.microsoft.com/en-us/bing/search-apis/bing-image-search/overview"&gt;Bing Image Search API&lt;/a&gt; to retrieve images for training data. While they have a nice wrapper for the API, I thought I'd dive into the API as well and use it to build my own way to download training image data.&lt;/p&gt;

&lt;p&gt;Let's suppose we need to make an image classification model to determine what kind of car is in an image. We'd need quite a bit of different images for this model, so let's use the Bing Image Search to gather images of the Aston-Martin car so we can start getting our data.&lt;/p&gt;

&lt;p&gt;Check out the below for a video version of this post.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/lKCxQ6mxuy0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Bing Image Search
&lt;/h2&gt;

&lt;p&gt;Before going into the technical side of Bing Image Search, let's go over why use this in the first place. Why not just download the images ourselves?&lt;/p&gt;

&lt;p&gt;Bing Images Search has a few features in it that we can utilize in our code when getting our images. Some of these features are important to take into account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automation
&lt;/h3&gt;

&lt;p&gt;I'll be honest, I'm lazy and if I can script something to do a task for me then I'll definitely spend the time to build the script rather than do the task manually. Rather than manually finding images and downloading them, we can use the Bing Image Search API to do this for us.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image License
&lt;/h3&gt;

&lt;p&gt;We can't always just take an image from a website and use it however we want. A lot of images that are online are copyrighted and if we don't have a license to use the copyright we are actually in violation of the creator's copyright. If they find out we use their image without a license or permission then they can, more than likely, take legal action against us.&lt;/p&gt;

&lt;p&gt;However, with Bing Image Search, we have an option to specify what license the images has that get returned to us. We can do this with the &lt;code&gt;licenseType&lt;/code&gt; query parameter in our API call. This utilizes &lt;a href="https://creativecommons.org/"&gt;Creative Commons&lt;/a&gt; licenses. We can specify exactly what type of license our images has. We can specify that want images that are public where the copyright is fully waived, which is what we will do. There are many Creative Commons license types that the Bing Image Search supports and there's a full list &lt;a href="https://docs.microsoft.com/en-us/bing/search-apis/bing-image-search/reference/query-parameters#license"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image Type
&lt;/h3&gt;

&lt;p&gt;There are quite a few images types that we could download from Bing Image Search. For our purposes, though, we only want photos of Aston Martin cars. Due to that, we can specify the image type in our API calls to just &lt;code&gt;photo&lt;/code&gt;. If we don't specify this we could get back animated GIFs, clip art, or drawings of Aston Martin cars.&lt;/p&gt;

&lt;h3&gt;
  
  
  Safe Content
&lt;/h3&gt;

&lt;p&gt;When downloading images from the internet you never really know what you're going to get. Bing Image Search can help ease that worry by specifying that you want only safe content to be returned.&lt;/p&gt;

&lt;p&gt;Bing can do this filtering for us so we don't have to worry about it when we do our API call. This is one less thing we have to worry about and, because it's the internet, it's definitely something to worry about when download images.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Azure Resource
&lt;/h2&gt;

&lt;p&gt;Before we can use the Bing Image Search API we need to create the resource for it. In the Azure Portal create a new resource and search for "Bing Search". Then, click on the "Bing Search v7" resource to create it.&lt;/p&gt;

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

&lt;p&gt;When creating the resource give it a name, what resource group it will be under, and what subscription it will be under. For the pricing tier, it does have a free tier to allow you to give the service a try for evaluation or for a proof of concept. Once that is complete, click "Create".&lt;/p&gt;

&lt;p&gt;When that completes deployment, we can explore a bit on the resource page. One thing to note is that there are a few things we can look at here. There's a "Try me" tab where we can try the Bing Search API and see what results we get. There is some sample code to see real quick how to use the Bing Search API. And there are a lot of tutorials that we can look at if we want to look at something more specific, such as the image or video search APIs.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Retrieve Key and Endpoint
&lt;/h2&gt;

&lt;p&gt;To use the API in our code we will need the API key and the endpoint to call. There are a couple of ways we can get to it. First, on the "Overview" page of the resource there's a link that says to "click here to manage keys". Clicking that will take you to another page where you can get the API keys and the endpoint URL.&lt;/p&gt;

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

&lt;p&gt;You can also click on the "Keys and Endpoint" section on the left navigation.&lt;/p&gt;

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

&lt;p&gt;Now save the API key and the endpoint since we'll need those to access the API in the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the API
&lt;/h2&gt;

&lt;p&gt;Now we get to the fun stuff where we can get into some code. I'll be using Python, but you're very welcome to use the language of your choice since this is a simple API call. I'm also using Azure ML since it's very easy to get a Jupyter Lab instance running plus most machine learning and data science packages already installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Imports
&lt;/h3&gt;

&lt;p&gt;First, we need to import some modules. We have four that we will need to import.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JSON&lt;/strong&gt;: This will be used to read in a config file for the API key and endpoint&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Requests&lt;/strong&gt;: Will be used to make the API calls. This is pre-installed in an Azure ML Jupyter instance, so you may need to run &lt;code&gt;pip install requests&lt;/code&gt; if you are using another envrionment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time&lt;/strong&gt;: Used to delay API calls so the server doesn't get hit too much by requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OS&lt;/strong&gt;: Used to saved and help clean image data on the local machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PPrint&lt;/strong&gt;: Used to format JSON when printing.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pprint&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The API Call
&lt;/h3&gt;

&lt;p&gt;Now, we can start building and making the API call to get the image data. &lt;/p&gt;

&lt;h4&gt;
  
  
  Building the Endpoint
&lt;/h4&gt;

&lt;p&gt;To start building the call, we need to get the API key which is kept in a JSON file for security reasons. We'll use the &lt;code&gt;open&lt;/code&gt; method to open the file to be able to read it and use the &lt;code&gt;json&lt;/code&gt; module to load the JSON file. This creates a dictionary where the JSON keys are the key names of the dictionary where you can get the values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"config.json"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"apiKey"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have the API key we can build up the URL to make the API call. We can use the endpoint that we got from the Azure Portal and help build up the URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;endpoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.bing.microsoft.com/"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the endpoint, we have to add some to it to tell it that we want the Image Search API. To learn more about the exact endpoints we're using here, &lt;a href="https://docs.microsoft.com/en-us/bing/search-apis/bing-image-search/reference/endpoints"&gt;this doc&lt;/a&gt; has a lot of good information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;endpoint&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;v7.0/images/search"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Building the Headers and Query Parameters
&lt;/h4&gt;

&lt;p&gt;Some more information we need to add to our call are the headers and the query parameters. The headers is where we supply the API key and the query parameters detail what images we want to return.&lt;/p&gt;

&lt;p&gt;Requests makes it easy to specify the headers, which is done as a dictionary. We need to supply the &lt;code&gt;Ocp-Apim-Subscription-Key&lt;/code&gt; header for the API key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query parameters are also done as a dictionary. We'll supply the license, image type, and safe search parameters here. Those are optional parameters, but the &lt;code&gt;q&lt;/code&gt;&lt;br&gt;
parameter is required which is what query we want to use to search for images. For our query here, we'll search for aston martin cars.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"q"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"aston martin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="s"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"public"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="s"&gt;"imageType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"photo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"safeSearch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Strict"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Making the API Call
&lt;/h4&gt;

&lt;p&gt;With everything ready, we can now make the API call and get the results. With &lt;code&gt;requests&lt;/code&gt; we can just call the &lt;code&gt;get&lt;/code&gt; method. In there we pass in the URl, the headers, and the parameters. We use the &lt;code&gt;raise_for_status&lt;/code&gt; method to throw an exception if the status code isn't successful. Then, we get the JSON of the response and store that into a variable. Finally, we use the pretty print method to print the JSON response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's a snapshot of the response. There's quite a bit here but we'll break it down some later in this post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'_type': 'Images',
 'currentOffset': 0,
 'instrumentation': {'_type': 'ResponseInstrumentation'},
 'nextOffset': 38,
 'totalEstimatedMatches': 475,
 'value': [{'accentColor': 'C6A105',
            'contentSize': '1204783 B',
            'contentUrl': '[https://www.publicdomainpictures.net/pictures/380000/velka/aston-martin-car-1609287727yik.jpg](https://www.publicdomainpictures.net/pictures/380000/velka/aston-martin-car-1609287727yik.jpg)',
            'creativeCommons': 'PublicNoRightsReserved',
            'datePublished': '2021-02-06T20:45:00.0000000Z',
            'encodingFormat': 'jpeg',
            'height': 1530,
            'hostPageDiscoveredDate': '2021-01-12T00:00:00.0000000Z',
            'hostPageDisplayUrl': '[https://www.publicdomainpictures.net/view-image.php?image=376994&amp;amp;amp;picture=aston-martin-car](https://www.publicdomainpictures.net/view-image.php?image=376994&amp;amp;amp;picture=aston-martin-car)',
            'hostPageFavIconUrl': '[https://www.bing.com/th?id=ODF.lPqrhQa5EO7xJHf8DMqrJw&amp;amp;amp;pid=Api](https://www.bing.com/th?id=ODF.lPqrhQa5EO7xJHf8DMqrJw&amp;amp;amp;pid=Api)',
            'hostPageUrl': '[https://www.publicdomainpictures.net/view-image.php?image=376994&amp;amp;amp;picture=aston-martin-car](https://www.publicdomainpictures.net/view-image.php?image=376994&amp;amp;amp;picture=aston-martin-car)',
            'imageId': '38DBFEF37523B232A6733D7D9109A21FCAB41582',
            'imageInsightsToken': 'ccid_WTqn9r3a*cp_74D633ADFCF41C86F407DFFCF0DEC38F*mid_38DBFEF37523B232A6733D7D9109A21FCAB41582*simid_608053462467504486*thid_OIP.WTqn9r3aKv5TLZxszieEuQHaF5',
            'insightsMetadata': {'availableSizesCount': 1,
                                 'pagesIncludingCount': 1},
            'isFamilyFriendly': True,
            'name': 'Aston Martin Car Free Stock Photo - Public Domain '
                    'Pictures',
            'thumbnail': {'height': 377, 'width': 474},
            'thumbnailUrl': '[https://tse2.mm.bing.net/th?id=OIP.WTqn9r3aKv5TLZxszieEuQHaF5&amp;amp;amp;pid=Api](https://tse2.mm.bing.net/th?id=OIP.WTqn9r3aKv5TLZxszieEuQHaF5&amp;amp;amp;pid=Api)',
            'webSearchUrl': '[https://www.bing.com/images/search?view=detailv2&amp;amp;amp;FORM=OIIRPO&amp;amp;amp;q=aston+martin&amp;amp;amp;id=38DBFEF37523B232A6733D7D9109A21FCAB41582&amp;amp;amp;simid=608053462467504486](https://www.bing.com/images/search?view=detailv2&amp;amp;amp;FORM=OIIRPO&amp;amp;amp;q=aston+martin&amp;amp;amp;id=38DBFEF37523B232A6733D7D9109A21FCAB41582&amp;amp;amp;simid=608053462467504486)',
            'width': 1920}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to note from the response:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;nextOffset&lt;/code&gt;: This will help us page items to perform multiple requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;value.contentUrl&lt;/code&gt;: This is the actual URL of the image. We will use this URL to download the images.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Paging Through Results
&lt;/h3&gt;

&lt;p&gt;For a single API call we may get around 30 items or so by default. How do we get more images with the API? We page through the results. And the way to do this is to use the &lt;code&gt;nextOffset&lt;/code&gt; item in the API response. We can use this value to pass in another query parameter &lt;code&gt;offset&lt;/code&gt; to give the next page of results.&lt;/p&gt;

&lt;p&gt;So if I only want at most 200 images, I can use the below code to page through the API results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;new_offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;new_offset&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_offset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"offset"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_offset&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;new_offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"nextOffset"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;contentUrls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"contentUrl"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We initialize the offset to 0 so the initial call will give the first page of results. In the &lt;code&gt;while&lt;/code&gt; loop we limit to just 200 images for the offset. Within the loop we set the &lt;code&gt;offset&lt;/code&gt; parameter to the current offset, which will be 0 initially. Then we make the API call, we sleep or wait for one second, and we set the &lt;code&gt;offset&lt;/code&gt; parameter to the &lt;code&gt;nextOffset&lt;/code&gt; from the results and save the &lt;code&gt;contentUrl&lt;/code&gt; items from the results into a list. Then, we do it again until we reach the limit of our offset.&lt;/p&gt;

&lt;h3&gt;
  
  
  Downloading the Images
&lt;/h3&gt;

&lt;p&gt;In the previous API calls all we did was capture the &lt;code&gt;contentUrl&lt;/code&gt; items from each of the images. In order to get the images as training data we need to download them. Before we do that, let's set up our paths to be ready for images to be downloaded to them. First we set the path and then we use the &lt;code&gt;os&lt;/code&gt; module to check if the path exists. If it doesn't, we'll create it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dir_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"./aston-martin/train/"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir_path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;makedirs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Generally, we could just do the below code and loop through all of the content URL items and for each one we create the path with the &lt;code&gt;os.path.join&lt;/code&gt; method to get the correct path for the system we're on, and open the path with the &lt;code&gt;open&lt;/code&gt; method. With that we can use &lt;code&gt;requests&lt;/code&gt; again with the &lt;code&gt;get&lt;/code&gt; method and pass in the URL. Then, with the &lt;code&gt;open&lt;/code&gt; function, we can write to the path from the image contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;contentUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"wb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;image_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this is a bit more complicated than we would hope it would be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cleaning the Image Data
&lt;/h3&gt;

&lt;p&gt;If we print the image URLs for all that we get back it would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.publicdomainpictures.net/pictures/380000/velka/aston-martin-car-1609287727yik.jpg
https://images.pexels.com/photos/592253/pexels-photo-592253.jpeg?auto=compress&amp;amp;amp;cs=tinysrgb&amp;amp;amp;h=750&amp;amp;amp;w=1260
https://images.pexels.com/photos/2811239/pexels-photo-2811239.jpeg?cs=srgb&amp;amp;amp;dl=pexels-tadas-lisauskas-2811239.jpg&amp;amp;amp;fm=jpg
https://get.pxhere.com/photo/car-vehicle-classic-car-sports-car-vintage-car-coupe-antique-car-land-vehicle-automotive-design-austin-healey-3000-aston-martin-db2-austin-healey-100-69398.jpg
https://get.pxhere.com/photo/car-automobile-vehicle-automotive-sports-car-supercar-luxury-expensive-coupe-v8-martin-vantage-aston-land-vehicle-automotive-design-luxury-vehicle-performance-car-aston-martin-dbs-aston-martin-db9-aston-martin-virage-aston-martin-v8-aston-martin-dbs-v12-aston-martin-vantage-aston-martin-v8-vantage-2005-aston-martin-rapide-865679.jpg
https://c.pxhere.com/photos/5d/f2/car_desert_ferrari_lamborghini-1277324.jpg!d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you notice anything in the URLs? While most of then end in &lt;code&gt;jpeg&lt;/code&gt; there are a few with some extra parameters on the end. If we try to download with those URLs we won't get the image. So we need to do a little bit of data cleaning here.&lt;/p&gt;

&lt;p&gt;Luckily, there are two patterns we can check, if there is a &lt;code&gt;?&lt;/code&gt; in the URL and if there is a &lt;code&gt;!&lt;/code&gt; in the URL. With those patterns we can update our loop to download the images to the below to get the correct URLs for all images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;contentUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;split&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;last_item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;second_split&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;last_item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;second_split&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;last_item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;second_split&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;third_split&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;last_item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;third_split&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;last_item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;third_split&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"wb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;image_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;#image_data.raise_for_status()
&lt;/span&gt;
            &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this cleaning of the URLs we can get the full images.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;While this probably isn't as sophisticated as the wrapper that FastAI has, this should help if you need to get training images from Bing Image Search manually. You can also tweak this if needed.&lt;/p&gt;

&lt;p&gt;Using Bing Image Search is a great way to get quality and license appropriate images for training data.&lt;/p&gt;

</description>
      <category>cognitiveservices</category>
      <category>azure</category>
      <category>deeplearning</category>
      <category>python</category>
    </item>
    <item>
      <title>How the Machine Learning Process is Like Cooking</title>
      <dc:creator>Jon Wood</dc:creator>
      <pubDate>Tue, 18 May 2021 07:24:14 +0000</pubDate>
      <link>https://dev.to/jwood803/how-the-machine-learning-process-is-like-cooking-3kca</link>
      <guid>https://dev.to/jwood803/how-the-machine-learning-process-is-like-cooking-3kca</guid>
      <description>&lt;p&gt;When creating machine learning models it's important to follow the machine learning process in order to get the best performing model that you can into production and to keep it performing well.&lt;/p&gt;

&lt;p&gt;But why cooking? First, I enjoy cooking. But also, it is something we all do. Now, we all don't make five course meals every day or aim to be a Michelin star chef. We do follow a process to make our food, though, even if it may be to just heat it up in the microwave.&lt;/p&gt;

&lt;p&gt;In this post, I'll go over the machine learning process and how it relates to cooking to give a better understanding of the process and maybe even a way to help remember the steps.&lt;/p&gt;

&lt;p&gt;For the video version, check below:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Hqrkbxd69lM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Machine Learning Process
&lt;/h1&gt;

&lt;p&gt;First, let's briefly go over the machine learning process. Here's a diagram that's known as the cross-industry standard process for data mining, or simply known as &lt;a href="https://en.wikipedia.org/wiki/Cross-industry_standard_process_for_data_mining"&gt;CRISP-DM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u7XdsA3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgz6oijpcieecmoyyfaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u7XdsA3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgz6oijpcieecmoyyfaj.png" alt="CRISP-DM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kenneth Jensen - Own work based on:&lt;a href="//ftp://public.dhe.ibm.com/software/analytics/spss/documentation/modeler/18.0/en/ModelerCRISPDM.pdf"&gt;ftp://public.dhe.ibm.com/software/analytics/spss/documentation/modeler/18.0/en/ModelerCRISPDM.pdf&lt;/a&gt; (Figure 1)&lt;/p&gt;

&lt;p&gt;The machine learning process is pretty straight forward when going through the diagram:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Business understanding - What exactly is the problem we are trying to solve with data&lt;/li&gt;
&lt;li&gt;  Data understanding - What exactly is in our data, such as what does each column mean and how does it relate to the business problem&lt;/li&gt;
&lt;li&gt;  Data prep - Data preprocessing and preparation. This can also include feature engineering&lt;/li&gt;
&lt;li&gt;  Modeling - Getting a model from our data&lt;/li&gt;
&lt;li&gt;  Evaluation - Evaluating the model for performance on generalized data&lt;/li&gt;
&lt;li&gt;  Deployment - Deploying the model for production use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that a couple of items can go back and forth. You may do multiple iterations of getting a better understanding of the business problem and the data, data prep and modeling, and even going back to the business problem when evaluating a model.&lt;/p&gt;

&lt;p&gt;Notice that there's a circle around the whole process which means you may even have to go back to understanding the problem once a model is deployed.&lt;/p&gt;

&lt;p&gt;There are a couple of items I would add to help improve this process, though. First, we need to think about getting our data. Also, I believe can add a separate item in the process for improving, or optimizing, our model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Data
&lt;/h2&gt;

&lt;p&gt;I would actually add an item before or after defining the business problem, and that's getting data. Sometimes you may have the data already and define the business problem but you may have to get the data after defining the problem. Either way, we need good data. You may have heard an old saying in programming, "Garbage in, garbage out", and that applies to machine learning as well.&lt;/p&gt;

&lt;p&gt;We can't have a good model unless we give it good data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Improving the Model
&lt;/h2&gt;

&lt;p&gt;Once we have an algorithm we can also spend some time to improve it even further. We can deploy some techniques that can tweak the algorithm to perform better.&lt;/p&gt;

&lt;p&gt;Now that we understand the machine learning process a bit better, let's see how it relates to cooking.&lt;/p&gt;

&lt;h1&gt;
  
  
  Relating the Machine Learning Process to Cooking
&lt;/h1&gt;

&lt;p&gt;At first glance, you may not see how the machine learning process relates to cooking at all. But let's go into more detail of the machine learning process and how each step relates to cooking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Business Understanding
&lt;/h2&gt;

&lt;p&gt;One of the first things to do for the machine learning process is to get a business understanding of the problem.&lt;/p&gt;

&lt;p&gt;For cooking, we know we want to make a dish, but which one? What do we want to accomplish with our dish? Is it for breakfast, lunch, or dinner? Is it for just yourself or do we want to create something for a family of four? Or for a large gathering?&lt;/p&gt;

&lt;p&gt;Knowing these will help us determine what we want to cook.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Data
&lt;/h2&gt;

&lt;p&gt;We would need a way to get our data. We may already have the data in a data warehouse or we would need to generate it.&lt;/p&gt;

&lt;p&gt;For cooking, getting data can be related to getting your ingredients. You may already have the ingredients that you need or you would need to go to the grocery store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Good Data
&lt;/h3&gt;

&lt;p&gt;Earlier I mentioned that in order to have the best performing machine learning model we need to give it good data. The same can be said for making the best tasting dish. We would need to give it the best ingredients we can find.&lt;/p&gt;

&lt;p&gt;You wouldn't want to give your model bad data just like you wouldn't want to use spoiled or rotten ingredients when making your dish.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Processing
&lt;/h2&gt;

&lt;p&gt;Data processing is perhaps the most important step after getting good data. Depending on how you process the data will depend on how well your model performs.&lt;/p&gt;

&lt;p&gt;For cooking, this is equivalent to preparing your ingredients. This includes chopping any ingredients such as vegetables, but keeping a consistent size when chopping also counts. This helps the pieces cook evenly. If some pieces are smaller they can burn or if some pieces are bigger then they may not be fully cooked.&lt;/p&gt;

&lt;p&gt;Also, just like in machine learning there are multiple ways to process your data, there are also different ways to prepare ingredients. In fact, there's a word for processing all of your ingredients before you start cooking - &lt;a href="https://en.wikipedia.org/wiki/Mise_en_place"&gt;mise en place&lt;/a&gt; - which is French for "everything in it's place". This is done in cooking shows all the time where they have everything ready to start cooking.&lt;/p&gt;

&lt;p&gt;This actually also makes sense for machine learning. We have to have all of our data processing done on the training data before we can give it to the machine learning algorithm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modeling
&lt;/h2&gt;

&lt;p&gt;Now it's time for the actual modeling part of the process where we give our data to an algorithm.&lt;/p&gt;

&lt;p&gt;In cooking, this is actually where we cook our dish. In fact, we can relate choosing a recipe to choosing a machine learning algorithm. The recipe will take the ingredients and turn out a dish, and the algorithm will take the data and turn out a model.&lt;/p&gt;

&lt;p&gt;Different recipes will turn out different dishes, though. Take a salad, for instance. Depending on the recipe and the ingredients, the salad can turn out to be bright and citrusy like this &lt;a href="https://www.foodnetwork.com/recipes/ree-drummond/kale-citrus-salad-2593844"&gt;kale citrus salad&lt;/a&gt;. Or, it can be warm and savory like this &lt;a href="https://www.foodnetwork.com/recipes/alton-brown/spinach-salad-with-warm-bacon-dressing-recipe-1947599"&gt;spinach salad with bacon dressing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;They're both salads, but they are turned into different kinds of salads because of different ingredients and recipes. In machine learning, you can have similar models from different data and algorithms.&lt;/p&gt;

&lt;p&gt;What if you have the same ingredients? There are definitely different ways to make the same recipe. Hummus is traditionally made with chickpeas, tahini, garlic, and lemon like in &lt;a href="https://www.foodnetwork.com/recipes/katie-lee/classic-hummus-2333947"&gt;this recipe&lt;/a&gt;. But there is also &lt;a href="https://www.foodnetwork.com/recipes/alton-brown/hummus-for-real-recipe-2014722"&gt;this hummus recipe&lt;/a&gt; that has the same ingredients but the recipe is just a bit different.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimizing the Model
&lt;/h2&gt;

&lt;p&gt;Depending on the algorithm the machine learning model is using we can give it different parameters that can optimize the model for better performance. These parameter are called &lt;a href="https://en.wikipedia.org/wiki/Hyperparameter_(machine_learning)"&gt;hyperparameters&lt;/a&gt;, which is used during the learning process of the model to your data.&lt;/p&gt;

&lt;p&gt;These can be updated manually by you choosing values for the hyperparameters. This can be quite tedious and you never know what value to choose. So, instead, there are ways this can be automated by giving a range of values and running the model multiple times with different values and you can use the best performing model that is found.&lt;/p&gt;

&lt;p&gt;How do we optimize a dish, though? Perhaps the best way to get the best taste out of your dish, other than using the best ingredients, is to season it. Specifically, seasoning with salt. In &lt;a href="https://www.youtube.com/watch?v=ITI3J5UWiyQ"&gt;this video&lt;/a&gt; by &lt;a href="https://www.ethanchlebowski.com/"&gt;Ethan Chlebowski&lt;/a&gt;, he suggests&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;…home cooks severely under salt the food they are cooking and is often why the food doesn't taste good.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;He even quotes this line from the book &lt;a href="https://amzn.to/2Rslw54"&gt;Ruhlman's Twenty&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How to salt food is the most important skill to know in the kitchen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I've even experienced this in my own cooking where I don't add enough salt. Once I do, the dish tastes 100 times better.&lt;/p&gt;

&lt;p&gt;Now, adding salt to your dish is the more manual way of optimizing it with seasoning. Is there a way that this can be automated? Actually, there is! Instead of using just salt and adding other spices to it yourself you can get these seasoning blends that has all the spices in it for you!&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluating the Model
&lt;/h2&gt;

&lt;p&gt;Evaluating the model is going to be one of the most important steps because this tells you how well your model will perform on new data, or rather, data that it hasn't seen before. During training your model have good performance, but giving it new data may reveal that it actually is performing bad.&lt;/p&gt;

&lt;p&gt;Evaluating your cooked dish is a lot more fun, though. This is where you get to eat it! You will determine if it's a good dish by how it tastes. Is it good or bad? If you served it to others, what did they think about it?&lt;/p&gt;

&lt;h2&gt;
  
  
  Iterating on the Model
&lt;/h2&gt;

&lt;p&gt;Iterating on the model is a part of the process that may not seem necessary, but it can be an important one. Your data may change over time which would then make your model stale. That is, it's relying on data that it used to but due to some process change or something similar it no longer does. And since the underlying data changed the model won't predict as well as it did.&lt;/p&gt;

&lt;p&gt;Similarly, you may have more or even better data that you can use for training, so you can then retrain the model with that to make better predictions.&lt;/p&gt;

&lt;p&gt;How can you iterate on a dish that you just prepared? First thing is if it was good or bad. If it was bad, then we can revisit the recipe and see if we did anything wrong. Did we overcook it? Did we miss an ingredient? Did we prepare an ingredient incorrectly?&lt;/p&gt;

&lt;p&gt;If it was good, we can still iterate on it. Any ingredients you would like to add or remove to make it more to your liking?&lt;/p&gt;

&lt;p&gt;A lot of chefs and home cooks like to take notes about recipes they've made. They write in some tricks they've learned along the way but also some different paths from the recipe that they either had to take due to a missing ingredient or preferred to take.&lt;/p&gt;

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

&lt;p&gt;Hopefully, this helps your better understand the machine learning process through the eyes of cooking a dish. It may even help you understand the importance of each step because, in cooking, if one step is missed then you probably won't be having a good dinner tonight.&lt;/p&gt;

&lt;p&gt;And if you're wondering where does AutoML fit into all of this, then you can think of it as the meal delivery kits like Hello Fresh or Blue Apron. They do a lot of the work for you and you just have to put it all together.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Participate in the 2020 Virtual ML.NET Hackathon</title>
      <dc:creator>Jon Wood</dc:creator>
      <pubDate>Fri, 30 Oct 2020 09:46:03 +0000</pubDate>
      <link>https://dev.to/jwood803/participate-in-the-2020-virtual-ml-net-hackathon-1kih</link>
      <guid>https://dev.to/jwood803/participate-in-the-2020-virtual-ml-net-hackathon-1kih</guid>
      <description>&lt;p&gt;If you wanted to learn machine learning then join in on the &lt;a href="https://github.com/virtualmlnet/hackathon-2020"&gt;Virtual ML.NET Hackathon&lt;/a&gt;! Here you can create or join a project to have fun, learn ML.NET and machine learning, and help contribute to open source.&lt;/p&gt;

&lt;p&gt;For anyone not familiar with ML.NET there will be a workshop presented on November 13th to go over the basics of ML.NET.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hmvMRkx04Qs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Schedule
&lt;/h2&gt;

&lt;p&gt;The workshop will be on November 13th and will start at 10AM Pacific or 1PM Eastern. &lt;/p&gt;

&lt;p&gt;The week to officialy start hacking on your ML.NET code is from November 13th to November 20th.&lt;/p&gt;

&lt;p&gt;Submissions of your projects or contributions will be on November 18th. And the winners of the hackathon will be announced on the 20th.&lt;/p&gt;

&lt;p&gt;Sign ups have already started and feel free to reference the official &lt;a href="https://github.com/virtualmlnet/hackathon-2020#schedule"&gt;schedule&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Sign Up
&lt;/h2&gt;

&lt;p&gt;To sign up for the workshop and/or the hackathon, fill out &lt;a href="https://aka.ms/mlnet-hack-signup"&gt;this form&lt;/a&gt;. The first 50 to sign up will get a free tshirt!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating or Joining a Project
&lt;/h2&gt;

&lt;p&gt;To create a project simply create an issue in the &lt;a href="https://github.com/virtualmlnet/hackathon-2020/issues/new?assignees=&amp;amp;labels=&amp;amp;template=idea.md&amp;amp;title=ML.NET+Hackathon+Idea"&gt;GitHub repository&lt;/a&gt;. When signing up feel free to describe the project or contribution you want to submit. You have the option to specify if you want others to join your project as part of a team as well to specify if you would like a mentor to help you with your project.&lt;/p&gt;

&lt;p&gt;If you see a project that's already listed as an issue and it specifies they would like others to join their team, simply comment on the issue indicating you would like to join.&lt;/p&gt;

&lt;p&gt;Note that, for your project, if you are using a dataset, to make sure that it doesn't have any personal information in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Submissions
&lt;/h2&gt;

&lt;p&gt;Final submissions are due November 18th. To submit, create a pull request in the repo in the &lt;code&gt;Submissions&lt;/code&gt; folder. Submissions must include a README file indicating what was done for a solution to the project or what was contributed, any source code used for the project, and a 1 to 3 minute video showing or talking about your project or contribution.&lt;/p&gt;

&lt;p&gt;Submissions do not have to be fully complete or to run to be counted.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>machinelearning</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
