<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>CourboSpark: Decision Tree for Time-series on Spark</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Christophe Salperwyck</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Simon Maby</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>ome Cubille</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Matthieu Lagacherie</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>EDF R</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>avenue du General de Gaulle</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Clamart</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>France</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>OCTO Technology</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>avenue des Champs-Elysees</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Paris</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>France</string-name>
        </contrib>
      </contrib-group>
      <pub-date>
        <year>2015</year>
      </pub-date>
      <abstract>
        <p>With the deployment of smart meters across many countries, data are being collected at a large scale and volume. These data are collected for billing purposes but also to get analytical insights. Our main goal here is to build an understandable model able to explain the electric consumption patterns regarding several features. We chose to use decision tree models as they are easily comprehensible and have already been parallelized with success. In our industrial context, we often have to work on electrical time-series where the target to predict is neither a label (classi cation) nor a numerical value (regression) but a time-series representing a load curve. Therefore we use a di erent split criterion to separate time-series: the inertia. We also need a dedicated method for categorical features since the standard implementation would not work for time-series. This method is based on a hierarchical clustering in order to have a good trade-o between the computational complexity and the exploration of the possible bi-partition splits. We demonstrate the performance of our implementation on datasets with di erent sizes (up to a terabyte).</p>
      </abstract>
      <kwd-group>
        <kwd>CourboTree</kwd>
        <kwd>Hadoop</kwd>
        <kwd>Spark</kwd>
        <kwd>Decision Tree</kwd>
        <kwd>Parallelization</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>With the deployment of smart meters across many countries, data are being
collected at a large scale and volume. Electric meters measure and transmit
electric power consumption from every individual household and enterprise at a
rate of a measurement from every 24 hours down to 10 minutes to a centralized
information system. In France, EDF provides electricity to more than 35
million customers leading to a massive amount of data to process. These data are
collected for billing purposes but also to get analytical insights. Our main goal
in this paper is to build an understandable model able to explain the electrical
consumption patterns regarding several features such as localization or type of
contract. We chose to use decision tree models as they are easily comprehensible
and have already been parallelized with success in the Hadoop ecosystem.</p>
      <p>CourboSpark is part of the X-Data project: http://www.xdata.fr/
Copyright c 2015 for this paper by its authors. Copying permitted for private and academic
purposes.</p>
      <p>
        Decision trees are well known methods in machine learning which are mainly
used for classi cation and regression tasks. In our industrial context, we often
have to work on electrical time-series where the target to predict is neither a label
(classi cation) nor a numerical value (regression) but a time-series representing
a load curve. Many versions of decision trees were proposed on top of Hadoop.
The Spark [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] implementation seems to be the most suitable for our use-case.
Therefore we extended the current Spark/MLlib [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] implementation of decision
trees so that it can deal with a time-series as a target.
      </p>
      <p>We rst present previous work on parallel decision trees and explain why
we choose to reuse the MLlib implementation. Then we describe the time-series
regression problem. In section 4, the inertia criterion used to separate time-series
is presented. Section 5 will focus on the algorithm adaptation for categorical
features with a method based on a hierarchical clustering. Finally, we demonstrate
the performance of our implementation on datasets with di erent sizes (up to a
terabyte).
2</p>
    </sec>
    <sec id="sec-2">
      <title>Previous work on parallel decision trees</title>
      <p>
        Our goal is to port our in-house software, CourboTree [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ], into a distributed
system so that more data can be processed. Our CourboTree software build
decision tree on time-series based on the inertia criterion.
      </p>
      <p>Many implementations of parallel decision trees have been proposed. In this
paper we focus on implementations that can run on top of Hadoop. Hadoop
clusters o er a very good trade-o between computing power/storage and price.
Hadoop is based on horizontal scaling: the computing power/storage is
quasilinear with the number of nodes in the cluster. To have more power, more nodes
have to be added into the cluster. Table 1 presents di erent implementations
of decision trees on Hadoop. We used the following criteria to compare these
implementations:
{ partitioning: horizontal means the algorithm will parallelize computations
on the lines, vertical on the columns of the dataset;
{ engine: the execution engine that will run the parallel algorithm. These
engines can also optimize the execution graph of the algorithm (as for Spark);
{ target type: categorical for classi cation, numerical for regression (can be
both)
{ ensemble: ability to build an ensemble of trees (random forest, bagging of
random trees...)
{ pruning: does the algorithm prune the tree to avoid over- tting?
{ open-source: is the source code available so that we can easily reuse it?</p>
      <p>As we aimed to reuse an open-source implementation and our datasets mainly
grow in an horizontal way, we choose to adapt the MLlib implementation.
Moreover it uses the Spark engine which is faster than the original Map/Reduce engine
in Hadoop.</p>
      <p>
        MLlib [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]
MR C4.5 [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
PLANET [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]
SAMOA [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]
The problem is the same as the one stated in CourboTree [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ]: explain load
curves pattern using explanatory features. It can be seen as time-series
regression. For this problem, we de ne our dataset as follows:
{ 1; :::; n: the examples of the dataset;
{ w1; :::; wn: the weights of the examples;
{ X1; :::; Xj ; :::; Xp: the p explanatory features where xij is the value for the
example i for Xj , these features can be either numerical or categorical;
{ Y1; :::; Yk; :::; Yq: the q numerical variables de ning the time-series where yik
is the value for the example i for Yk. This time-series is the target of the
regression.
      </p>
      <p>Therefore an example i is described as the following tuple: wi; xi1:::xip; yi1:::yiq.
There can be missing values for either the explanatory features or the time-series.</p>
      <p>As in CourboTree, the model used to explain the load curves is a tree:
{ l: a node/leaf of the tree,
{ gl: the center of gravity of the examples in l. Its coordinates gl1; : : : ; glq are
the weighted mean of the examples in the node/leaf l for the q points of the
time-series Y .
4</p>
    </sec>
    <sec id="sec-3">
      <title>Split criteria: inertia</title>
      <p>Decision trees used in classi cation aim to lower the impurity in the leaves and
use a criterion such as the entropy gain or the Gini coe cient. For regression
task, variance reduction is often used. As we deal with time-series we want to
lower the variance between the time-series within a leaf/node. In this paper we
use the euclidean distance to compute the variance. Other distances could be
used.</p>
      <p>Given a node t, its intra inertia is de ned as:</p>
      <p>Iw(l) =</p>
      <p>X wi
k=1;:::;q
(yik
glk)2</p>
      <p>This criteria can be used in the same way as the criterion used in classi cation
and regression trees. The best split to divide a leaf l into two leaves lL and lR is
the one minimizing the intra-inertia of these two new leaves:</p>
      <p>argmin Iw(lL) + Iw(lR)</p>
      <p>Computing this intra-inertia is expensive but we can use the Konig-Huyghens
theorem which states that the global inertia is the sum of the intra-inertia Iw
and inter-inertia IB:</p>
      <p>I = Iw + IB</p>
      <p>
        Therefore we can maximize the inter-inertia instead of minimizing the
intrainertia (which is also known as the \Ward's method" [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] in statistics). This
corresponds to nd the centers of gravity of the two new leaves which are the
furthest possible (relatively to their center weights). The computation of the
inter-inertia is much more e ective. For each potential split points we do not
need to recompute the intra-inertia on all the points to the two new centers of
gravity, but just the distance between the two new centers of gravity.
      </p>
      <p>For times-series this means to maximize the distance between the average
curves in the two leaves (lL; lR) having weights (wL; wR):
argmax
wL:wR
wL + wR i21:::q</p>
      <p>X (gLi
gRi)2</p>
      <p>As computing the inter-inertia criterion is more e ective we have only used
this criterion in CourboSpark. Both criteria are sums that can be parallelized.
Therefore the computation can be easily spread across the nodes in the cluster
in order to take advantage of its computational power.
5</p>
    </sec>
    <sec id="sec-4">
      <title>Categorical variables: hierarchical clustering</title>
      <p>For numerical feature, the MLlib algorithm has a parameter to specify the
number of \bins" that will be tested as split points. These bins correspond to
quantiles computed on a random sample of the whole dataset. For the categorical
features the next section explains how the current implementation works and
how it was adapted for time-series.</p>
      <p>Building a binary decision tree with categorical feature requires to evaluate
all the bi-partition/split of the modalities. The bi-partition with the lowest value
of the criteria is the one chosen to split the node into two leaves. This evaluation
can be costly as for m modalities there are (2m 1 1) possible bi-partitions.
With m up to 30, the computation of all these partitions can be computed in
a reasonable time (less than a minute on recent hardware). Our datasets have
categorical features up to 100 modalities (the number of French departments
for example). An exhaustive test of all the bi-partitions would take too much
time as the number of bi-partitions to test is exponential with the number of
modalities.</p>
      <p>
        There are many ways to deal with categorical features in a binary decision
tree in order to limit the number of potential split points. The simplest one is
to only test the bi-partitions having one modality versus all the other
modalities. A more sophisticated approach is based on ordering the modalities. For
classi cation, modalities are ordered relatively to their entropy or Gini and for
regression relatively to their means. This option is the one chosen in the
MLlib decision tree implementation. As we deal with time-series, we can not order
modalities. We can illustrate that with 4 stable curves: (a) at 0.6, (b) at 0.4,
(c) at -0.45 and (d) at -0.55. Their average curve is at 0.0. If we order them by
their euclidean distance to the average curve we have: (b,c,a,d), which gives 3
possible bi-partitions: ((b,(c,a,d)), ((b,c)(a,d)) and ((b,c,a)(d)). Looking at this
example, the best bi-partitions is ((a,b)(c,d)) but was not evaluated using this
heuristic. Therefore we chose to use the hierarchical clustering [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] to nd better
splits without doing an exhaustive test of all the bi-partitions.
      </p>
      <p>Hierarchical clustering is a bottom-up heuristic. The rst step is to aggregate
the curve of the two modalities that maximize the loss of inertia. Using the
inter-inertia criterion, this aggregation corresponds to the computation of the
new average curve based on the weighting sum of the average curve of the two
modalities. These two aggregated modalities are seen as one cluster and then we
can continue to merge the modalities/cluster in the same way. Figure 1 shows
an example of hierarchical clustering with 7 modalities. The algorithm stops
once there are only two clusters. In order to optimize the nal bi-partition we
perform a post-optimization by trying to move all the modalities from one cluster
to the other one. Modalities are moved one by one, until no loss of inertia can
be achieved. The complexity of this heuristic is much lower: O(m3).
This section presents our experiments on a generated, but realistic, dataset with
di erent sizes.
Dataset: In order to control the experiments we have developed a generator.
This generator takes as parameters: the depth of the tree, number of points in
the time-series, number of features, number of modalities for categorical features.
We con gured the generator to have a tree of depth 4, with 10 numerical and 10
categorical features (50 modalities each). Each time-series has 144 points (step
of 10 minutes for one day). We generated from 10 to 1,000 millions time-series.
Con guration: The experiments were run on a cluster of 10 machines. Each
machine has 32 cores, 48 GB of RAM and 14 SATA spinning disks. Spark was
con gured to run with 9 executors with 20 GB and 8 cores each.
Results: The results of the the experimentation are presented in Figure 2. As we
can see the Spark MLlib implementation of decision tree scales almost linearly
with the dataset size.</p>
      <p>400
s350
te300
u
in250
m200
in150
e100
im50
T
0
0
200
400
600
800
1000
1200</p>
      <p>1400</p>
      <p>Data in GB</p>
      <p>More experiments were conducted with similar results. We tested datasets
with up to 100 features, and also up to 500 modalities for categorical features.
7</p>
    </sec>
    <sec id="sec-5">
      <title>Future works</title>
      <p>We plan to extend our implementation so that it can deal with \cyclic features"
as day of the week, month of the year... which are common in our datasets.
This case is similar to numerical feature but gives two times more possible split
points.</p>
      <p>The MLlib library only build trees which are balanced (each leaf is at the
same depth). The current CourboTree implementation rst grows the part of the
tree that gives the greatest loss of inertia and therefore can produce unbalanced
trees. As we would like to have the lowest global inertia for a given number of
leaves, we would either need to drive the tree construction to expand just a part
of the tree or to do post-pruning to remove parts of the tree. A next step could
be to use this pruning to control over- tting.</p>
      <p>More generally we plan to do more extensive tests to study how the Spark
con guration (number of executors, memory...) impact performance depending
on the datasets properties (number of features, modalities/bins...).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Stephan</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cogordan</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <string-name>
            <surname>Courbotree : Application Des Arbres De Regression Multivaries Pour La Classi cation De Courbes. XXXVIemes Journees de statistique</surname>
          </string-name>
          <article-title>a Montpellier</article-title>
          . http://www.agro-montpellier.fr/sfds/CD/textes/stephan1.pdf
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Stephan</surname>
          </string-name>
          , V.: CourboTree : Une Methode de Classi cation de Courbes Appliquee au Load Pro ling pp.
          <volume>129</volume>
          {
          <fpage>138</fpage>
          .
          <string-name>
            <surname>Revue</surname>
            <given-names>MODULAB</given-names>
          </string-name>
          33 (
          <year>2005</year>
          ). http://www.modulad. fr/archives/numero-33/stephan-33/stephan-33.pdf
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Zaharia</surname>
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chowdhury</surname>
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Franklin</surname>
            <given-names>M.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shenker</surname>
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stoica</surname>
            <given-names>I.</given-names>
          </string-name>
          :
          <article-title>Spark: Cluster Computing with Working Sets</article-title>
          ,
          <source>Proceedings of the 2nd USENIX conference on Hot topics in cloud computing</source>
          (
          <year>2010</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Amde</surname>
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Das</surname>
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sparks</surname>
            <given-names>E.</given-names>
          </string-name>
          <string-name>
            <surname>Talwalkar</surname>
          </string-name>
          <article-title>A.: Scalable Distributed Decision Trees in Spark MLLib</article-title>
          ,
          <source>Spark Summit</source>
          <year>2014</year>
          . http://spark-summit.org/wpcontent/uploads/2014/07/Scalable-Distributed-
          <article-title>Decision-Trees-in-</article-title>
          <string-name>
            <surname>SparkMade-Das-</surname>
          </string-name>
          Sparks-Talwalkar.pdf
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Dai</surname>
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wei</surname>
            <given-names>J</given-names>
          </string-name>
          .:
          <article-title>A MapReduce Implementation of C4.5 Decision Tree Algorithm</article-title>
          .
          <source>International Journal of Database Theory and Application</source>
          . Vol.
          <volume>7</volume>
          , No.
          <issue>1</issue>
          , pp.
          <volume>49</volume>
          {
          <issue>60</issue>
          (
          <year>2014</year>
          ) http://www.chinacloud.cn/upload/2014-03/14031920373451.pdf
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Panda</surname>
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Herbach</surname>
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Basu</surname>
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bayardo</surname>
            <given-names>R.:</given-names>
          </string-name>
          <article-title>PLANET: massively parallel learning of tree ensembles with MapReduce</article-title>
          .
          <source>Proceedings of the VLDB Endowment</source>
          , pp.
          <volume>1426</volume>
          {
          <issue>143</issue>
          (
          <year>2009</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7. De Francisci Morales G. ,
          <article-title>Bifet A.: SAMOA: Scalable Advanced Massive Online Analysis</article-title>
          .
          <source>Journal of Machine Learning Research</source>
          , Volume
          <volume>16</volume>
          , pp.
          <volume>149</volume>
          {
          <issue>153</issue>
          (
          <year>2015</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Ward</surname>
            ,
            <given-names>J. H.</given-names>
          </string-name>
          :
          <article-title>Hierarchical Grouping to Optimize an Objective Function</article-title>
          .
          <source>Journal of the American Statistical Association</source>
          <volume>58</volume>
          , no. 301 pp.
          <volume>236</volume>
          {
          <issue>244</issue>
          (
          <year>1963</year>
          ).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>