<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marieke Kortsmit on Medium]]></title>
        <description><![CDATA[Stories by Marieke Kortsmit on Medium]]></description>
        <link>https://medium.com/@mariekekortsmit?source=rss-b14be5267320------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LtaceChEPAarZGJOLU6Psg.jpeg</url>
            <title>Stories by Marieke Kortsmit on Medium</title>
            <link>https://medium.com/@mariekekortsmit?source=rss-b14be5267320------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:52:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mariekekortsmit/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Access to Azure Data Lake Storage Gen 2 from Databricks Part 1: Quick & Dirty]]></title>
            <link>https://medium.com/@mariekekortsmit/access-to-azure-data-lake-storage-gen-2-from-databricks-part-1-quick-dirty-6cd5a89aa823?source=rss-b14be5267320------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cd5a89aa823</guid>
            <dc:creator><![CDATA[Marieke Kortsmit]]></dc:creator>
            <pubDate>Fri, 14 Jun 2019 22:01:54 GMT</pubDate>
            <atom:updated>2019-06-18T09:24:22.905Z</atom:updated>
            <content:encoded><![CDATA[<h4>Support to existing documentation</h4><p>If you search your favorite search engine on how to access ADLS Gen 2 from your Databricks notebook, it will probably give you this great <a href="https://docs.databricks.com/spark/latest/data-sources/azure/azure-datalake-gen2.html">reference</a>. Although this documentation is pretty good, I personally struggled bigtime to set this up. Therefore, this blog is an attempt to clarify this with screenshots and some additional text. Make sure to read the original <a href="https://docs.databricks.com/spark/latest/data-sources/azure/azure-datalake-gen2.html">documentation </a>for the full story.</p><h3>Assumptions</h3><p>Let&#39;s assume:</p><ul><li>You have an ADLS Gen 2 storage account set up in your Azure subscription (ref this <a href="https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-quickstart-create-account">Quickstart</a>) with name &lt;your-storage-account-name&gt;;</li><li>You have created a blob container in this storage account with name &lt;your-file-system-name&gt; which contains a file file.csv.</li><li>You have Databricks set up in y our Azure subscription (ref this <a href="https://docs.microsoft.com/en-us/azure/azure-databricks/quickstart-create-databricks-workspace-portal">Quickstart</a>);</li><li>You want to access file.csv from your Databricks notebook.</li></ul><p>Note that in my case I&#39;ve used Python and to confirm that you have done it the way I picture it, find below two screenshots from my ADLS where I have:</p><ul><li>ADLS with name adlsmarieke</li><li>Blob container with name container1</li><li>File file.csv in it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*eBJrntYYKC-9VFyNgZ53fQ.png" /><figcaption>ADLS adlsmarieke with blob container container1 and file file.csv in it, displayed in <a href="https://azure.microsoft.com/en-us/features/storage-explorer/">Microsoft Azure Storage Explorer</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_DcvpOrxXHUPaGBuHx4Wg.png" /><figcaption>ADLS adlsmarieke with blob container container1 and file file.csv in it, displayed in the Azure Portal.</figcaption></figure><h3>Options</h3><p>Databricks documentation provides three ways to access ADLS Gen2:</p><ol><li><a href="https://docs.databricks.com/spark/latest/data-sources/azure/azure-datalake-gen2.html#mount-an-adls-filesystem-to-dbfs-using-a-service-principal-and-oauth-2-0">Mount an Azure Data Lake Storage Gen2 filesystem to DBFS using a Service Principal and OAuth 2.0</a></li><li><a href="https://docs.databricks.com/spark/latest/data-sources/azure/azure-datalake-gen2.html#access-an-adls-account-directly-with-oauth-2-0-using-the-service-principal">Access an Azure Data Lake Storage Gen2 account directly with OAuth 2.0 using the Service Principal</a></li><li><a href="https://docs.databricks.com/spark/latest/data-sources/azure/azure-datalake-gen2.html#access-an-adls-account-directly-using-the-storage-account-access-key"><strong>Access an Azure Data Lake Storage Gen2 account directly using the storage account access key</strong></a></li></ol><p>The easiest and quickest way is option 3. This post has focus on option 3 which is very suitable for some quick testing. I&#39;m working on creating posts for the other options as you probably don&#39;t want to go with option 3 in real scenarios (too quick and dirty for secure solutions).</p><h3>Part 1: Quick and Dirty</h3><p>You can access an Azure Data Lake Storage Gen2 storage account using the storage account access key directly by using the following code snippet:</p><pre>spark.conf.set(&quot;fs.azure.account.key.&lt;your-storage-account-name&gt;.dfs.core.windows.net&quot;,dbutils.secrets.get(scope <strong>=</strong> &quot;&lt;scope-name&gt;&quot;, key <strong>=</strong> &quot;&lt;key-name&gt;&quot;))</pre><p>which you can replace by the even quicker and dirtier method:</p><pre>spark.conf.set(&quot;fs.azure.account.key.&lt;your-storage-account-name&gt;.dfs.core.windows.net&quot;,&quot;&lt;access-key&gt;&quot;)</pre><p>where you can replace the items between &lt;brackets&gt; by information you can get from the ADLS Gen2 page on the Azure portal (specifically on the Acces Keys tab).</p><blockquote>Note that in Databricks documentation, if something is shown between &lt;&gt; brackets, you are supposed to replace the whole thing, including &lt;&gt; by something custom to your project. If something is shown between “&lt;&gt;”, this means the double quotes stay and the &lt;&gt; brackets have to go.</blockquote><p>Replace:</p><ul><li>&lt;your-storage-account-name&gt; with the name of your storage account, in the case of the picture below that would be adlsmarieke</li><li>&lt;acces-key&gt; by the string that is included in the Key box, as highlighted in the picture below, so it should look something like &quot;whatever-you-copied-from-the-box&quot;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gDVH9d5UmF4z584KW9bWmg.png" /><figcaption>Screenshot of ADLS Gen2 on Azure Portal</figcaption></figure><p>You can now read your file.csv which you stored in container1 in ADLS from your notebook by (note that the directory &lt;your-directory-name&gt; is optional):</p><pre>df = spark.read.csv(&quot;abfss://&lt;your-file-system-name&gt;@&lt;your-storage-account-name&gt;.dfs.core.windows.net/&lt;your-directory-name&gt;/&lt;your-file-name&gt;&quot;)</pre><p>which in my case looks like this:</p><pre>df = spark.read.csv(&quot;abfss://container1@adlsmarieke.dfs.core. windows.net/file.csv&quot;)</pre><p>Now you can have fun and work with your dataframe in the notebook! :)</p><blockquote>The cells to read the csv file are in Python. In case you are using Scala, use val df instead of df!</blockquote><h3>Part 1.1: Quick and a little less Dirty</h3><p>In the above demonstrated piece you are directly inserting your access key into your notebook. This is a very <strong>bad </strong>practice, which you should never ever do. However, it is a very quick way to do some testing.</p><p>The quickest solution to remove your key from the code is to set up a Databricks secret. Follow the below steps to set up everything you need to generate a secret:</p><h4>1. Create a personal access token to Databricks:</h4><p>This <a href="https://docs.azuredatabricks.net/api/latest/authentication.html#token-management">reference </a>doesn&#39;t need further explanation. Remember to copy the token once you have created it as you won&#39;t be able to see it again.</p><h4>2. Use Databricks CLI from Azure Cloud Shell:</h4><p>The easiest way to use the Databricks CLI is from the Azure Cloud Shell. Read all about it <a href="https://docs.microsoft.com/en-us/azure/azure-databricks/databricks-cli-from-azure-cloud-shell">here</a>.</p><p>Copy the highlighted URL from the Databricks page in your Azure portal as the Databricks host:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJjPn2VBj-R0uuiG2HU_Pg.png" /><figcaption>Screenshot of Databricks in the Azure Portal.</figcaption></figure><p>The token asked is the personal access token to Databricks you&#39;ve copied in step 1.</p><h4>3. Create a Databricks-backed secret scope</h4><p>Refer to <a href="https://docs.databricks.com/user-guide/dev-tools/databricks-cli.html#secrets-cli">this link</a> to read all about the Secrets CLI within the Databricks CLI to create your Databricks-backed secret scope. Basically only 2 steps are needed, just paste the following commands in your Databricks CLI:</p><pre>databricks secrets create-scope --scope &lt;scope-name&gt;<br>databricks secrets put --scope &lt;scope-name&gt; --key &lt;key-name&gt; <br>--string-value &lt;access-key&gt;</pre><p>which in my case from the Azure Cloud Shell looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*JCXVv8OxZWW5Aflya3GKyA.png" /><figcaption>Screenshot from the Azure Cloud Shell where I created my Databricks secret</figcaption></figure><p>with &lt;access-key&gt; the same Key string as copied from your Azure portal in Part 1. Once you&#39;re done with that, you can safely refer to this key as follows in your Databricks notebook:</p><pre>spark.conf.set(&quot;fs.azure.account.key.&lt;your-storage-account-name&gt;.dfs.core.windows.net&quot;,dbutils.secrets.get(scope <strong>=</strong> &quot;&lt;scope-name&gt;&quot;, key <strong>=</strong> &quot;&lt;key-name&gt;&quot;))</pre><p>which in my case looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*M3-9I8Foh4YicIq6NHUY-A.png" /><figcaption>My Databricks notebook connecting to ADLS via a Databricks secret</figcaption></figure><h3>To be continued</h3><p>This is it! Or, at least, this is it if you want to connect ADLS to Databricks in a quick way.</p><p>I am working on follow up posts to give more details around the options of mounting and accessing by using OAuth 2.0 and a Service Principal.</p><p>In the meantime: if you&#39;re stuck, or something of the abovementioned info doens&#39;t work for you, feel free to leave a comment with an ask as I or other Medium readers might be able to help out! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cd5a89aa823" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Feature Engineering for Time Series Data in R]]></title>
            <link>https://medium.com/@mariekekortsmit/feature-engineering-for-time-series-data-ad4f52548a16?source=rss-b14be5267320------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad4f52548a16</guid>
            <category><![CDATA[timeseries]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[azure-notebooks]]></category>
            <dc:creator><![CDATA[Marieke Kortsmit]]></dc:creator>
            <pubDate>Fri, 23 Mar 2018 13:02:04 GMT</pubDate>
            <atom:updated>2018-04-16T09:43:06.334Z</atom:updated>
            <content:encoded><![CDATA[<h4>Creating features for Machine Learning</h4><p>Time series data usually comes in the form of a timestamp and a measurement. The big question is: how to create more useful features to be able to use machine learning?</p><p>In my recent projects I found that aggregating the measurement over a time window is very very helpful and can improve your predictions big time. I saw prediction rates going up once I applied this ‘trick’ so I wanted to share the idea with you!</p><p>To write this post I used <a href="https://notebooks.azure.com/">Azure Notebooks</a>: a free interactive coding experience powered by Jupyter.</p><h3>Aggregation on which level?</h3><p>When adding features to a data set it is important to keep in mind how you are going to use them for machine learning. Let’s assume a very simple sample data set sensordata:</p><pre>╔══════╦═════════════╗<br>║ ID   ║ Measurement ║<br>╠══════╬═════════════╣<br>║ 1    ║ 3           ║ <br>║ 2    ║ 5           ║ <br>║ 3    ║ 9           ║ <br>║ 4    ║             ║ <br>╚══════╩═════════════╝</pre><p>Row ID = 4 represents the datapoint we want to predict, i.e. see whether the incoming value is normal or if it differs a lot from the expected value. Therefore, features to be added to row ID = 4 can only be created from information in previous measurements, rows ID = 1,2,3: the information for ID = 4 is not yet available.</p><h3>Feature Examples</h3><p>Engineered features for measurement S at time mcould be:</p><ul><li>Change between previous measurement: <br>S(m-1)-S(m-2);</li><li>Change over a time window of size w:<br>[S(m-1)-S(m-1-w)]/[t(m-1)-t(m-1-w)];<br>Note that if measurements are regular, you can also just divide by w;</li><li>Average over a time window <br>[S(m-1)+...+S(m-1-w)]/[t(m-1)-t(m-1-w)];</li><li>Relative growth over a time window: <br>[S(m-1)-S(m-1-w)]/S(m-1-w);</li></ul><p>Note once again that aggregations can only be made based upon previous measurements since measurement S(m) is not known yet.</p><p>To expand the list of possible aggregations, think about your use case and what aggregations could be valuable: maybe it is the maximum, minimum, average, standard deviation,…… over a certain time window: everything is possible! Just be sure to make it <strong>useful </strong>information to help the algorithm <em>understand </em>what is going on in your data.</p><h3>Code examples</h3><p>How to implement these features into your data set? See below for a code example in R on how to engineer additional features.</p><h4>R sample for regular time intervals</h4><p>For this example we use the above mentioned simple data set sensordata. Note that in this data set we assume the time between measurements is regular since we only have the ID of a reading and not the timestamp. We take window w = 2and assume we want to calculate the mean value over these measurements:</p><pre>library(zoo)<br>width = 2<br>means = rollmean(sensordata$Measurement,width)<br>sensordata$Mean = c(rep(NA,width),means[1:(nrow(sensordata)-width)])</pre><p>The function rollmean could also be replaced by rollmax and rollmedian, and there are also possibilities for a custom function. In this example the custom function still contains the mean, but this can be replaced by any function:</p><pre>custom_function = function(vec){<br>  return(mean(vec))<br>}</pre><pre>width = 2<br>customvals = rollapply(sensordata$Measurement,width = 2,<br>                       FUN = custom_function) <br>sensordata$Mean = c(rep(NA,width),<br>                    customvals[1:(nrow(sensordata)-width)])</pre><p>Both code blocks results in the following data set:</p><pre>╔══════╦═════════════╦═══════════╗<br>║ ID   ║ Measurement ║ Mean      ║<br>╠══════╬═════════════╬═══════════╣<br>║ 1    ║ 3           ║ NA        ║<br>║ 2    ║ 5           ║ NA        ║<br>║ 3    ║ 9           ║ 4         ║<br>║ 4    ║             ║ 7         ║<br>╚══════╩═════════════╩═══════════╝</pre><p>You now have one feature to use to predict the measurement at ID = 4 by using machine learning algorithms. In this example we added the mean values of the previous 2 measurements as a feature, but keep in mind that including something very simple as the previous measurement as a feature is also very valuable.</p><h4>R sample for irregular time intervals</h4><p>For this example, assume a slightly different data set sensordata:</p><pre>╔══════╦═════════════╗<br>║ Time ║ Measurement ║<br>╠══════╬═════════════╣<br>║ 1    ║ 3           ║ <br>║ 2    ║ 5           ║ <br>║ 3    ║ 9           ║ <br>║ 4    ║ 10          ║ <br>║ 6    ║ 13          ║<br>║ 7    ║             ║<br>╚══════╩═════════════╝</pre><p>Note that in this data set we have a time indicator instead of an ID, this could be seconds, hours, but also any timestamp. The time between measurements is not regular since we don’t have a measurement for Time = 5. Assume a window w = 2 and assume we want to calculate the change over that time window:</p><pre>custom_function = function(x){<br>  return (x[window,2] - x[1,2])/ (x[window,1] - x[1,1])<br>}</pre><pre>window = 2<br>change = rollapply(sensordata, window, custom_function, <br>                   by.column = FALSE)<br>sensordata$Change= c(rep(NA,window),<br>                     change[1:(nrow(sensordata)-width)])</pre><p>The result will look like:</p><pre>╔══════╦═════════════╦════════╗<br>║ Time ║ Measurement ║ Change ║<br>╠══════╬═════════════╬════════╣<br>║ 1    ║ 3           ║ NA     ║<br>║ 2    ║ 5           ║ NA     ║<br>║ 3    ║ 9           ║ 2      ║<br>║ 4    ║ 10          ║ 4      ║<br>║ 6    ║ 13          ║ 1      ║<br>║ 7    ║             ║ 1,5    ║<br>╚══════╩═════════════╩════════╝</pre><p>You now have one feature to use to predict the measurement at Time = 7 by using machine learning algorithms. Let your creativity flow and create more features in a similar way to improve your predictions even further!</p><h4>Writing your own custom function for irregular time intervals</h4><p>At first, I struggled with writing a custom function for irregular time intervals, because the rollapply custom function is not that self explanatory. For understanding it is very helpful to include a print statement inside the custom_function. which then looks like:</p><pre>custom_function = function(x){<br>  print(x)<br>  yourresult = (x[window,2] - x[1,2])/ (x[window,1] - x[1,1])<br>  return(yourresult)<br>}</pre><p>Resulting in:</p><pre>      Time Measurement<br>[1,]  1              3 <br>[2,]  2              5      <br>      Time Measurement<br>[1,]  2              5 <br>[2,]  3              9      <br>      Time Measurement<br>[1,]  3              9 <br>[2,]  4             10      <br>      Time Measurement<br>[1,]  4             10 <br>[2,]  6             13      <br>      Time Measurement<br>[1,]  6             13 <br>[2,]  7</pre><p>As you can see, inside custom_function your data set x is already sliced based on the provided window w and is now represented by multiple 2*window-sized matrices. Your custom function will automatically be applied to each of these matrices and you only need to write your code as if you were applying it to one of these matrices!</p><h3>Summary</h3><p>The question of this article is how to aggregate measurements over a time window to be able to use these measurements as features for machine learning. We see that usingrollapply in R is an excellent way to provide such aggregations!</p><h3>Questions</h3><p>Let me know in the comments if you have any questions, feedback, suggestions, asks! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad4f52548a16" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>