From 92becac280e9105810cb5789e983710c91ab9565 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Mon, 8 Jan 2018 16:30:03 -0500 Subject: [PATCH] syntax fixes / function name fix --- doc/02_moran.md | 33 ++++++++++++++++++++++----------- doc/04_markov.md | 8 ++++++-- doc/11_kmeans.md | 36 ++++++++++++++++++++++-------------- doc/12_segmentation.md | 8 ++++---- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/doc/02_moran.md b/doc/02_moran.md index 57cf9ba..683bd2f 100644 --- a/doc/02_moran.md +++ b/doc/02_moran.md @@ -37,8 +37,10 @@ SELECT aoi.quads, aoi.significance, c.num_cyclists_per_total_population -FROM cdb_crankshaft.CDB_AreasOfInterestLocal('SELECT * FROM commute_data' - 'num_cyclists_per_total_population') As aoi +FROM + cdb_crankshaft.CDB_AreasOfInterestLocal( + 'SELECT * FROM commute_data' + 'num_cyclists_per_total_population') As aoi JOIN commute_data As c ON c.cartodb_id = aoi.rowid; ``` @@ -71,8 +73,12 @@ A table with the following columns. #### Examples ```sql -SELECT * -FROM cdb_crankshaft.CDB_AreasOfInterestGlobal('SELECT * FROM commute_data', 'num_cyclists_per_total_population') +SELECT + * +FROM + cdb_crankshaft.CDB_AreasOfInterestGlobal( + 'SELECT * FROM commute_data', + 'num_cyclists_per_total_population') ``` ### CDB_AreasOfInterestLocalRate(subquery text, numerator_column text, denominator_column text) @@ -113,9 +119,11 @@ SELECT aoi.quads, aoi.significance, c.cyclists_per_total_population -FROM cdb_crankshaft.CDB_AreasOfInterestLocalRate('SELECT * FROM commute_data' - 'num_cyclists', - 'total_population') As aoi +FROM + cdb_crankshaft.CDB_AreasOfInterestLocalRate( + 'SELECT * FROM commute_data' + 'num_cyclists', + 'total_population') As aoi JOIN commute_data As c ON c.cartodb_id = aoi.rowid; ``` @@ -149,10 +157,13 @@ A table with the following columns. #### Examples ```sql -SELECT * -FROM cdb_crankshaft.CDB_AreasOfInterestGlobalRate('SELECT * FROM commute_data', - 'num_cyclists', - 'total_population') +SELECT + * +FROM + cdb_crankshaft.CDB_AreasOfInterestGlobalRate( + 'SELECT * FROM commute_data', + 'num_cyclists', + 'total_population') ``` ## Hotspot, Coldspot, and Outlier Functions diff --git a/doc/04_markov.md b/doc/04_markov.md index 95137ca..a2afc85 100644 --- a/doc/04_markov.md +++ b/doc/04_markov.md @@ -40,8 +40,12 @@ SELECT m.trend_up, m.trend_down, m.volatility -FROM cdb_crankshaft.CDB_SpatialMarkovTrend('SELECT * FROM nyc_real_estate' - Array['m03y2009','m03y2010','m03y2011','m03y2012','m03y2013','m03y2014','m03y2015','m03y2016']) As m +FROM + cdb_crankshaft.CDB_SpatialMarkovTrend( + 'SELECT * FROM nyc_real_estate' + Array['m03y2009', 'm03y2010', 'm03y2011', + 'm03y2012', 'm03y2013', 'm03y2014', + 'm03y2015','m03y2016']) As m JOIN nyc_real_estate As c ON c.cartodb_id = m.rowid; ``` diff --git a/doc/11_kmeans.md b/doc/11_kmeans.md index 16c202f..6fe571a 100644 --- a/doc/11_kmeans.md +++ b/doc/11_kmeans.md @@ -1,8 +1,8 @@ ## K-Means Functions -### CDB_KMeans(subquery text, no_clusters INTEGER) +### CDB_KMeans(subquery text, no_clusters integer) -This function attempts to find n clusters within the input data. It will return a table to CartoDB ids and +This function attempts to find n clusters within the input data. It will return a table to CartoDB ids and the number of the cluster each point in the input was assigend to. @@ -26,18 +26,20 @@ A table with the following columns. #### Example Usage ```sql -SELECT - customers.*, - km.cluster_no - FROM cdb_crankshaft.CDB_Kmeans('SELECT * from customers' , 6) km, customers_3 - WHERE customers.cartodb_id = km.cartodb_id +SELECT + customers.*, + km.cluster_no +FROM + cdb_crankshaft.CDB_Kmeans('SELECT * from customers' , 6) km, customers_3 +WHERE + customers.cartodb_id = km.cartodb_id ``` ### CDB_WeightedMean(subquery text, weight_column text, category_column text) Function that computes the weighted centroid of a number of clusters by some weight column. -### Arguments +### Arguments | Name | Type | Description | |------|------|-------------| @@ -45,18 +47,24 @@ Function that computes the weighted centroid of a number of clusters by some wei | weight\_column | TEXT | The name of the column to use as a weight | | category\_column | TEXT | The name of the column to use as a category | -### Returns +### Returns A table with the following columns. | Column Name | Type | Description | |-------------|------|-------------| | the\_geom | GEOMETRY | A point for the weighted cluster center | -| class | INTEGER | The cluster class | +| class | INTEGER | The cluster class | -### Example Usage +### Example Usage -```sql -SELECT ST_TRANSFORM(the_geom, 3857) as the_geom_webmercator, class -FROM cdb_crankshaft.cdb_weighted_mean('SELECT *, customer_value FROM customers','customer_value','cluster_no') +```sql +SELECT + ST_Transform(m.the_geom, 3857) AS the_geom_webmercator, + m.class +FROM + cdb_crankshaft.cdb_WeightedMean( + 'SELECT * FROM customers', + 'customer_value', + 'cluster_no') AS m ``` diff --git a/doc/12_segmentation.md b/doc/12_segmentation.md index b6b0c95..055554b 100644 --- a/doc/12_segmentation.md +++ b/doc/12_segmentation.md @@ -3,7 +3,7 @@ ### CDB_CreateAndPredictSegment(query TEXT, variable_name TEXT, target_query TEXT) -This function trains a [Gradient Boosting](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html) model to attempt to predict the target data and then generates predictions for new data. +This function trains a [Gradient Boosting](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html) model to attempt to predict the target data and then generates predictions for new data. #### Arguments @@ -34,12 +34,12 @@ A table with the following columns. SELECT * from cdb_crankshaft.CDB_CreateAndPredictSegment( 'SELECT agg, median_rent::numeric, male_pop::numeric, female_pop::numeric FROM late_night_agg', 'agg', -'SELECT row_number() OVER () As cartodb_id, median_rent, male_pop, female_pop FROM ml_learning_ny'); +'SELECT row_number() OVER () As cartodb_id, median_rent, male_pop, female_pop FROM ml_learning_ny'); ``` ### CDB_CreateAndPredictSegment(target numeric[], train_features numeric[], prediction_features numeric[], prediction_ids numeric[]) -This function trains a [Gradient Boosting](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html) model to attempt to predict the target data and then generates predictions for new data. +This function trains a [Gradient Boosting](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html) model to attempt to predict the target data and then generates predictions for new data. #### Arguments @@ -76,7 +76,7 @@ WITH training As ( FROM late_night_agg), target AS ( SELECT cdb_crankshaft.CDB_PyAgg(Array[median_rent, male_pop, female_pop]::Numeric[]) As features, - array_agg(cartodb_id) As cartodb_ids FROM late_night_agg) + array_agg(cartodb_id) As cartodb_ids FROM late_night_agg) SELECT cdb_crankshaft.CDB_CreateAndPredictSegment(training.target, training.features, target.features, target.cartodb_ids) FROM training, target;