<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.classify.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.classify</api:function-name><api:suggest>cts.classify</api:suggest><api:suggest>cts</api:suggest><api:suggest>classify</api:suggest><api:function-link mode="xquery" fullname="cts:classify">/apidoc/8.0/cts:classify.xml</api:function-link><api:function mode="javascript" name="classify" type="builtin" lib="cts" category="Classifier" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.classify"><api:summary>
  Classifies 
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">an array</span>
  of nodes based on training data.  The training data is in the form
  of a classifier specification, which is generated from the output of
   <span class="javascript" xmlns="http://www.w3.org/1999/xhtml"><code>cts.train</code>.</span> Returns labels for
  each of the input documents in the same order as the input document.
</api:summary><api:params><api:param class="javascript" name="dataNodes" type="Array"><api:param-description>
 The array of nodes to be classified.
 </api:param-description><api:param-name>dataNodes</api:param-name><api:param-type>Array</api:param-type></api:param><api:param class="javascript" name="classifier" type="Object"><api:param-description>
 An object containing the classifier specification.  This is typically
 the output of <code xmlns="http://www.w3.org/1999/xhtml">cts.train</code>, either run directly or saved in
 a JSON document in the database.
 </api:param-description><api:param-name>classifier</api:param-name><api:param-type>Object</api:param-type></api:param><api:param name="options" type="(element()|map:map)?" optional="true"><api:param-description>
  <p xmlns="http://www.w3.org/1999/xhtml">An options 
  <span class="javascript">object</span>.  The options for classification 
  are passed automatically from 
  <span class="javascript"><code>cts.train</code></span> to the
  
  <span class="javascript"><code>cts.classifier</code></span>
  specification as part of the classifier 
  <span class="javascript">object</span> so that they are
  consistent with the parameters used in training.  The following 
  
  <span class="javascript">options</span>
  may be separately passed to 
  
  <span class="javascript"><code>cts.classify</code></span>
  .
  These options override the options present in the classifier item-by-item.</p>
   <dl xmlns="http://www.w3.org/1999/xhtml">
   
   
   <dt class="javascript"><p><code>defaultThreshold</code>,
     <code>classThresholds</code></p></dt>
     <dd class="javascript">Definitions of the thresholds to use in
     classification. <code>classThresholds</code> specify per-class values
     (as computed from <code>cts.thresholds</code>). 
     <code>defaultThreshold</code>
     will apply to any classes for which a per-class value is not specified.
     For example:
   <pre xml:space="preserve">
    {
        ...
        defaultThreshold: -1.0,
        classThresholds: {"Example 1": -2.42, "Example 2": 0.41}
        ...
    }
    </pre>
    </dd>
   </dl>
 </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param><api:param class="javascript" name="trainingNodes" type="Array" optional="true"><api:param-description>
 The array of training nodes used to train the classifier.
 Required if the <code xmlns="http://www.w3.org/1999/xhtml">supports</code> form of the classifier is used;
 ignored if the <code xmlns="http://www.w3.org/1999/xhtml">weights</code> form of the classifier is used.
 </api:param-description><api:param-name>trainingNodes</api:param-name><api:param-type>Array</api:param-type></api:param></api:params><api:return class="javascript">Array</api:return><api:usage>

  

  <p class="javascript" xmlns="http://www.w3.org/1999/xhtml"><code>cts.classify</code> classifies 
  an array of nodes using the output from <code>cts.train</code>.
  The <code>dataNodes</code> and <code>classifier</code> parameters 
  are respectively the nodes to
  be classified and the specification output from <code>cts.train</code>.
  <code>cts.classify</code> can use either <code>supports</code> or
  <code>weights</code> forms of the <code>classifier</code> output
  from <code>cts.train</code> (see <a href="#outputformats">Output
  Formats</a>).  If the <code>supports</code> form is used, the training
  nodes must be passed as the 4th parameter.  The <code>options</code>
  parameter is an options object.
  </p>



<p class="javascript" xmlns="http://www.w3.org/1999/xhtml">
The output is an array of label objects of the form:
</p>

  <p xmlns="http://www.w3.org/1999/xhtml">Each label corresponds to the data node in the corresponding
  position in the input sequence. There will be <span class="javascript">an
  object</span> for each class where the document passed the class 
  threshold. The <code>val</code> 
  <span class="javascript">property</span> gives the
  class membership value for the data node in the given class.  Values
  greater than zero indicate likely class membership, values less than
  zero indicate likely non-membership.  Adjusting thresholds can give
  more or less selective classification. Increasing the threshold
  leads to a more selective classification (that is, decreases the
  likelihood of classification in the class). Decreasing the threshold
  gives less selective classification.
  </p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var firsthalf = fn.subsequence(
  xdmp.directory("/shakespeare/plays/", "1"), 1, 19);
var plays1 = firsthalf.clone();
var secondhalf = fn.subsequence(
  xdmp.directory("/shakespeare/plays/", "1"), 20, 37);
var plays2 = secondhalf.clone();
var labels = [];
for (var x of firsthalf) {
  var singleClass = [{"name": xdmp.documentProperties(xdmp.nodeUri(x)).next().value.
                      xpath("//playtype/fn:string()")
                     }];
  labels.push({"classes": singleClass});
}
var classifier = cts.train(plays1.toArray(), labels,
                           {"classifierType": "supports",
                            "useDbConfig": true,
                            "epsilon": 0.00001
                           });
cts.classify(plays2.toArray(), classifier, {}, plays1.toArray());
=&gt;
[
  {
    "classes": [
      { "name": "HISTORY",
        "val": 4.29498338699341
      },
      { "name": "COMEDY",
        "val": 2.83974766731262
      },
      { "name": "TRAGEDY",
        "val": -0.454397678375244
      }
    ]
  },
  {
    "classes": [
      { "name": "HISTORY",
        "val": 3.70210886001587
      },
      { "name": "COMEDY",
        "val": 2.59831714630127
      },
      { "name": "TRAGEDY",
        "val": -0.404506534337997
      }
    ]
  },
  ...
]

</pre></api:example></api:function></api:function-page>