<?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>A journey into the wondrous land of Machine Learning Archives - OVHcloud Blog</title>
	<atom:link href="https://blog.ovhcloud.com/tag/a-journey-into-the-wondrous-land-of-machine-learning/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.ovhcloud.com/tag/a-journey-into-the-wondrous-land-of-machine-learning/</link>
	<description>Innovation for Freedom</description>
	<lastBuildDate>Fri, 03 Mar 2023 16:41:31 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.ovhcloud.com/wp-content/uploads/2019/07/cropped-cropped-nouveau-logo-ovh-rebranding-32x32.gif</url>
	<title>A journey into the wondrous land of Machine Learning Archives - OVHcloud Blog</title>
	<link>https://blog.ovhcloud.com/tag/a-journey-into-the-wondrous-land-of-machine-learning/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>A journey into the wondrous land of Machine Learning, or “Cleaning data is funnier than cleaning my flat!” (Part 3)</title>
		<link>https://blog.ovhcloud.com/a-journey-into-the-wondrous-land-of-machine-learning-or-cleaning-data-is-funnier-than-cleaning-my-flat-part-3/</link>
		
		<dc:creator><![CDATA[Guillaume Ruty]]></dc:creator>
		<pubDate>Tue, 12 Apr 2022 08:13:52 +0000</pubDate>
				<category><![CDATA[OVHcloud Engineering]]></category>
		<category><![CDATA[A journey into the wondrous land of Machine Learning]]></category>
		<category><![CDATA[Machine learning]]></category>
		<guid isPermaLink="false">https://blog.ovhcloud.com/?p=21754</guid>

					<description><![CDATA[What am I doing here? The story so far&#8230; As you might know if you have read our blog for more than a year, a few years ago, I bought a flat in Paris. If you don&#8217;t know, the real estate market in Paris is expensive but despite that, it is so tight that a [&#8230;]<img src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-into-the-wondrous-land-of-machine-learning-or-cleaning-data-is-funnier-than-cleaning-my-flat-part-3%2F&amp;action_name=A%20journey%20into%20the%20wondrous%20land%20of%20Machine%20Learning%2C%20or%20%E2%80%9CCleaning%20data%20is%20funnier%20than%20cleaning%20my%20flat%21%E2%80%9D%20%28Part%203%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">What am I doing here?</h3>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img fetchpriority="high" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/03/IMG_0896-1024x537.jpeg" alt="A journey into the wondrous land of Machine Learning, or “Cleaning data is funnier than cleaning my flat!” (Part 3)" class="wp-image-22797" width="512" height="269" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/03/IMG_0896-1024x537.jpeg 1024w, https://blog.ovhcloud.com/wp-content/uploads/2022/03/IMG_0896-300x157.jpeg 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/03/IMG_0896-768x403.jpeg 768w, https://blog.ovhcloud.com/wp-content/uploads/2022/03/IMG_0896.jpeg 1200w" sizes="(max-width: 512px) 100vw, 512px" /></figure></div>



<h4 class="wp-block-heading">The story so far&#8230;</h4>



<p>As you might know if you have read our blog for more than a year, a few years ago, I bought a flat in Paris. If you don&#8217;t know, the real estate market in Paris is expensive but despite that, it is so tight that a good flat at a correct price can be for sale for less than a day.</p>



<p>Obviously, you have to take a decision quite fast, and considering the prices, you have to trust your decision. Of course, to trust your decision, you have to take your time, study the market, make some visits etc… This process can be quite long (in my case it took a year between the time I decided that I wanted to buy a flat and the time I actually commited to buying my current flat), and even spending a lot of time will never allow you to have a perfect understanding of the market. What if there was a way to do that very quickly and with a better accuracy than with the standard process?</p>



<div class="wp-block-image"><figure class="alignright size-large is-resized"><a href="https://blog.ovhcloud.com/a-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1/" data-wpel-link="internal"><img decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-1024x537.png" alt="A journey into the wondrous land of Machine Learning, or “Did I get ripped off?” (Part 1)" class="wp-image-17908" width="400" height="210" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-1024x537.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-300x157.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-768x403.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20.png 1200w" sizes="(max-width: 400px) 100vw, 400px" /></a></figure></div>



<p>As you might also know if you are one of our regular readers, I tried to solve this problem with Machine Learning, using an end-to-end software called Dataiku. In a <a href="https://blog.ovhcloud.com/a-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">first blog post</a>, we learned how to make a basic use of Dataiku, and discovered that just knowing how to click on a few buttons wasn&#8217;t quite enough: you had to bring some sense in your data and in the training algorithm, or you would find absurd results.</p>



<div class="wp-block-image"><figure class="alignright size-large is-resized"><a href="https://blog.ovhcloud.com/a-journey-through-the-wondrous-land-of-machine-learning-or-can-i-really-buy-a-palace-in-paris-for-100000e-part-2/" data-wpel-link="internal"><img decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-1024x537.png" alt="A journey through the wondrous land of Machine Learning or &quot;Can I really buy a palace in Paris for 100,000€?&quot; (Part 2)" class="wp-image-19147" width="400" height="211" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-1024x537.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-300x157.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-768x403.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F.png 1200w" sizes="(max-width: 400px) 100vw, 400px" /></a></figure></div>



<p>In a <a href="https://blog.ovhcloud.com/a-journey-through-the-wondrous-land-of-machine-learning-or-can-i-really-buy-a-palace-in-paris-for-100000e-part-2/" target="_blank" rel="noreferrer noopener" data-wpel-link="internal">second entry</a>, we studied a bit more the data, tweaked a few parameters and values in Dataiku&#8217;s algorithms and trained a new model. This yielded a much better result, and this new model was &#8211; if not accurate &#8211; at least relevant: the same flat had a higher predicted place when it was bigger or supposedly in a better neighbourhood. However, it was far from perfect and really lacked accuracy for several reasons, some of them out of our control.</p>



<p>However, all of this was done on one instance of Dataiku &#8211; a licensed software &#8211; on a single VM. There are multiple reasons that could push me to do things differently:</p>



<ul class="wp-block-list"><li>Maybe you want to only use open-source frameworks to make sure you have full control over exactly what runs and how it works</li><li>Maybe you don&#8217;t want to pay a license to make an extensive use of the software</li><li>Maybe you have a vast amount of data to process and transform and even a big VM is not enough</li><li>Maybe you want to only use &#8220;universal&#8221; tools and languages to make sure you will always find people with the appropriate skills so that your pipelines are maintaineable</li></ul>



<h4 class="wp-block-heading">But seriously, what am I doing?</h4>



<p>What we did very intuitively (and somewhat naively) with Dataiku was actually a quite complex pipeline that is often called <em>ELT</em>, for <em>Extract, Load and Transform</em>.</p>



<ul class="wp-block-list"><li>We <em>extracted</em> the data when we downloaded it from the French open data website</li><li>We <em>loaded</em> it when we uploaded it to our Dataiku Instance</li><li>We <em>transformed</em> it when we used Dataiku&#8217;s data processing capabilities to make it digestible for a machine learning algorithm</li></ul>



<p>And obviously, after this <em>ELT</em> process, we added a step to train a model on the transformed data.</p>



<p>So what are we going to do to redo all of that without Dataiku&#8217;s help?</p>



<ul class="wp-block-list"><li>For the <em>extract</em> phase, we are actually going to cheat a little bit and do things the exact same way: we will download the data directly from the website on a public cloud VM. Obviously this is not very scalable, but the <em>extract</em> phase is the most dependant on the source format: in that case, it&#8217;s csv files from a webserver.</li><li>For the <em>load</em> phase, we are going to push these csv files to an object store &#8211; in that case <a href="https://www.ovhcloud.com/en/public-cloud/object-storage/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external">OVHcloud PCS</a> (Public Cloud Storage) &#8211; using the standard S3 CLI. An object store is ideal to store this kind of data because:<ul><li>It is infinitely scalable so no matter how much data I push, I won&#8217;t have to handle storage provisioning etc…</li><li>It works best with large objects (&gt; 1MB. In our case, the csv files are around ~500MB)</li><li>It works with standard APIs that most cloud providers provide and that you can also deploy on-premise if you wish</li></ul></li><li>For the <em>transform</em> phase, we are going to use the most well-known distributed processing framework: Apache Spark. Spark is a framework that transparently distribute the operations on data on several worker nodes. Thus, it allows you to manipulate much bigger datasets than what you could do on a single VM. However, setting up a Spark cluster to launch Spark jobs is not an easy task. Therefore, we are going to use OVHcloud <a href="https://www.ovhcloud.com/en-gb/public-cloud/data-processing/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external">data processing</a>. With data processing, we can just upload our code in an object storage bucket and launch a job in a few clicks/a CLI call, not handling any infrastructure in the process. This job will read raw data from a S3 bucket and write the processed data in another S3 bucket.</li><li>After ELT has been done, we still need to <em>train</em> the model! An interactive and user-friendly way to develop the code to train machine learning models is through the use of <em>Jupyter notebooks</em>. A jupyter notebook is a web-based UI allowing you to write and execute python code in blocks in an interactive way, allowing you to explore data and try different things in a seamless fashion. As it turns out, OVHcloud has a product called <a href="https://www.ovhcloud.com/en-gb/public-cloud/ai-notebook/" data-wpel-link="external" target="_blank" rel="nofollow external noopener noreferrer">OVHcloud AI notebook</a> that allows you to spin up a notebook on multiple GPUs in just a few clicks or a CLI call. Even better, you can attach S3 buckets to your notebook, transparently pushing the data contained in the bucket to high-speed storage near the notebooks to make sure you make full use of your GPUs. As you might have guessed already, we will use this product to spin up a notebook, work on the clean data, train a model and evaluate its results.</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/04/1-4-phases-1024x576.png" alt="" class="wp-image-22888" width="768" height="432" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/04/1-4-phases-1024x576.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2022/04/1-4-phases-300x169.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/04/1-4-phases-768x432.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2022/04/1-4-phases.png 1280w" sizes="auto, (max-width: 768px) 100vw, 768px" /><figcaption><em>When ELT becomes ELTT</em></figcaption></figure></div>



<p>Now that we know what we are going to do, let us proceed!</p>



<h3 class="wp-block-heading">Preparing your setup</h3>



<p>Before beginning, we have to properly set up our environment to be able to launch the different tools and products. Throughout this tutorial, we will show you how to do everything with CLIs. However, all these manipulations can also be done on OVHcloud&#8217;s manager (GUI), in which case you won&#8217;t have to configure these tools.</p>



<h4 class="wp-block-heading">Setting up your environment</h4>



<p>For all the manipulations described in the next phase of this article, we will use a Virtual Machine deployed in OVHcloud&#8217;s Public Cloud that will serve as the extraction agent to download the raw data from the web and push it to S3 as well as a CLI machine to launch data processing and notebook jobs. It is a <code>d2-4</code> flavor with 4GB of RAM, 2 vCores and 50 GB of local storage running Debian 10, deployed in Graveline&#8217;s datacenter. During this tutorial, I run a few UNIX commands but you should easily be able to adapt them to whatever OS you use if needed. All the CLI tools specific to OVHcloud&#8217;s products are available on multiple OSs.</p>



<p>You will also need an OVHcloud NIC (user account) as well as a Public Cloud Project created for this account with a quota high enough to deploy a GPU (if that is not the case, you will be able to deploy a notebook on CPU rather than GPU, the training phase will juste take more time). To create a Public Cloud project, you can follow <a href="https://docs.ovh.com/gb/en/public-cloud/create_a_public_cloud_project/" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">these steps</a>.</p>



<h4 class="wp-block-heading">Installing and configuring your tools</h4>



<p>Here is a list of the CLI tools and other that we will use during this tutorial and why:</p>



<ul class="wp-block-list"><li><code>wget</code> to retrieve the data from a public data website.</li><li><code>gunzip</code> to unzip it.</li><li><code>aws</code> CLI, that we will use to interact with OVHcloud&#8217;s Public Cloud Storage, a product allowing you to manipulate object storage buckets either through the Swift or the S3 API. Alternatively, you could use the <code>Swift</code> CLI. You will find how to configure your <code>aws</code> CLI <a href="https://docs.ovh.com/gb/en/public-cloud/getting_started_with_the_swift_S3_API/" data-wpel-link="exclude">h</a><a href="https://docs.ovh.com/gb/en/public-cloud/getting_started_with_the_swift_S3_API/" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">e</a><a href="https://docs.ovh.com/gb/en/public-cloud/getting_started_with_the_swift_S3_API/" data-wpel-link="exclude">re</a>.</li><li><code>ovh-spark-submit</code> CLI to launch OVHcloud data processing (Spark-as-a-Service) jobs. You will find the instructions to install and configure the CLI <a href="https://docs.ovh.com/gb/en/data-processing/submit-cli/" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">here</a>.</li><li><code>ovhai</code> CLI to launch OVHcloud AI notebook or AI training jobs. You will find out how to install and configure this CLI <a href="https://docs.ovh.com/gb/en/ai-training/install-client/" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">here</a>.</li></ul>



<p>Additionally you will find commented code samples for the processing and training steps in <a href="https://github.com/Le-Gruty/real-estate-open-data" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external">this Github repository</a>.</p>



<h4 class="wp-block-heading">Creating your object storage buckets</h4>



<p>In this tutorial, we will use several object storage buckets. Since we will use the S3 API, we will call them S3 bucket, but as mentioned above, if you use OVHcloud standard Public Cloud Storage, you could also use the Swift API. However, you are restricted to only the S3 API if you use our new <a href="https://labs.ovh.com/high-perf-object-storage" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">high-performance object storage</a> offer, currently in Beta.</p>



<p>For this tutorial, we are going to create and use the following S3 buckets:</p>



<ul class="wp-block-list"><li><code>transactions-ecoex-raw</code> to store the raw data before it is processed</li><li><code>transactions-ecoex-processing</code> to store the Spark code and environment files used to process the raw data</li><li><code>transactions-ecoex-clean</code>to store the data once it has been cleaned</li><li><code>transactions-ecoex-model</code>to store the weights of the trained model once it has been trained</li></ul>



<p>To create these buckets, use the following commands after having configured your aws CLI as explained above:</p>



<pre class="wp-block-code"><code class="">aws s3 mb s3://transactions-ecoex-raw
aws s3 mb s3://transactions-ecoex-processing
aws s3 mb s3://transactions-ecoex-clean
aws s3 mb s3://transactions-ecoex-model</code></pre>



<p>Now that you have your environment set up and your S3 buckets ready, we can begin the tutorial!</p>



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



<h4 class="wp-block-heading">Extracting/Ingesting the Data</h4>



<p>First, let us download the data files directly on Etalab&#8217;s website and unzip them:</p>



<pre class="wp-block-code"><code class="">wget -r -l2 -P data -np "https://files.data.gouv.fr/geo-dvf/latest/csv/" -A "*full.csv.gz" --reject-regex="/communes/|/departements/"
cd data
for FILE in `find files.data.gouv.fr -name "*.csv.gz"`
do
      NEWFILE=`echo $FILE | tr '/' '-'`
      mv $FILE $NEWFILE
done
rm -rf files.data.gouv.fr/*
rm -r files.data.gouv.fr
gunzip *.csv.gz</code></pre>



<p>You should now have the following files in your directory, each one corresponding to the French real estate transaction of a specific year:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~/data$ ls
files.data.gouv.fr-geo-dvf-latest-csv-2016-full.csv  
files.data.gouv.fr-geo-dvf-latest-csv-2019-full.csv
files.data.gouv.fr-geo-dvf-latest-csv-2017-full.csv  
files.data.gouv.fr-geo-dvf-latest-csv-2020-full.csv
files.data.gouv.fr-geo-dvf-latest-csv-2018-full.csv</code></pre>



<p>Now, use the S3 CLI to push these files in the relevant S3 bucket:</p>



<pre class="wp-block-code"><code class="">find * -type f -name "*.csv" -exec aws s3 cp {} s3://transactions-ecoex-raw/{} \;</code></pre>



<p>You should now have those 5 files in your S3 bucket:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~/data$ aws s3 ls transactions-ecoex-raw
2021-09-21 17:43:32  511804467 files.data.gouv.fr-geo-dvf-latest-csv-2016-full.csv
2021-09-21 17:43:54  590281357 files.data.gouv.fr-geo-dvf-latest-csv-2017-full.csv
2021-09-21 17:44:14  580600597 files.data.gouv.fr-geo-dvf-latest-csv-2018-full.csv
2021-09-21 17:44:36  614788794 files.data.gouv.fr-geo-dvf-latest-csv-2019-full.csv
2021-09-21 17:44:52  426715300 files.data.gouv.fr-geo-dvf-latest-csv-2020-full.csv</code></pre>



<p>What we just did with a small VM was <strong><em>ingesting</em></strong> data into a S3 bucket. In real-life usecases with more data, we would probably use dedicated tools to ingest the data. However, in our example with just a few GB of data coming from a public website, this does the trick.</p>



<h4 class="wp-block-heading">Processing the data</h4>



<p>Now that you have your raw data in place to be processed, you just have to upload the code necessary to run your data processing job. Our data processing product allows you to run Spark code written either in Java, Scala or Python. In our case, we used Pyspark on Python. Your code should consist in 3 files:</p>



<ul class="wp-block-list"><li>A .py file containing your code. In my case, this file is <code>real_estate_processing.py</code></li><li>A <code>environment.yml</code> file containing your dependencies.</li><li>If &#8211; like me &#8211; you don&#8217;t wish to put your S3 credentials in your .py file, a separate <code>.env</code> file containing them. You will need to use a library like <code>python-dotenv</code> and source it in the <code>environment.yml</code> file to handle that.</li></ul>



<p>Once you have your code files, go to the folder containing them and push them on the appropriate S3 bucket:</p>



<pre class="wp-block-code"><code class="">cd ~/EcoEx_Tech_Masterclass/Processing/
aws s3 cp real_estate_processing.py s3://transactions-ecoex-processing/processing.py
aws s3 cp environment.yml s3://transactions-ecoex-processing/environment.yml
aws s3 cp .env s3://transactions-ecoex-processing/.env</code></pre>



<p>Your bucket should now look like that:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~/EcoEx_Tech_Masterclass/Processing$ aws s3 ls transactions-ecoex-processing
2021-10-04 10:14:52         94 .env
2021-10-04 10:14:09         99 environment.yml
2021-10-04 10:20:08       4425 processing.py</code></pre>



<p>You are now ready to launch your data processing job. The following command will allow you to launch this job on 10 executors, each with 4 vCores and 15 GB of RAM.</p>



<pre class="wp-block-code"><code class="">ovh-spark-submit \
    --projectid $OS_PROJECT_ID \
    --jobname transactions-ecoex-processing \
    --class org.apache.spark.examples.SparkPi \
    --driver-cores 4 \
    --driver-memory 15G \
    --executor-cores 4 \
    --executor-memory 15G \
    --num-executors 10 \
    swift://transactions-ecoex-processing/processing.py 1000</code></pre>



<p>Note that the data processing product uses the Swift API to retrieve the code files. This is totally transparent to the user, and the fact that we used the S3 CLI to create the bucket has absolutely no impact. When the job is over, you should see the following in your <code>transactions-ecoex-clean</code> bucket:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~$ aws s3 ls transactions-ecoex-clean
                             PRE data_clean.parquet/
debian@d2-4-gra5:~$ aws s3 ls transactions-ecoex-clean/data_clean.parquet/
2021-10-04 16:35:48          0 _SUCCESS
2021-10-04 16:27:13      50769 part-00000-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
2021-10-04 16:27:16      52253 part-00001-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
2021-10-04 16:27:18      51412 part-00002-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
2021-10-04 16:27:21      46962 part-00003-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
2021-10-04 16:27:23      49130 part-00004-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
2021-10-04 16:27:26      50046 part-00005-ac3acfc2-c5b3-430e-91b4-7f5e50b537a6-c000.snappy.parquet
.......</code></pre>



<p>Before going further, let us look at the size of the data before and after cleaning:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~$ aws s3 ls s3://transactions-ecoex-raw --human-readable --summarize
2021-10-18 18:59:21  488.1 MiB full.csv.2016
2021-10-18 18:59:21  562.9 MiB full.csv.2017
2021-10-18 18:59:21  553.7 MiB full.csv.2018
2021-10-18 18:59:21  586.3 MiB full.csv.2019
2021-10-18 18:59:21  406.9 MiB full.csv.2020

Total Objects: 5
   Total Size: 2.5 GiB

debian@d2-4-gra5:~$ aws s3 ls s3://transactions-ecoex-clean --recursive --human-readable --summarize
2021-10-19 09:20:23    0 Bytes data_clean.parquet/_SUCCESS
2021-10-19 09:19:09   49.5 KiB data_clean.parquet/part-00000-48156d39-f3fb-495b-b829-edee3777701f-c000.snappy.parquet
2021-10-19 09:19:10   51.1 KiB data_clean.parquet/part-00001-48156d39-f3fb-495b-b829-edee3777701f-c000.snappy.parquet
2021-10-19 09:19:09   50.3 KiB data_clean.parquet/part-00002-48156d39-f3fb-495b-b829-edee3777701f-c000.snappy.parquet
...
...
2021-10-19 09:20:11   49.1 KiB data_clean.parquet/part-00199-48156d39-f3fb-495b-b829-edee3777701f-c000.snappy.parquet

Total Objects: 197
   Total Size: 9.4 MiB</code></pre>



<p>As you can see, with ~2.5 GB of raw data, we extracted only ~10 MB of actually useful data (only 0,4%)!! What is noteworthy here is that that you can easily imagine usecases where you need a large-scale infrastructure to ingest and process the raw data but where one or a few VMs are enough to work on the clean data. Obviously, this is more often the case when working with text/structured data than with raw sound/image/videos. </p>



<p>Before we start training a model, take a look at these two screenshots from OVHcloud&#8217;s data processing UI to erase any doubt you have about the power of distributed computing:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="421" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_slow-1024x421.png" alt="" class="wp-image-21769" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_slow-1024x421.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_slow-300x123.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_slow-768x316.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_slow.png 1505w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="399" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_fast-1024x399.png" alt="" class="wp-image-21771" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_fast-1024x399.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_fast-300x117.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_fast-768x299.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/job_fast.png 1494w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>In the first picture, you see the time taken for this job when launching only 1 executor- 8:35 minutes. This duration is reduced to only 2:56 minutes when launching the same job (same code etc…) on 4 executors: almost 3 times faster. And since you pay-as-you go, this will only cost you ~33% more in that case for the same operation done 3 times faster- without any modification to your code, only one argument in the CLI call. Let us now use this data to train a model.</p>



<h4 class="wp-block-heading">Training the model</h4>



<p>To train the model, you are going to use OVHcloud AI notebook to deploy a … notebook! With the following command, you will:</p>



<ul class="wp-block-list"><li>Deploy a notebook running a Jupyterlab, …</li><li>… pre-configured to run on a VM with 1 GPU, …</li><li>… with several important libraries such as Tensorflow or Pytorch installed, …</li><li>… with your S3 bucket <code>transactions-ecoex-clean</code> synchronized on a high-performance storage cluster that is mounted on <code>/workspace/data</code>in your notebook, …</li><li>… and ready to write the model when it has been trained on the <code>/workspace/model</code> path that will be synchronized with your <code>transactions-ecoex-model</code> when the job is over.</li></ul>



<pre class="wp-block-code"><code class="">ovhai notebook run one-for-all jupyterlab \
    --name transactions-ecoex-training \
    --framework-version v98-ovh.beta.1 \
    --flavor ai1-1-gpu \
    --gpu 1 \
    --volume transactions-ecoex-clean@GRA/:/workspace/data:RO \
    --volume transactions-ecoex-model@GRA/:/workspace/model:RW</code></pre>



<p>In our case, we launch a notebook with only 1 GPU because the code samples we provide would not leverage several GPUs for a single job. I could adapt my code to parallelize the training phase on multiple GPUs, in which case I could launch a job with up to 4 parallel GPUs.Once this is done, just get the URL of your notebook with the following command and connect to it with your browser:</p>



<p>Once you&#8217;re done, just get the URL of your notebook with the following command and connect to it with your browser:</p>



<pre class="wp-block-code"><code class="">debian@d2-4-gra5:~$ ovhai notebook list
ID                                   STATE   AGE FRAMEWORK   VERSION          EDITOR     URL
525bcb3e-d57b-4111-91ff-4a8759061f75 RUNNING 20m one-for-all v98-ovh.beta.1   jupyterlab https://XXXXXXXXXX.notebook.gra.training.ai.cloud.ovh.net</code></pre>



<p>You can now import the <code>real-estate-training.ipynb</code> file to the notebook with just a few clicks. If you don&#8217;t want to import it from the computer you use to access the notebook (for example if like me you use a VM to work and have cloned the git repo on this VM and not on your computer), you can push the <code>.ipynb</code> file to your <code>transactions-ecoex-clean</code> or <code>transactions-ecoex-model</code> bucket and re-synchronize the bucket to your notebook while it runs by using the <code>ovhai notebook pull-data</code> command. You will then find the notebook file in the corresponding directory.</p>



<p>Once you have imported the notebook file to your notebook instance, just open it and follow the directives. If you are interested in the result but don&#8217;t want to do it yourself, let&#8217;s sum up what the notebook does:</p>



<ul class="wp-block-list"><li>It reads the clean data from the folder where it has been synchronized from the S3 bucket and plots a few figures.</li><li>In these two plots, you can see that the most represented price range is between 400 and 500k€, and that the price per m<sup>2</sup> is approximatively a gaussian curve centered on ~10k€. If you know Paris&#8217; real estate market, this shouldn&#8217;t surprise you.</li></ul>



<div class="inherit-container-width wp-block-group is-layout-constrained wp-block-group-is-layout-constrained"><div class="wp-block-group__inner-container">
<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="437" height="464" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/1-distrib_valeur-1.png" alt="" class="wp-image-21757" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/1-distrib_valeur-1.png 437w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/1-distrib_valeur-1-283x300.png 283w" sizes="auto, (max-width: 437px) 100vw, 437px" /></figure>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/2-distrib_m2-1.png" alt="" class="wp-image-21758" width="439" height="466" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/2-distrib_m2-1.png 878w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/2-distrib_m2-1-283x300.png 283w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/2-distrib_m2-1-768x815.png 768w" sizes="auto, (max-width: 439px) 100vw, 439px" /></figure>
</div></div>



<ul class="wp-block-list"><li>The next two plots show you the geographical repartition of the prices &#8211; absolute and per m<sup>2</sup>. They tell us an interesting story: if you look at the absolute prices, you can see that the West of Paris looks more expensive than the East. However, the price per m<sup>2</sup> shows that for en equal surface, it is the center of Paris that is more expensive. That means that the center of Paris is relatively more expensive but has smaller flats to offer, so probably less families there!</li></ul>



<div class="inherit-container-width wp-block-group is-layout-constrained wp-block-group-is-layout-constrained"><div class="wp-block-group__inner-container">
<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/3-heatmap_valeur-1.png" alt="" class="wp-image-21761" width="564" height="403" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/3-heatmap_valeur-1.png 800w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/3-heatmap_valeur-1-300x215.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/3-heatmap_valeur-1-768x549.png 768w" sizes="auto, (max-width: 564px) 100vw, 564px" /></figure>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/4-heatmap_m2-1.png" alt="" class="wp-image-21762" width="577" height="411" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/4-heatmap_m2-1.png 806w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/4-heatmap_m2-1-300x214.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/4-heatmap_m2-1-768x547.png 768w" sizes="auto, (max-width: 577px) 100vw, 577px" /></figure>



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



<ul class="wp-block-list"><li>Finally, a last visualization plot shows you a correlation table of all numerical values contained in the data. Here are a few noteworthy facts:<ul><li>As expected, there is a very high correlation between the absolute price and the surface of a flat. This is common sense for whoever has tried to buy a flat in a city.</li><li>There is a positive correlation between the price per m<sup>2</sup> and the date of the transaction: again this is not a surprise as Paris&#8217; real estate steadily increases in value over the years.</li><li>There is however only a very slightly negative correlation between the surface of a flat and its price per m<sup>2</sup>. This means that the bigger a flat is, the lesser its surface is taken into account in the price. However, this negative correlation is very small so it doesn&#8217;t have that much effect.</li></ul></li></ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="748" height="697" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/5-correlation.png" alt="" class="wp-image-21763" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/5-correlation.png 748w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/5-correlation-300x280.png 300w" sizes="auto, (max-width: 748px) 100vw, 748px" /></figure>



<ul class="wp-block-list"><li>After that, the data is transformed a bit to be digestible for the neural network:<ul><li>It is divided in numerical data and categorical data (mainly the street and postal codes);</li><li>A statistical algorithm is applied to the numerical values to drop outliers that were not dropped in our processing phase by empiric methods;</li><li>The numerical values are normalized;</li><li>The categorical data is encoded in discreet numerical values;</li><li>Finally, the two datasets are merged again.</li></ul></li><li>Once this is done, we create a neural network and finally train a model on a subset of our data! After this first model has been trained, we test it on the remainder of the data. In the next plot, you can see a mapping between the prices predicted by this model and the actual prices. As you can see, our model fares quite poorly and severely undervalues flats most flats.</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/6-model1.png" alt="" class="wp-image-21764" width="811" height="791" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/6-model1.png 811w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/6-model1-300x293.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/6-model1-768x749.png 768w" sizes="auto, (max-width: 811px) 100vw, 811px" /><figcaption><em>Use the models built in this tutorial at your own risk&#8230;</em></figcaption></figure></div>



<ul class="wp-block-list"><li>After this disappointing result, we create a new neural network with more neurons per layer and train it again. The following plot shows its result on our testing set. While it remains quite unprecise and still slightly undervalues flats in average, the results are much better than with the previous model.</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="813" height="784" src="https://blog.ovhcloud.com/wp-content/uploads/2022/01/7-model2.png" alt="" class="wp-image-21765" srcset="https://blog.ovhcloud.com/wp-content/uploads/2022/01/7-model2.png 813w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/7-model2-300x289.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2022/01/7-model2-768x741.png 768w" sizes="auto, (max-width: 813px) 100vw, 813px" /></figure></div>



<ul class="wp-block-list"><li>Before stopping the notebook, we save both models to a local directory that will be synchronized to our <code>transactions-ecoex-model</code> S3 bucket.</li></ul>



<p>So, what can we conclude from all of this? First, even if the second model is obviously better than the first, it is still very noisy: while not far from correct on average, there is still a huge variance. Where does this variance come from?</p>



<p>Well, it is not easy to say. To paraphrase the finishing part of my last article:</p>



<ul class="wp-block-list"><li>We trained this model on only two combinations of basic parameters (the number of neurons per layer). If we were to do that seriously, we would have launched tens or hundreds of trainings in parallel with other parameters and selected the best. There are almost certainly some sets of parameters that would have converged towards a better model.</li><li>Even with the best set of parameters the data is not perfect. How can it differentiate between two flats at the exact same address and with the same surface, one on the ground floor in a narrow street and in front of a very noisy bar, the other on the last floor, higher than the neighbouring buildings, South-oriented towards a calm public garden with a direct view on the Eiffel Tower? The answer is no, as these informations are not contained in the data. And yet, this second flat would probably be more expensive than the first one. Even a very well-trained model would almost certainly overvalue the first one and undervalue the second one.</li></ul>



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



<p>In this article, I tried to give you a glimpse at the tools that Data Scientists commonly use to manipulate data and train models at scale, in the Cloud or on their own infrastructure:</p>



<ul class="wp-block-list"><li>Object storage to store the raw and/or clean data;</li><li>Spark or any other distributed processing framework to clean the data &#8211; obviously alternatives exist for specific usecase, for example labelling tools to label images when the goal is to train an object detection in images model;</li><li>Notebooks running Machine-Learning frameworks such as Tensorflow, PyTorch, Scikit-Learn etc… to prototype and code algorithms.</li></ul>



<p>Hopefuly, you now have a better understanding on how Machine Learning algorithms work, what their limitations are, and how Data Scientists work on data to create models.</p>



<p>As explained earlier, all the code used to obtain these results can be found <a href="https://github.com/Le-Gruty/real-estate-open-data" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external">here</a>. Please don&#8217;t hesitate to replicate what I did or adapt it to other usecases!</p>
<img loading="lazy" decoding="async" src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-into-the-wondrous-land-of-machine-learning-or-cleaning-data-is-funnier-than-cleaning-my-flat-part-3%2F&amp;action_name=A%20journey%20into%20the%20wondrous%20land%20of%20Machine%20Learning%2C%20or%20%E2%80%9CCleaning%20data%20is%20funnier%20than%20cleaning%20my%20flat%21%E2%80%9D%20%28Part%203%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A journey through the wondrous land of Machine Learning or &#8220;Can I really buy a palace in Paris for 100,000€?&#8221; (Part 2)</title>
		<link>https://blog.ovhcloud.com/a-journey-through-the-wondrous-land-of-machine-learning-or-can-i-really-buy-a-palace-in-paris-for-100000e-part-2/</link>
		
		<dc:creator><![CDATA[Guillaume Ruty]]></dc:creator>
		<pubDate>Thu, 03 Sep 2020 14:52:09 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[A journey into the wondrous land of Machine Learning]]></category>
		<category><![CDATA[Deep learning]]></category>
		<category><![CDATA[Machine learning]]></category>
		<guid isPermaLink="false">https://www.ovh.com/blog/?p=19078</guid>

					<description><![CDATA[Spoiler alert, no you can&#8217;t. A few months ago, I explained how to use Dataiku &#8211; a well-known interactive AI studio &#8211; and how to use data, made available by the French government, to build a Machine Learning model predicting the market value of real estate. Sadly, it failed miserably: when I tried it on [&#8230;]<img src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-through-the-wondrous-land-of-machine-learning-or-can-i-really-buy-a-palace-in-paris-for-100000e-part-2%2F&amp;action_name=A%20journey%20through%20the%20wondrous%20land%20of%20Machine%20Learning%20or%20%26%238220%3BCan%20I%20really%20buy%20a%20palace%20in%20Paris%20for%20100%2C000%E2%82%AC%3F%26%238221%3B%20%28Part%202%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></description>
										<content:encoded><![CDATA[
<p>Spoiler alert, no you can&#8217;t.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-1024x537.png" alt="A journey through the wondrous land of Machine Learning or &quot;Can I really buy a palace in Paris for 100,000€?&quot; (Part 2)" class="wp-image-19147" width="768" height="403" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-1024x537.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-300x157.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F-768x403.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/12B8273B-DCF4-4705-9E08-5FE05760102F.png 1200w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<p><a href="https://www.ovh.com/blog/a-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1/" target="_blank" rel="noreferrer noopener" data-wpel-link="exclude">A few months ago</a>, I explained how to use Dataiku &#8211; a well-known interactive AI studio &#8211; and how to use data, made available by the French government, to build a Machine Learning model predicting the market value of real estate. Sadly, it failed miserably: when I tried it on the transactions made in my street, the same year I bought my flat, the model predicted that all of them had the same market value. </p>



<p>In this blog post, I will point out several reasons why our experiment failed, and then I will try to train a new model, taking into account what we will have learned.</p>



<h3 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Whyourmodelfailed">Why our model failed</h3>



<p>There are several reasons why our model failed. Three of them stand out:</p>



<ul class="wp-block-list"><li>The open data format layout</li><li>The data variety</li><li>Dataiku&#8217;s default model parameters</li></ul>



<h4 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-OpenDataFormatLayout">Open Data Format Layout</h4>



<p>You can find a description of the data layout on the dedicated <a href="https://www.data.gouv.fr/fr/datasets/5cc1b94a634f4165e96436c1/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external">webpage</a>. I will not list all the columns of the schema (there are 40 of them), but the most important one is the first one: id_mutation. This information is a unique transaction number, and not an unusual column to find. </p>



<p>However, if you look at the dataset itself, you will see that some transactions are spread over multiple lines. They correspond to transactions regrouping multiple parcels. In the example of my own transaction, there are two lines: one for the flat itself, and one for a separate basement under the building. </p>



<p>The problem is that the full price is found on every such line. From the point of view of my AI studio, which only sees a set of lines it interprets as data points, it looks like my basement and my flats are two different properties that cost an equal amount! This gets worse for properties that have lands and several constructs attached to them. How can we expect our algorithm to learn appropriately under these conditions?</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/08/8AD89D9B-B3AE-4D6E-B92D-9601A091B47B-1024x766.png" alt="Open Data Format Layout" class="wp-image-19145" width="768" height="575" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/8AD89D9B-B3AE-4D6E-B92D-9601A091B47B-1024x766.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/8AD89D9B-B3AE-4D6E-B92D-9601A091B47B-300x225.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/8AD89D9B-B3AE-4D6E-B92D-9601A091B47B-768x575.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/8AD89D9B-B3AE-4D6E-B92D-9601A091B47B.png 1248w" sizes="auto, (max-width: 768px) 100vw, 768px" /><figcaption>Dataiku doesn&#8217;t naturally understand that a data point can consist of multiple lines!</figcaption></figure></div>



<h4 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-DataVariety">Data Variety</h4>



<p>In this case, we are trying to predict the price of a flat in Paris. However, the data we gave the algorithm regroups every real estate transaction made in France over the last few years. While you might think that more data is always better, this is not necessary the case. </p>



<p>The real estate market changes according to where you are, and Paris is a very specific case in France, with prices being much higher than in other big cities and the rest of France. Of course, this can be seen in the data, but the training algorithm does not know that in advance, and it is very hard for it to learn how to price a small flat in Paris and a farm with acres of land in Lozère at the same time.&nbsp;</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/08/D673B22D-30EB-43F8-BC7B-D8EE0D25EEED-1024x563.png" alt="Data variety" class="wp-image-19141" width="768" height="422" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/D673B22D-30EB-43F8-BC7B-D8EE0D25EEED-1024x563.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/D673B22D-30EB-43F8-BC7B-D8EE0D25EEED-300x165.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/D673B22D-30EB-43F8-BC7B-D8EE0D25EEED-768x422.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/D673B22D-30EB-43F8-BC7B-D8EE0D25EEED.png 1253w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure>



<h4 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Modeltrainingparameters">Model training parameters</h4>



<p>In the last blog post, you have seen how easy it is to use Dataiku. But it comes at a price: the default script can be used for very simple use-cases. But it is not suited for complex tasks &#8211; like predicting real-estate prices. I myself do not have much experience with Dataiku. However, by digging deeper into the details, I was able to correct a few obvious mistakes:</p>



<ul class="wp-block-list"><li>Data types: A lot of the columns in the dataset are specific types: integers, geographic coordinates, dates etc. Most of them are correctly identified by Dataiku, but some of them &#8211; such as geographic coordinates, or dates &#8211; are not.<br></li><li>Data analysis: If you remember the previous post, at one point we were looking at different models trained by the algorithm. We didn&#8217;t take the time to look at the design automated by the model. This section allows us to tweak several elements; such as the types of algorithms we run, the learning parameters, the choice of the dataset etc&#8230; <br><br>With so many features present in the dataset, Dataiku tried to reduce the number of features it would analyze, in order to simplify the learning algorithm. But it made poor choices. For example, it considers the street number but not the street itself. Even worse, it doesn&#8217;t even look at the date, or the parcels&#8217; surface area (but it does consider land surface when present&#8230;), which is by far the most important factor in most cities!</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/09/IMG_0255-1024x418.png" alt="Auto Machine Learning did bad choices" class="wp-image-19234" width="768" height="314" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0255-1024x418.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0255-300x122.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0255-768x313.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0255.png 1476w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure></div>



<h3 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Howtofixallofthat">How to fix all of that</h3>



<p>Fortunately, there are ways to solve these issues. Dataiku integrates tools to transform and filter your datasets before running your algorithms. It also allows you to change training parameters. Rather than walking you through all the steps, I&#8217;m going to summarize what I did for each of the issues we identified earlier:</p>



<h4 class="wp-block-heading">Data layout</h4>



<ul class="wp-block-list"><li>First, I grouped the lines that corresponded with the same transactions. Depending on the fields, I either summed them up (when it was a living area surface, for example), kept one of them (address), or concatenated them (when it was the identifier for an outbuilding, for example).</li><li>Second, I removed several unnecessary or redundant fields that add noise to the algorithm; such as street name (there are already per-city-unique street codes), street number suffix (&#8220;Bis&#8221; or &#8220;Ter&#8221; commonly found in an address after a street number) or other administration-related information.</li><li>Finally, some transactions contain not only several parcels (on several lines) but also several subparcels per parcel, each with its own surface and subparcel number. This subdivision is mostly administrative, and subparcels are often previously adjoining flats that have been reunited. To simplify the data, I cut the subparcel numbers and summed their respective surfaces, before regrouping the lines.</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/09/IMG_0254-935x1024.png" alt="Cleaning data layout" class="wp-image-19232" width="701" height="768" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0254-935x1024.png 935w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0254-274x300.png 274w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0254-768x841.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0254.png 1248w" sizes="auto, (max-width: 701px) 100vw, 701px" /></figure></div>



<h4 class="wp-block-heading">Data variety</h4>



<ul class="wp-block-list"><li>First, as we are trying to train a model to estimate the price of Parisian flats, I filtered out all the transactions that didn&#8217;t happen in Paris (which as you can expect is most of it).<br></li><li>Second, I removed all the transactions that had incomplete data for important fields (such as surface or address).<br></li><li>Finally, I removed outliers: transactions corresponding to properties that don&#8217;t correspond to standard flats; such as houses, commercial land, very high-end flats etc&#8230;</li></ul>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/08/674C0C3E-33DE-4AF1-B682-83654DD42F3B-1024x701.png" alt="Tackling data variety" class="wp-image-19146" width="768" height="526" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/674C0C3E-33DE-4AF1-B682-83654DD42F3B-1024x701.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/674C0C3E-33DE-4AF1-B682-83654DD42F3B-300x205.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/674C0C3E-33DE-4AF1-B682-83654DD42F3B-768x526.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/674C0C3E-33DE-4AF1-B682-83654DD42F3B.png 1527w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure></div>



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



<ul class="wp-block-list"><li>Model training parameters:<ul><li>First, I made sure that the model considered all the features. Note: rather than removing unnecessary fields from the dataset, I could have just told the algorithm to ignore the corresponding features. However, my preference is to increase the readability of the dataset to make it easier to explore. Moreover, Dataiku loads data in RAM to process it, so making it run on a clean dataset makes it more RAM-efficient.<br></li><li>Second, I trained the algorithm on different sets of features: in some cases I kept the district but not the street. As there are a lot of different streets in Paris this is a categorical feature with high cardinality (lots of different possibilities that can&#8217;t be numerized).<br></li><li>Finally, I tried different families of Machine Learning algorithms: Random Forest &#8211; basically building a decision tree; XGBoost &#8211; gradient boosting; SVM (Support Vector Machine)- a generalization of linear classifiers; and KNN (K-Nearest-Neighbours) &#8211; which tries to categorize data points by looking at its neighbors according to different metrics.</li></ul></li></ul>



<h1 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Diditwork?">Did it work?</h1>



<p>So, after all that, how did we fare? Well, first off, let us look at the R2 score of our models. Depending on the training session, our best models have an R2 score between 0.8 and 0.85. As a reminder, a R2 score of 1 would mean that the model perfectly predicts the price of every data point used in the training evaluation phase. The best models in our previous tries had an R2 score between 0.1 and 0.2, so we are already clearly better here. Let us now look at a few predictions from this model.</p>



<p>First, I re-checked all the transactions from my street. This time, the prediction for my flat is ~16% lower than the price I paid. But unlike last time, every flat has a different estimate and these estimates are all in the correct order of magnitude. Most values have less than 20% error when compared to the real price, and the worst estimates have ~50% error. Obviously, this margin of error is unacceptable when investing in a flat. However, when compared to the previous iteration of our model &#8211; that returned the same estimate for all the flats in my street &#8211; we are making significant progress.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/09/IMG_0250-1024x893.png" alt="A journey through the wondrous land of Machine Learning  - Did it work?" class="wp-image-19228" width="768" height="670" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0250-1024x893.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0250-300x262.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0250-768x669.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0250.png 1224w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure></div>



<p>So, now that we at least have the correct order of magnitude, let&#8217;s try and tweak some values in our input dataset to see if the model reacts predictably. To do this, I took the data point of my own transaction and created new data points, each time by changing one of the features of the original data point:</p>



<ol class="wp-block-list"><li>the surface to reduce it</li><li>the coordinates (street name, street code, geographic coordinates, etc) to put it in a cheaper district</li><li>the date of transaction to year 2015 (3 years prior to the real date)</li></ol>



<p>With each of these modifications, we would expect the new estimates to be lower than the original one (the real estate market in Paris is in permanent inflation). Let us look at the results:</p>



<figure class="wp-block-table"><table><thead><tr></tr></thead><tbody><tr><td class="has-text-align-center" data-align="center"><strong>Real Price</strong></td><td class="has-text-align-center" data-align="center"><strong>Original Estimate</strong></td><td class="has-text-align-center" data-align="center"><strong>Reduced Surface Estimate</strong></td><td class="has-text-align-center" data-align="center"><strong>Other District Estimate</strong></td><td class="has-text-align-center" data-align="center"><strong>Older Estimate</strong></td></tr><tr><td class="has-text-align-center" data-align="center">100%</td><td class="has-text-align-center" data-align="center">84%</td><td class="has-text-align-center" data-align="center">45%</td><td class="has-text-align-center" data-align="center">61%</td><td class="has-text-align-center" data-align="center">76%</td></tr></tbody></table></figure>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/09/IMG_0251-1024x562.png" alt="Tweaking values in the data-set" class="wp-image-19230" width="768" height="422" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0251-1024x562.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0251-300x165.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0251-768x422.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0251-1536x843.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/09/IMG_0251.png 1554w" sizes="auto, (max-width: 768px) 100vw, 768px" /></figure></div>



<p>At least the model behaves in an appropriate way, qualitatively speaking.</p>



<h1 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Howcouldwedobetter?">How could we do better?</h1>



<p>At this point, we have used common sense to significantly improve our previous results and build a model that gives predictions in a good order of magnitude and that behaves as we expect when tweaking the features of data points. However, the remaining margin of error makes it unsuitable for real-world application . But why, and what could we do to keep improving our model? Well there are several reasons:</p>



<p>Data complexity: I am going to contradict myself a little. While complex data is harder to digest for a Machine Learning algorithm, it is necessary to preserve this complexity if it reflects a complexity in the final result. In this case, we might not only have oversimplified the data, but the original data itself may lack a lot of relevant information.</p>



<p>We trained our algorithm on general location and surface, which admittedly are the most important criteria, but our dataset lacks very important information such as floors, exposure, construction years, insulation diagnostics, condition, accessibility, view, general state of the flats etc&#8230;</p>



<p>There are private datasets built by notarial offices that are more complete than our open dataset, but while those might have features such as floor or construction year, they would probably lack more subjective information; such as general state or view.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.ovh.com/blog/wp-content/uploads/2020/08/A72E1C7E-A66E-410A-A587-73AF9D538C95-1024x951.png" alt="Data complexity" class="wp-image-19143" width="768" height="713" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/08/A72E1C7E-A66E-410A-A587-73AF9D538C95-1024x951.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/A72E1C7E-A66E-410A-A587-73AF9D538C95-300x279.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/A72E1C7E-A66E-410A-A587-73AF9D538C95-768x713.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/08/A72E1C7E-A66E-410A-A587-73AF9D538C95.png 1395w" sizes="auto, (max-width: 768px) 100vw, 768px" /><figcaption>The dataset lacks very important information about the flats.</figcaption></figure>



<ul class="wp-block-list"><li>Data amount: Even if we had very complete data, we would need a vast amount of it. The more features we include in our training, the more data we need. And for such a complex task, the ~150K transactions per year we have in Paris are probably not enough. A solution could be to create artificial data points: flats that don&#8217;t really exist, but that human experts would still be able to evaluate. <br><br>But there are three issues with that: first, any bias in the experts would inevitably be passed on the model. Second, we would have to generate a huge number of artificial, but realistic data points and then would need the help of multiple human experts to label it. Finally, the aforementioned experts would label this artificial data based on their current experience. It would be very hard for them to remember the market prices from a few years ago. This means to have a homogeneous dataset over the years, we would have to create this artificial data over time and at the same pace as the real transactions happen.<br></li><li>Skills: Finally, being a data scientist is a full-time job that requires experience and skill. A real data scientist would probably be able to reach better results than what I obtained by adjusting the learning parameters and choosing the most appropriate algorithms.<br><br>Furthermore, even good data scientists would have to know their way around real estate and its pricing. It&#8217;s very hard to build advanced Machine Learning models without having a good comprehension of the topic at hand.</li></ul>



<h1 class="wp-block-heading" id="AjourneyinthewondrouslandofMachineLearning,or&quot;DoesaPalaceinParisreallycost100000€?&quot;(Part2)-Summary">Summary</h1>



<p>In this blog post, we discussed why our previous attempt at training a model to predict the price of flats in Paris failed. The data we used was not cleaned enough and we used Dataiku&#8217;s default training parameters rather than verifying that they made sense. </p>



<p>After that, we corrected our mistakes, cleaned the data and tweaked the training parameters. This improved the result of our model a lot, but not enough to use it realistically. There are ways to improve the model further, but the available datasets lack some information and the amount of data itself may not be sufficient to build a robust model. </p>



<p>Fortunately, the intent of this series was never to predict the price of flats in Paris perfectly. If it was possible, there would be no more real estate agencies. Instead, it serves as an illustration of how anyone can take raw data, find a problem related to the data and train a model to tackle this problem.</p>



<p>However, the dataset that we used in this example was quite small: only a few gigabytes. Everything happened on a single VM and we had to do everything manually, on a fixed dataset. What would I do if I wanted to handle petabytes of data? If I wanted to handle continuously streaming data? If I wanted to expose my model so that external applications could query it? </p>



<p>That is what we are going to look at next time, in the final blog post of the series.</p>
<img loading="lazy" decoding="async" src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-through-the-wondrous-land-of-machine-learning-or-can-i-really-buy-a-palace-in-paris-for-100000e-part-2%2F&amp;action_name=A%20journey%20through%20the%20wondrous%20land%20of%20Machine%20Learning%20or%20%26%238220%3BCan%20I%20really%20buy%20a%20palace%20in%20Paris%20for%20100%2C000%E2%82%AC%3F%26%238221%3B%20%28Part%202%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A journey into the wondrous land of Machine Learning, or &#8220;Did I get ripped off?&#8221; (Part 1)</title>
		<link>https://blog.ovhcloud.com/a-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1/</link>
		
		<dc:creator><![CDATA[Guillaume Ruty]]></dc:creator>
		<pubDate>Fri, 17 Apr 2020 15:31:58 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[A journey into the wondrous land of Machine Learning]]></category>
		<category><![CDATA[Machine learning]]></category>
		<guid isPermaLink="false">https://www.ovh.com/blog/?p=17870</guid>

					<description><![CDATA[Two years ago, I bought an apartment. It took me a year to get a proper idea of the real estate market: make some visits, get disappointed a couple of times, and finally find the flat of my dreams (and that I perceived to be priced appropriately for the market). But how exactly did I [&#8230;]<img src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1%2F&amp;action_name=A%20journey%20into%20the%20wondrous%20land%20of%20Machine%20Learning%2C%20or%20%26%238220%3BDid%20I%20get%20ripped%20off%3F%26%238221%3B%20%28Part%201%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></description>
										<content:encoded><![CDATA[
<p>Two years ago, I bought an apartment. It took me a year to get a proper idea of the real estate market: make some visits, get disappointed a couple of times, and finally find the flat of my dreams (and that I perceived to be priced appropriately for the market). </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="537" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-1024x537.png" alt="" class="wp-image-17908" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-1024x537.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-300x157.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20-768x403.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/949613E6-BB64-45A6-9A57-9C20A4808B20.png 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>But how exactly did I come up with this perceived &#8220;appropriate price&#8221;? Well, I saw a lot of ads for a lot of apartments. I found out that some properties were desirable and thus marketable (having a balcony, a good view, being in a safe district, etc), and step by step I built up my perception based on evidence of how these features impacted the price of an apartment.</p>



<p>In other words, I <em>learned</em> from <em>experience</em>, and this knowledge allowed me to build a mental <em>model</em> of how much an apartment should cost depending on its characteristics.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="835" height="542" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/49984FA3-16CC-4251-93F1-8B3B655DD4B4.png" alt="" class="wp-image-17914" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/49984FA3-16CC-4251-93F1-8B3B655DD4B4.png 835w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/49984FA3-16CC-4251-93F1-8B3B655DD4B4-300x195.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/49984FA3-16CC-4251-93F1-8B3B655DD4B4-768x499.png 768w" sizes="auto, (max-width: 835px) 100vw, 835px" /></figure>



<p>But like every other human being, I am fallible, and thus keep asking myself the same question: &#8220;Did I get ripped off?&#8221;. Well, looking back at the process that led me there, it is evident that there is a way to follow the same process, but with more data, less bias, and hopefully in better time: Machine Learning.</p>



<p>In this series of blog posts, I am going to explore how Machine Learning could have helped me estimate the price of the apartment I bought; what tools you would need to do that, how you would proceed, and what difficulties you might encounter. Now, before we dive head first into this wondrous land, here is a quick disclaimer: the journey we are about to go through together serves as an illustration of how Machine Learning works and why it is not, in fact, magic.</p>



<p>You will not finish this journey with an algorithm that is able to price any apartment with extreme precision. You will not be the next real estate mogul (if it was that simple, I would be selling courses on how to become a millionaire on Facebook for 20€). Hopefully, however, if I have done my job correctly, you will understand why Machine Learning is simpler than you might think, but not as simple at it may appear. </p>



<h3 class="wp-block-heading">What do you need to build a model with Machine Learning?</h3>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="535" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/532C9B7B-0ADB-48DF-8A14-339CD19BD23F-1024x535.png" alt="" class="wp-image-17913" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/532C9B7B-0ADB-48DF-8A14-339CD19BD23F-1024x535.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/532C9B7B-0ADB-48DF-8A14-339CD19BD23F-300x157.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/532C9B7B-0ADB-48DF-8A14-339CD19BD23F-768x401.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/532C9B7B-0ADB-48DF-8A14-339CD19BD23F.png 1142w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<h4 class="wp-block-heading">Labelled data</h4>



<p>In this example, for predicting property exchange value, we are looking for data that contains the characteristics of houses and apartments as well as the price they were sold for (the price being the label). Luckily, a few years ago, the French government decided to build an <a href="https://www.data.gouv.fr/fr/" data-wpel-link="external" target="_blank" rel="nofollow external noopener noreferrer">open data platform</a> providing access to dozens of datasets related to the administration &#8211; such as a public drug database, real-time atmospheric pollutant concentration and many others. Luckily for us, they included a dataset containing property transactions! </p>



<p>Well, here is <a href="https://www.data.gouv.fr/fr/datasets/demandes-de-valeurs-foncieres/" data-wpel-link="external" target="_blank" rel="nofollow external noopener noreferrer">our dataset</a>. If you look through the webpage, you will see that there are multiple community contributions, which all enrich the data, making it suitable for a macro-analysis. For our purposes we can use the <a href="https://www.data.gouv.fr/fr/datasets/5cc1b94a634f4165e96436c1/" data-wpel-link="external" target="_blank" rel="nofollow external noopener noreferrer">dataset provided by Etalab</a>, the public organisation responsible for maintaining the open data platform.</p>



<h4 class="wp-block-heading">Software</h4>



<p>This is where it gets a bit tricky. If I were a gifted data scientist, I could simply rely on an environment &#8211; such as TensorFlow, PyTorch, or ScikitLearn &#8211; to load my data, and find out which algorithm is best to train a model. From here, I could determine the optimal learning parameters and then train it. Unfortunately, I am not a gifted data scientist. But, in my misfortune, I am still lucky: there are tools &#8211; generally grouped under the name &#8220;AI Studios&#8221; &#8211; which are developed exactly for this purpose, yet require none of the skills. In this example, we will use <a href="https://www.dataiku.com/" data-wpel-link="external" target="_blank" rel="nofollow external noopener noreferrer">Dataiku</a>, one of the most well-known and effective AI Studios:</p>



<h4 class="wp-block-heading">Infrastructure</h4>



<p>Obviously, the software has to run on a computer. I could try to install Dataiku on my machine, but since we are on the OVHCloud blog, it seems suitable that we would deploy it in the Cloud! As it turns out, you can easily deploy a Virtual Machine with Dataiku pre-installed on our <a href="https://www.ovh.com/fr/cloud-apps/dataiku.xml" data-wpel-link="exclude">Public Cloud</a> (you could also do that on some of our competitors&#8217; public cloud) with a free community license. With the Dataiku tool, I should be able to upload the dataset, train a model, and deploy it. Easy, right?</p>



<h3 class="wp-block-heading">Working with your dataset</h3>



<p>Once you have installed your VM, Dataiku automatically launches a web server accessible through the port 11000. To access it, simply go to your browser and type <code>http://&lt;your-VM-IP-address&gt;:11000.</code> You will then be greeted by the welcome screen prompting you to register for a free community license. Once all this is done, create your first project and follow the steps to import your first dataset (you should just have to drag and drop a few files) and save it.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="374" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku1-1024x374.png" alt="" class="wp-image-17872" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku1-1024x374.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku1-300x109.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku1-768x280.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku1-1536x560.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku1.png 1905w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="351" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku2-1024x351.png" alt="" class="wp-image-17873" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku2-1024x351.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku2-300x103.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku2-768x263.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku2-1536x526.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku2.png 1893w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>Once this is done, go to the &#8220;Flow&#8221; view of your project. You should see your dataset there. Select it and you will see a wide range of possible actions. </p>



<p>Now, let&#8217;s get straight to the point and train a model. To do that, go to the &#8220;Lab&#8221; action and select the &#8220;Quick Model&#8221; then &#8220;Prediction&#8221; options, with &#8220;valeur_fonciere&#8221; as the target variable (as we are trying to predict the price). </p>



<p>Since we are not experts, let&#8217;s try the Automated Machine Learning proposed by Dataiku with an interpretable model and train it. Dataiku should automatically train two models, a decision tree and a regression, with one having a better score than the other (the default metric chosen is the R2 score, one of the multiple metrics that can be used to evaluate the performance of a model). Click on this model and you will be able to deploy it. You are now able to use this model on any dataset following the same scheme.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="452" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku3-1024x452.png" alt="" class="wp-image-17874" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku3-1024x452.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku3-300x133.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku3-768x339.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku3-1536x679.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku3.png 1892w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="475" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku4-1024x475.png" alt="" class="wp-image-17875" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku4-1024x475.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku4-300x139.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku4-768x356.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku4-1536x712.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku4.png 1904w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>Now that the model is trained, let&#8217;s try it and see if it predicts the correct price for the apartment I bought! Now for very obvious reasons, I will not share with you my address, the price of my apartment or other such personal informations. Therefore, for the remainder of this post, I will pretend that I bought my apartment for 100€ (lucky me!) and normalize every other price the same way.</p>



<p>As I mentioned above, in order to query the model, we need to build a new dataset comprised of the data we want to test. In my case, I just had to build a new csv file from the header (you have to keep it in the file for Dataiku to understand it) and the line that relates to the actual transaction I made (easy as it was already done). </p>



<p>If I wanted to do that for a property I intended to buy, I would have had to gather as much information as possible to best fill the criteria in the scheme (address, surface, postal code, geographic coordinates, etc) and build that line myself. At this stage, I am also able to build a dataset with multiple lines to query the model on several cases at once. </p>



<p>Once this new dataset is built, just upload it like first time and go back to the flow view. Your new dataset should appear there. Click on the model on the right of the flow and then on the &#8220;Score&#8221; action. Select your sample dataset, go with the default options and run the job. You should now have a new dataset appearing in your flow. If you explore this dataset, you will see that there is a new column at the end, containing the predictions!</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="415" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku5-1024x415.png" alt="" class="wp-image-17876" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku5-1024x415.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku5-300x122.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku5-768x311.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku5-1536x623.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku5.png 1907w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="421" src="https://www.ovh.com/blog/wp-content/uploads/2020/04/dataiku6-1024x421.png" alt="" class="wp-image-17878" srcset="https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku6-1024x421.png 1024w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku6-300x123.png 300w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku6-768x316.png 768w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku6-1536x631.png 1536w, https://blog.ovhcloud.com/wp-content/uploads/2020/04/dataiku6.png 1900w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>In my case, for my 100€ apartment, the price predicted is 105€. That can mean two things:</p>



<ul class="wp-block-list"><li>The model we trained is quite good, and the property was a good deal! </li></ul>



<p>Or&#8230;</p>



<ul class="wp-block-list"><li>The model made a lucky guess.</li></ul>



<p>Lets give it a go on the other transactions that have taken place on the same street and in the same year. Well, this time the result is underwhelming: apparently, every apartment bought on my street in 2018 is worth exactly 105€, regardless of their size or features. If I had known that, I would probably have bought a bigger apartment! It would appear that our model is not as smart as we initially thought and we still have work to do&#8230;</p>



<p>In this post, we explored where machine learning might come in handy, which data would be helpful, the software we need to make use of it, and looked at the infrastructure required to run the software. We found that everyone can give machine learning a go &#8211; it is not magic &#8211; but we also found that we would have to work a bit harder to get results. Indeed, rushing into the wondrous journey as we did, we did not take the time to look more closely at the data itself and how to make it easier to exploit the model &#8211; nor did we look at what the model was actually observing when predicting a price. If we had, we would have realized that indeed, it didn&#8217;t make sense. In other words, we did not <em>qualify</em> our problem enough. But let that not diminish our enthusiasm on our journey, for this is merely a small setback!</p>



<p>In the next post, we will go further on our journey and understand why the model we trained was ultimately useless: we will look more precisely at the data we have at our disposal and will find multiple ways to make it more suitable for the machine learning algorithms &#8211; following simple, common sense guidelines. Hopefully, with better data, we will then be able to greatly improve our model.</p>
<img loading="lazy" decoding="async" src="//blog.ovhcloud.com/wp-content/plugins/matomo/app/matomo.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fblog.ovhcloud.com%2Fa-journey-into-the-wondrous-land-of-machine-learning-or-did-i-get-ripped-off-part-1%2F&amp;action_name=A%20journey%20into%20the%20wondrous%20land%20of%20Machine%20Learning%2C%20or%20%26%238220%3BDid%20I%20get%20ripped%20off%3F%26%238221%3B%20%28Part%201%29&amp;urlref=https%3A%2F%2Fblog.ovhcloud.com%2Ffeed%2F" style="border:0;width:0;height:0" width="0" height="0" alt="" />]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
