Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Introduction

This sample demonstrates how a model is generated out of a data set using the k-means algorithm. The sample uses a data set to generate a model, which is divided into two sets for training and testing.

Prerequisites

Follow the steps below to set up the prerequisites before you start.

  1. Download WSO2 Machine Learner, and start the server. For information on setting up and running WSO2 ML, see Getting Started.
  2. Download and install jq (CLI JSON processor). For instructions, see jq Documentation.
  3. If you are using Mac OS X, download and install GNU stream editor (sed). For instructions, see GNU sed Documentation.

Executing the sample

Follow the steps below to execute the sample.

  1. Navigate to <ML_HOME>/samples/default/k-means/ directory using the CLI.

  2. Execute the following command to execute the sample: ./model-generation.sh

Analyzing the output

Once the sample is successfully executed, you can view the summary and the prediction of the model  as described below.

By  default , the sample generates the model in the <ML_HOME>/models/    directory of your machine. For example, the generated file is in the following format denoting the date and time when it was generated:   wso2-ml-kmeans-sample-analysis.Model.2015-09-03_12-02-05

Viewing the model 

You can view the summary of the built model using the ML UI as follows.

  1. Log in to the ML UI from your Web browser using admin/admin credentials and the following URL: https://<ML_HOST>:<ML_PORT>/ml

  2. Click the Projects button as shown below.
    view Projects

  3. Click Models to view the models of the wso2-ml-kmeans-sample-analysis analysis that was created when the sample was executed.
  4. Click View on the model as shown below.

    The summary of the model is displayed as shown below.

Viewing the model prediction

The sample executes the generated model on the <ML_HOME>/samples/rest-api/k-means/prediction-test data set, and it prints the following as the prediction result In the CLI logs.

<ClusteringModel functionName="clustering" modelClass="centerBased" modelName="k-means" numberOfClusters="3">
        <MiningSchema>
            <MiningField name="field_0" usageType="active"/>
            <MiningField name="field_1" usageType="active"/>
            <MiningField name="field_2" usageType="active"/>
            <MiningField name="field_3" usageType="active"/>
            <MiningField name="field_4" usageType="active"/>
            <MiningField name="field_5" usageType="active"/>
            <MiningField name="field_6" usageType="active"/>
        </MiningSchema>
        <ComparisonMeasure kind="distance">
            <squaredEuclidean/>
        </ComparisonMeasure>
        <ClusteringField compareFunction="absDiff" field="field_0"/>
        <ClusteringField compareFunction="absDiff" field="field_1"/>
        <ClusteringField compareFunction="absDiff" field="field_2"/>
        <ClusteringField compareFunction="absDiff" field="field_3"/>
        <ClusteringField compareFunction="absDiff" field="field_4"/>
        <ClusteringField compareFunction="absDiff" field="field_5"/>
        <ClusteringField compareFunction="absDiff" field="field_6"/>
        <Cluster name="cluster_0">
            <Array n="7" type="real">12.066923076923079 13.316769230769232 0.8539938461538467 5.2377076923076915 2.894953846153847 4.533107692307692 5.071476923076921</Array>
        </Cluster>
        <Cluster name="cluster_1">
            <Array n="7" type="real">14.886000000000003 14.568444444444443 0.880822222222222 5.591266666666665 3.3089333333333326 2.567691111111112 5.207</Array>
        </Cluster>
        <Cluster name="cluster_2">
            <Array n="7" type="real">18.764999999999997 16.321052631578944 0.8843921052631577 6.219394736842104 3.7254999999999994 3.548184210526316 6.062710526315789</Array>
        </Cluster>
    </ClusteringModel>
  • No labels