You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by nj...@apache.org on 2017/12/08 19:31:15 UTC
madlib git commit: Doc: Add grouping predict e.g. for lin_reg
Repository: madlib
Updated Branches:
refs/heads/master edc93f529 -> 2658b3343
Doc: Add grouping predict e.g. for lin_reg
Add example for prediction with grouping support in linear the
regression module.
Closes #209
Project: http://git-wip-us.apache.org/repos/asf/madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/madlib/commit/2658b334
Tree: http://git-wip-us.apache.org/repos/asf/madlib/tree/2658b334
Diff: http://git-wip-us.apache.org/repos/asf/madlib/diff/2658b334
Branch: refs/heads/master
Commit: 2658b33434d0e7f7ce248fed64f6ab81111c5329
Parents: edc93f5
Author: Frank McQuillan <fm...@pivotal.io>
Authored: Wed Dec 6 11:04:27 2017 -0800
Committer: Nandish Jayaram <nj...@apache.org>
Committed: Fri Dec 8 11:28:19 2017 -0800
----------------------------------------------------------------------
.../postgres/modules/regress/linear.sql_in | 38 ++++++++++++++++++++
1 file changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/madlib/blob/2658b334/src/ports/postgres/modules/regress/linear.sql_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/regress/linear.sql_in b/src/ports/postgres/modules/regress/linear.sql_in
index e1484db..68c9020 100644
--- a/src/ports/postgres/modules/regress/linear.sql_in
+++ b/src/ports/postgres/modules/regress/linear.sql_in
@@ -356,6 +356,44 @@ Result:
(15 rows)
</pre>
+-# Compare predicted price with actual with grouping.
+It means a different model is used depending on the number of bedrooms.
+<pre class="example">
+\\x OFF
+SELECT houses.*,
+ madlib.linregr_predict( m.coef,
+ ARRAY[1,tax,bath,size]
+ ) as predict,
+ price -
+ madlib.linregr_predict( m.coef,
+ ARRAY[1,tax,bath,size]
+ ) as residual
+FROM houses, houses_linregr_bedroom m
+WHERE houses.bedroom = m.bedroom
+ORDER BY id;
+</pre>
+Result:
+<pre class="result">
+ id | tax | bedroom | bath | price | size | lot | predict | residual
+----+------+---------+------+--------+------+-------+------------------+-------------------
+ 1 | 590 | 2 | 1 | 50000 | 770 | 22100 | 43223.5393423978 | 6776.46065760222
+ 2 | 1050 | 3 | 2 | 85000 | 1410 | 12000 | 111527.609949684 | -26527.609949684
+ 3 | 20 | 3 | 1 | 22500 | 1060 | 3500 | 20187.9052986341 | 2312.09470136587
+ 4 | 870 | 2 | 2 | 90000 | 1300 | 17500 | 99354.9203362612 | -9354.92033626116
+ 5 | 1320 | 3 | 2 | 133000 | 1500 | 30000 | 124508.080626412 | 8491.91937358756
+ 6 | 1350 | 2 | 1 | 90500 | 820 | 25700 | 96640.8258367579 | -6140.8258367579
+ 7 | 2790 | 3 | 2.5 | 260000 | 2130 | 25000 | 224650.799707327 | 35349.2002926733
+ 8 | 680 | 2 | 1 | 142500 | 1170 | 22000 | 138458.174652714 | 4041.82534728572
+ 9 | 1840 | 3 | 2 | 160000 | 1500 | 19000 | 138650.335313722 | 21349.6646862777
+ 10 | 3680 | 4 | 2 | 240000 | 2790 | 20000 | 240000 | 0
+ 11 | 1660 | 3 | 1 | 87000 | 1030 | 17500 | 62911.2752186594 | 24088.7247813406
+ 12 | 1620 | 3 | 2 | 118600 | 1250 | 20000 | 117007.693446414 | 1592.30655358579
+ 13 | 3100 | 3 | 2 | 140000 | 1760 | 38000 | 189203.861766403 | -49203.8617664034
+ 14 | 2070 | 2 | 3 | 148000 | 1550 | 14000 | 143322.539831869 | 4677.46016813093
+ 15 | 650 | 3 | 1.5 | 65000 | 1450 | 12000 | 82452.4386727394 | -17452.4386727394
+(15 rows)
+</pre>
+
@anchor notes
@par Note