<?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 Cloudleaf on Medium]]></title>
        <description><![CDATA[Stories by Cloudleaf on Medium]]></description>
        <link>https://medium.com/@pdunna_11739?source=rss-c7a8d5b9c33c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nB6TLLW4Y6WyS-gn2OOWGQ.png</url>
            <title>Stories by Cloudleaf on Medium</title>
            <link>https://medium.com/@pdunna_11739?source=rss-c7a8d5b9c33c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:58:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pdunna_11739/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[Computing Asset Utilization in Real Time using Machine Learning — Part 2]]></title>
            <link>https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-2-c9928902ebc8?source=rss-c7a8d5b9c33c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9928902ebc8</guid>
            <dc:creator><![CDATA[Cloudleaf]]></dc:creator>
            <pubDate>Wed, 02 Sep 2020 22:58:53 GMT</pubDate>
            <atom:updated>2020-09-17T01:21:42.921Z</atom:updated>
            <content:encoded><![CDATA[<h3>Computing Asset Utilization in Real Time using Machine Learning — Part 2</h3><h4>Authored By Malini Pathakota &amp; Pradeep Dunna</h4><h3>Introduction</h3><p>Now that our accelerometer batch data has been partitioned, clustered, and labeled, we can create a machine learning model to partition the streaming data in real time and instantaneously classify it as ‘utilized’ or ‘ not utilized.’ This is done by identifying changepoints using a Bayesian model and classifying the created partitions using K-Nearest-Neighbors. Through this process, the utilization of assets can be determined in real time and the overall percentage of utilization can be calculated.</p><p>We created the set of labeled training data in <strong>Part 1</strong> of the project, which can be found at: <a href="https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-1-e636fefb086c">https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-1-e636fefb086c</a>.</p><h3>Bayesian Model and Classifying Streaming Data</h3><p>We utilize a Bayesian Model to detect a change point as it comes in and partition the accelerometer data immediately to be classified. The Bayesian model works by calculating the initial probability of a point being a changepoint and continually adjusting the probability based on the new points coming into the stream. A matrix ‘R’ is populated with these probabilities and once a probability crosses a certain threshold, the associated point is identified as the changepoint and the streaming data is partitioned and classified.</p><pre>from __future__ import division<br>from functools import partial<br>from scipy import stats<br>from scipy.spatial import distance</pre><pre>class BayesianStream:  <br>  def __init__(self):<br>    self.hazard_func = partial(self.constant_hazard_temp, 250)<br>    self.observation_likelihood = BayesianModel(0.1, .01, 1, 0)<br>    <br>    self.maxes = np.zeros(100 + 1)<br>    self.R = np.zeros((100 + 1, 100 + 1))<br>    self.R[0, 0] = 1<br>    <br>    self.index = 0<br>    self.flag = False<br>    self.streamdata = []<br>    self.points = []<br>    self.util = []<br>    self.memory = []<br>    self.count_partitions = 0<br>  <br>  def constant_hazard_temp(self, lam, r):<br>    return 1/lam * np.ones(r.shape)<br>  <br>  def reset(self):<br>    self.hazard_func = partial(self.constant_hazard_temp, 250)<br>    self.observation_likelihood = BayesianModel(0.1, .01, 1, 0)<br>    <br>    #self.maxes = np.zeros(100 + 1)<br>    #self.R = np.zeros((100 + 1, 100 + 1))<br>    self.maxes = np.zeros(100)<br>    self.R = np.zeros((100, 100))<br>    self.R[0, 0] = 1<br>    <br>    self.index = 0<br>    self.flag = False<br>    self.streamdata = []<br>  <br>  def find_cluster(self, stream_matrix):<br>    centers = model.clusterCenters()<br>    num_centers = len(centers)-1<br>    dist = [0] * num_centers<br>    mindist = [10] * 2<br>    for i in range(0, num_centers):<br>      dist[i] = distance.euclidean(centers[i], stream_matrix)<br>      if dist[i] &lt;= mindist[0]:<br>        mindist[0] = dist[i]<br>        mindist[1] = i</pre><pre>    if(mindist[1] == 0):<br>      self.util.append(0)<br>    else:<br>      self.util.append(1)<br>  <br>  def streaming(self, data):<br>    self.streamdata.append(data)<br>    tempval = False<br>    <br>    if (len(self.streamdata) == 100):<br>      self.count_partitions = self.count_partitions + 1<br>      streaming_partition = self.streamdata<br>      stream_matrix = self.find_frequencies(streaming_partition) <br>      self.find_cluster(stream_matrix)<br>      self.points.append(self.index)<br>      self.flag = False;<br>      self.reset()<br>    else:<br>      predprobs = self.observation_likelihood.pdf(data)<br>      t = self.index<br>      H = self.hazard_func(np.array(range(t+1)))</pre><pre>      self.R[1:t+2, t+1] = self.R[0:t+1, t] * predprobs * (1-H)<br>      self.R[0, t+1] = np.sum(self.R[0:t+1, t] * predprobs * H)<br>      self.R[:, t+1] = self.R[:, t+1] / np.sum(self.R[:, t+1])<br>      self.observation_likelihood.update_theta(data)</pre><pre>      if(t &gt;= 8):<br>        if(self.R[7,7:-1][t-7] &gt;= 0.2):<br>          self.flag = True<br>          tempval = True<br>          self.memory = self.streamdata[-8:]<br>          self.count_partitions = self.count_partitions + 1<br>          self.points.append(temp.index-8)</pre><pre>        if self.flag == True:<br>          streaming_partition = self.streamdata[0:(temp.index)-7]<br>          stream_matrix = self.find_frequencies(streaming_partition)        <br>          self.find_cluster(stream_matrix)</pre><pre>          self.flag = False;<br>          self.reset()</pre><pre>      if tempval == False:<br>        self.index = self.index + 1<br>        self.maxes[t] = self.R[:, t].argmax()</pre><p>In order to simulate streaming data to test our Bayesian Model’s capability of determining changepoints in real time, we send in a series of data, such as the series shown below, one point at a time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o3MzpNymxa4Y95gl.png" /><figcaption>Simulated streaming accelerometer data</figcaption></figure><p>As mentioned above, the probability matrix ‘R’ is calculated and updated for every new point that is read into the model. One calculation for the matrix ‘R’ is shown below. The threshold we set for our code is 0.2 so when a probability in the ‘R’ matrix is above this value, that point is identified as the changepoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/0*-Usy9VH9X_K8Z_RQ" /><figcaption>R matrix of probabilities</figcaption></figure><p>Once a changepoint is identified and the sequence is partitioned, the sequence is converted into a frequency matrix using the same process from the previous phase of this project. The euclidean distance between this frequency matrix and each of the cluster centroids is calculated and the pair with the shortest distance corresponds to the cluster that the sequence belongs to. Then, depending on the cluster identified, the partition is labeled as ‘utilized’ or ‘not utilized.’</p><pre>from scipy.spatial import distancecenters = model.clusterCenters()<br>dist = [0] * 5<br>mindist = [10] * 2<br>for i in range(0,5):<br>  dist[i] = distance.euclidean(centers[i], stream_matrix)<br>  if dist[i] &lt;= mindist[0]:<br>  mindist[0] = dist[i]<br>  mindist[1] = i</pre><p>After partitioning and classifying a sequence of the streaming data, the model resets the ‘R’ matrix and new probabilities populate the matrix as more points are read. This process continues until the next changepoint is found or the sequence length hits 100. At this point, the model automatically classifies the sequence as ‘utilized’ or ‘not utilized’ even if a changepoint wasn’t identified. This continues until we run out of streaming data.</p><p>The graph below shows the output after our entire inputted sequence is processed by the model. The pink partition was labeled as ‘utilized’ while the blue partitions were labeled as ‘not utilized.’ The gray vertical lines indicate the detected changepoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FOruPMNWKJcprmQb.png" /><figcaption>Classified streaming accelerometer data</figcaption></figure><p>Now that we have created a streaming machine learning model that can classify data as ‘utilized’ or ‘not utilized’ in real time, we can integrate the model into the existing Spark streaming pipeline and calculate asset utilization using dstreams. This process will be explained in <strong>Part 3</strong> when it is complete.</p><h3>References</h3><p>Gundersen, G. (2019, August 13). Bayesian Online Changepoint Detection. Retrieved August 21, 2020, from <a href="http://gregorygundersen.com/blog/2019/08/13/bocd/">http://gregorygundersen.com/blog/2019/08/13/bocd/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9928902ebc8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-2-c9928902ebc8">Computing Asset Utilization in Real Time using Machine Learning — Part 2</a> was originally published in <a href="https://medium.com/cloudleaf">Cloudleaf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computing Asset Utilization in Real Time using Machine Learning — Part 1]]></title>
            <link>https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-1-791e901ece16?source=rss-c7a8d5b9c33c------2</link>
            <guid isPermaLink="false">https://medium.com/p/791e901ece16</guid>
            <dc:creator><![CDATA[Cloudleaf]]></dc:creator>
            <pubDate>Mon, 31 Aug 2020 21:43:19 GMT</pubDate>
            <atom:updated>2020-08-31T23:41:55.443Z</atom:updated>
            <content:encoded><![CDATA[<h3>Computing Asset Utilization in Real Time using Machine Learning — Part 1</h3><h4>Authored By Malini Pathakota &amp; Pradeep Dunna</h4><h3>Introduction</h3><p>A supply chain is a network connecting every stage of the complex process of making, selling, and distributing commercial goods. There is a massive amount of unutilized data stored within this network and increased visibility into even just one section of this system would provide an organization with invaluable information that would positively affect decision making and significantly drive profit. The company Cloudleaf uses IoT sensors and AI/ML analytics to create a ‘Sensor Fabric,’ a location tracking and condition monitoring system that provides complete visibility into a supply chain, allowing organizations to utilize this massive volume of data to harness actionable insights and optimize operations at all levels. It provides an aggregated perspective of the billions of events that occur as assets travel across a supply chain and supports proactive decision making by diagnosing problems in real time, ultimately eliminating loss and creating profit.</p><p>One aspect of a supply chain that IoT data and analytics can optimize is in determining asset utilization. Asset utilization is a measure of how efficient an organization is at managing and operating its assets. A low asset utilization indicates improper and inefficient usage of equipment, which results in a loss in revenue due to the leasing or maintenance costs of said equipment. Thus, in order to increase profit and reduce loss, a company should always strive to maximize its asset utilization. By attaching IoT accelerometer sensors to assets, organizations can continuously collect data about the conditions and usage of their assets and calculate their asset utilization.</p><p>The purpose of this project is to determine the utilization of an asset based on its x, y, and z historical and streaming accelerometer data.</p><p><strong>Part 1</strong> describes the ‘batch processing’ phase of the project. This is where a large volume of historical accelerometer data is processed all at once in order to create a set of training data to be used for stream processing.</p><p><strong>Part 2</strong> describes the ‘stream processing’ phase. In this phase, continuous streams of real time accelerometer data are processed instantaneously and classified as ‘utilized’ or ‘not utilized.’</p><p><strong>Part 3</strong> describes the final phase of the project, the integration of the previously developed machine learning model with a Spark Streaming pipeline where asset utilization is calculated using dstreams.</p><h3>Part 1: Batch Processing</h3><h3>Data Retrieval and Transformation</h3><p>We are using accelerometer data that was collected for a specific tenant over a period of four months to create our training set. The data is first retrieved and transformed into a format usable for our analysis. This is done by dropping unneeded columns, converting the time values into a datetime format, and splitting the directional data into separate components. Then, the absolute values of the x, y, and z components of the accelerometer data are added together to create a xyz total sum value that is used to detect movement in any direction. Summing the directional values reduces the high dimensionality of our data and simplifies the clustering process without reducing its accuracy.</p><pre>data = full_data.drop(columns=[&#39;stream_id&#39;, &#39;shard_date&#39;])data[&#39;time&#39;] = pd.to_datetime(data[&#39;time&#39;], utc=True)<br>data[&#39;property_value&#39;] = data[&#39;property_value&#39;].str.strip(&#39;[]&#39;)<br>data[[&#39;x&#39;, &#39;y&#39;, &#39;z&#39;]] = data.property_value.str.split(&#39;, &#39;, expand=True)<br>data[&#39;x&#39;] = data[&#39;x&#39;].astype(float)<br>data[&#39;y&#39;] = data[&#39;y&#39;].astype(float)<br>data[&#39;z&#39;] = data[&#39;z&#39;].astype(float)<br>data[&#39;xyz&#39;] = abs(data[&#39;x&#39;]) + abs(data[&#39;y&#39;]) + abs(data[&#39;z&#39;])</pre><pre>assets_df = data.groupby([&#39;asset_external_id&#39;], sort=False).apply(lambda x: x.sort_values([&#39;time&#39;], ascending=True)).reset_index(drop=True)<br>asset = assets_df.loc[assets_df[&#39;asset_external_id&#39;] == &#39;HME 5517&#39;]<br>asset = asset.reset_index(drop=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Di7QRUx-e9gLsZs8.png" /><figcaption>Dataframe after retrieval and transformation</figcaption></figure><h3>PELT Changepoint Algorithm</h3><p>Now we have to partition our data using changepoints, which are points that indicate abrupt changes in the mean or variance of the data. Then, these partitions can be clustered and appropriately labeled as ‘utilized’ or ‘not utilized.’</p><p>Because we have a large volume of complex time series data to analyze, running a changepoint detection algorithm directly on the data can take an extensive amount of time. In order to speed up the changepoint detection process, we use Cython, which allows Python code to be compiled into extremely fast C code, thus potentially speeding up the process of finding changepoints by a factor of one hundred.</p><p>The changepoints are detected using a Cython version of the PELT or ‘Pruned Exact Linear Time’ algorithm. This algorithm finds changepoints by creating a list of ‘good’ index values that could potentially be changepoints and using a pruning rule to narrow down the list to only the most significant index values. It does so in nearly linear time.</p><pre>%%cython<br>cdef class Pelt:<br>  cdef:<br>    object model<br>    np_float_t[:] form<br> <br>  def __init__(self, object model):<br>    self.model = model<br> <br>  cpdef object fit(self, np.ndarray[np_float_t, ndim=1] form):<br>    self.form = form<br>    self.model.fit(form)<br>    return self<br> <br>  cpdef list predict(self, float val):<br>    cdef:<br>      int i, count, cur_val, prev_tau, best_prev_ind, prev_size, <br>      curr_ind, curr_best<br>      list prev_vals, cps<br>      np_int_t[:] prev_cps      <br>      np_float_t[:] best_cost, prev_cost<br> <br>    count = self.form.shape[0]<br>    best_cost = np.empty(n+1, dtype=np.float64)<br>    best_cost[0] = -val<br> <br>    prev_cps = np.zeros(n+1, dtype=np.int64)<br>    prev_vals = [0, 2]<br> <br>    for cur_val in range(4, count+1):<br>      prev_cost = np.empty(len(prev_vals), dtype=np.float64)<br>      for i, prev_tau in enumerate(prev_vals):<br>        prev_cost[i] = best_cost[prev_tau] +     <br>        self.model.error(prev_tau, cur_val) + val<br> <br>      best_prev_ind = np.argmin(prev_cost)<br>      best_cost[cur_val] = prev_cost[best_prev_ind]<br>      prev_cps[cur_val] = prev_vals[best_prev_ind]<br>      curr_best = prev_cost[best_prev_ind]<br> <br>      prev_size = 0 <br>      for i in range(0, len(prev_vals)):<br>        if prev_cost[i] &lt; curr_best + val:<br>          prev_vals[prev_size] = prev_vals[i]<br>          prev_size += 1<br>      del prev_vals[prev_size:(len(prev_vals)-prev_size)]<br> <br>      prev_vals.append(cur_val — 1)<br> <br>    cps = []<br>    curr_ind = prev_cps[count]<br>    while curr_ind != 0:<br>      cps.append(curr_ind-1)<br>      curr_ind = prev_cps[curr_ind]<br>   cps = sorted(cps)<br>   return cps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Kf9knW9ooboWbKIf" /><figcaption>Accelerometer data with changepoints indicated</figcaption></figure><p>Now, using the array of changepoint indices we found using the PELT algorithm, we partition our time series data and create a large matrix containing all the created partitions. Because there’s no predictable pattern for where the changepoints are located, each of these partitions have drastically different lengths and most clustering algorithms would fail to create cohesive groupings on data of this format. To solve this problem, we partition the range of our accelerometer data into 24 uniform sections and calculate the frequencies of each accelerometer point falling within those specific ranges. This converts our partitions of varying lengths into frequency matrices all of length twenty-four, which then allows us to use any clustering algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RuOVit8qc_Fsww11.png" /><figcaption>Dataframe of normalized frequency matrices</figcaption></figure><h3>SparkMLib K-Means Clustering</h3><p>Now that we have data of uniform length, we can perform clustering and determine labels. We use the unsupervised learning algorithm, K-Means, to cluster our data. This algorithm works by randomly initializing an inputted amount of points called the cluster centroids and then iteratively assigning the partitions to one of the centroids. At each iteration, it moves the centroids to the average of the partitions in a cluster, thus slowly grouping all similar data together. This process is repeated until there is no change in the centroids and clusters formed.</p><p>By comparing the silhouette scores of the groupings with varying amounts of clusters, we found the optimal number of clusters to be fifteen. We then perform K-Means clustering with fifteen clusters and get the list of cluster labels.</p><pre>from pyspark.ml.clustering import KMeans<br>from pyspark.ml.evaluation import ClusteringEvaluator</pre><pre>kmeans = KMeans(k=15, seed=1)<br>model = kmeans.fit(training_df.select(‘features’))<br>kmeans_df = model.transform(training_df)<br>labels = kmeans_df.select(“prediction”).rdd.flatMap(lambda x: x).collect()</pre><p>After clustering using K-Means, we attach each of the labels to the appropriate partitions. We then convert each of the numerical labels into a categorical label of ‘utilized’ or ‘not utilized.’ We also indicate the starting and ending changepoints as well as starting and ending times for each of the partitions. This extra data makes it easier for us to later determine what percentage of time an asset is actually being utilized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nEb_OZep_iLiW36W.png" /><figcaption>Final dataframe with cluster labels</figcaption></figure><p>We also save the centroids of each of the fifteen clusters to use later for classifying the new streaming data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/0*VtJqQ8WiMXuUdCrM.png" /><figcaption>Centroid of the first cluster</figcaption></figure><p>We can now plot the accelerometer data with changepoints and information about which clusters they fall into. The grey and orange colored clusters clearly correspond to times where the asset is being ‘utilized’ while the pink and the other colored clusters correspond to ‘not utilized.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N1Bz7un8OHDvlfAI.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5uD1Lr1FHB38zp_p.png" /><figcaption>Accelerometer data with color coded clusters</figcaption></figure><p>Through batch processing and identification of the ‘utilized’ and ‘not utilized’ partitions of our historical accelerometer data, we are able to determine the overall percent of utilization for each time shift of all the assets. We break down a day into three uniform sections of eight hours in order to determine the time shifts. A total percentage of utilization is then calculated and reported. This data can be used to determine which assets have a large amount of dwell time or are being improperly utilized and changes or decisions can be made to use the assets more effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K4vZjmhl60BdCu_K.png" /><figcaption>Overall percent utilization for all the assets</figcaption></figure><p>Now that we have a set of labeled training data, we can build a streaming machine learning model to classify accelerometer data as ‘utilized’ or ‘not utilized’ in real time.</p><p>This can be found in <strong>Part 2</strong>: <a href="https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-2-c9928902ebc8">https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-2-c9928902ebc8</a>.</p><h3>References</h3><p>Akinshin, A. (2019, October 7). Implementation of efficient algorithm for changepoint detection: ED-PELT: Andrey Akinshin. Retrieved August 25, 2020, from <a href="https://aakinshin.net/posts/edpelt/">https://aakinshin.net/posts/edpelt/</a></p><p>R. Killick, P. Fearnhead &amp; I. A. Eckley (2012) Optimal Detection of Changepoints With a Linear Computational Cost, Journal of the American Statistical Association, 107:500, 1590–1598, DOI: <a href="https://doi.org/10.1080/01621459.2012.737745">10.1080/01621459.2012.737745</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=791e901ece16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudleaf/computing-asset-utilization-in-real-time-using-machine-learning-part-1-791e901ece16">Computing Asset Utilization in Real Time using Machine Learning — Part 1</a> was originally published in <a href="https://medium.com/cloudleaf">Cloudleaf</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>