[
https://issues.apache.org/jira/browse/MADLIB-1181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16363214#comment-16363214
]
Frank McQuillan commented on MADLIB-1181:
-----------------------------------------
Testing regression seems OK:
{code}
DROP TABLE IF EXISTS knn_train_data_reg;
CREATE TABLE knn_train_data_reg (
id integer,
data integer[],
label float -- Float label means for regression
);
INSERT INTO knn_train_data_reg VALUES
(1, '{1,0}', 1.0),
(2, '{12,0}', 2.0);
DROP TABLE IF EXISTS knn_test_data;
CREATE TABLE knn_test_data (
id integer,
data integer[]
);
INSERT INTO knn_test_data VALUES
(1, '{2,0}');
DROP TABLE IF EXISTS knn_result_regression;
SELECT * FROM madlib.knn(
'knn_train_data_reg', -- 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_regression', -- Output table
2, -- 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_regression ORDER BY id;
{code}
produces
{code}
id | data | prediction | k_nearest_neighbours
----+-------+------------------+----------------------
1 | {2,0} | 1.09090909090909 | {1,2}
(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)