Options

KNN Classification

ShubhaShubha Member Posts: 139 Maven
edited November 2019 in Help
Hi,

I run the below code given in the sample XML files (04_NearestNeighbours.XML) for the KNN Classification.
<operator name="Root" class="Process" expanded="yes">
    <description text="This learner uses a simple nearest neighbors classifier. This instance based classifiers just uses the other instances closest to the instance at hand in order to determine a prediction."/>
    <operator name="ArffExampleSource" class="ArffExampleSource">
        <parameter key="data_file" value="../data/iris.arff"/>
        <parameter key="label_attribute" value="class"/>
    </operator>
    <operator name="NearestNeighbors" class="NearestNeighbors">
        <parameter key="keep_example_set" value="true"/>
        <parameter key="k" value="3"/>
    </operator>
</operator>
But the result I get is a blank KNNClassification model with the contents,
KNNClassification

KNNClassification (prediction model for label class)
and an id attribute added into the Exampleset.

Why are the results not displayed?

Thanks,
Shubha

Answers

  • Options
    keithkeith Member Posts: 157 Maven
    You created a model, but did not apply it to the dataset.  Applying the model is what generates predictions.  You need to add a ModelApplier node after creating the model.  ry this instead:

    <operator name="Root" class="Process" expanded="yes">
        <description text="This learner uses a simple nearest neighbors classifier. This instance based classifiers just uses the other instances closest to the instance at hand in order to determine a prediction."/>
        <operator name="ArffExampleSource" class="ArffExampleSource">
            <parameter key="data_file" value="../data/iris.arff"/>
            <parameter key="label_attribute" value="class"/>
        </operator>
        <operator name="NearestNeighbors" class="NearestNeighbors">
            <parameter key="keep_example_set" value="true"/>
            <parameter key="k" value="3"/>
        </operator>
        <operator name="ModelApplier" class="ModelApplier">
            <list key="application_parameters">
            </list>
        </operator>
    </operator>
  • Options
    ShubhaShubha Member Posts: 139 Maven
    Thank you very much Keith... It helped.

    I have one single question... Dont we get any 'values' like estimate values or any any distance values in the model? Because i just see the below in the model.
    KNNClassification
    KNNClassification (prediction model for label class)
    Thanks,Shubha
  • Options
    keithkeith Member Posts: 157 Maven
    KNN is a "lazy" learner.  It doesn't compute anything when it builds the model.  It just saves the examples as reference points so that the nearest neighbors can be computed later when applied to other data.  There are no distance computations, and the coordinates of the examples in the multidimensional space are just the attribute values of the examples.

    In other words, there really isn't anything to show when the model is created, since all the heavy lifting is done at prediction time.

Sign In or Register to comment.