[ 
https://issues.apache.org/jira/browse/MADLIB-1181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16363219#comment-16363219
 ] 

Frank McQuillan commented on MADLIB-1181:
-----------------------------------------

Testing classification seems OK:
{code}
DROP TABLE IF EXISTS knn_train_data_class;
CREATE TABLE knn_train_data_class (
                    id integer, 
                    data integer[], 
                    label integer  -- Integer label means for classification
                    );
INSERT INTO knn_train_data_class VALUES
(1, '{4,0}', 1),
(2, '{5,0}', 2),
(3, '{6,0}', 2),
(4, '{7,0}', 2);


DROP TABLE IF EXISTS knn_test_data;
CREATE TABLE knn_test_data (
                    id integer,
                    data integer[]
                    );
INSERT INTO knn_test_data VALUES
(1, '{3,0}');

DROP TABLE IF EXISTS knn_result_classification;
SELECT * FROM madlib.knn(
                'knn_train_data_class',      -- Table of training data
                'data',                -- Col name of training data
                'id',                  -- Col name of id in train data
                'label',               -- Training labels
                'knn_test_data',       -- Table of test data
                'data',                -- Col name of test data
                'id',                  -- Col name of id in test data
                'knn_result_classification',  -- Output table
                 4,                    -- Number of nearest neighbors
                 True,                 -- True to list nearest-neighbors by id
                 'madlib.dist_norm2',                 -- Distance function
                 True                 -- For weighted average
                );
SELECT * FROM knn_result_classification ORDER BY id;
{code}
produces
{code}
 id | data  | prediction | k_nearest_neighbours 
----+-------+------------+----------------------
  1 | {3,0} |          2 | {1,2,3,4}
(1 row)
{code}

> Add an option for weighted average in k-NN
> ------------------------------------------
>
>                 Key: MADLIB-1181
>                 URL: https://issues.apache.org/jira/browse/MADLIB-1181
>             Project: Apache MADlib
>          Issue Type: Improvement
>          Components: k-NN
>            Reporter: Frank McQuillan
>            Assignee: Himanshu Pandey
>            Priority: Minor
>             Fix For: v1.14
>
>
> Follow on from 
> https://issues.apache.org/jira/browse/MADLIB-1059
> (please see this JIRA for additional comments)
> MADlib does a simple average of the k-nearest neighbors to come up with the
> final value for classification and regression. Doing a weighted average 
> instead
> might be a desirable functionality. The weighting for the average can be 
> based on the
> distance of the k-nearest neighbors.
> We can probably provide an optional parameter to let users choose how the 
> final
> score has to be computed (avg or weighted avg).
> This JIRA applies to classification and regression.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to