在 Amazon RDS 上安装 Kmeans PostgreSQL 扩展

Installing the Kmeans PostgreSQL extension on Amazon RDS

我参与了一些 Django 项目,我们使用地理数据(通过 GeoDjango)。 我已经按照 AWS 文档中的说明安装了 PostGis。

我们在地图上有很多点(标记)。我们需要将它们聚类。

我发现一个库 anycluster. This library need the PostgreSQL extension named kmeans-postgresql 安装在 Postgre 数据库上。

但我的数据库位于 Amazon RDS 上。我无法通过 SSH 连接到它以安装扩展...

有人知道如何在我的 Amazon RDS 数据库上安装 kmeans-postgresql 扩展吗?

或者您可以建议我其他的聚类方法吗?

您可以只在 Amazon RDS 和 Kmeans 上安装支持的扩展,不是吗。

ERROR: Extension "kmeans" is not supported by Amazon RDS DETAIL: Installing the extension "kmeans" failed, because it is not on the list of extensions supported by Amazon RDS. HINT: Amazon RDS allows users with rds_superuser role to install supported extensions. See: SHOW rds.extensions; alexandria_development=> SHOW rds.extensions

RDS 扩展:

btree_gin, btree_gist, chkpass, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, intagg, intarray, isn, ltree, pgcrypto, pgrowlocks, pg_prewarm, pg_stat_statements, pg_trgm, plcoffee, plls, plperl, plpgsql, pltcl, plv8, postgis, postgis_tiger_geocoder, postgis_topology, postgres_fdw, sslinfo, tablefunc, test_parser, tsearch2, unaccent, uuid-ossp

K-Means 这是一个非常复杂的计算,对数据挖掘和聚类分析很有用(你可以在维基百科页面上看到更多关于它的信息 https://en.wikipedia.org/wiki/K-means_clustering ). It have a big complexity when have to deal with many points. The K-means extension to postgresql http://pgxn.org/dist/kmeans/doc/kmeans.html 它是用 C 编写的,并在数据库中编译机器。与 plpgsql 中的过程相比,这带来了更好的性能。不幸的是,@estevao_lucas 回答说,此扩展未在 Amazon RDS 中启用。

如果您真的需要 k-means 结果,我翻译了它的这个实现,由 Joni Salonen 在 http://jonisalonen.com/2012/k-means-clustering-in-mysql/ and changed to plpgsql https://gist.github.com/thiagomata/a9737c3455d6248bef9f 中创建。此函数使用临时 table。如果您愿意,可以将其更改为仅使用 Pin 数组。

但是,如果您只需要在地图中显示一些图钉,您可能会对将结果分组到 [x,y] 矩阵中的真正更快、更简单的函数感到满意。我创建了这样的函数,因为 kmeans 函数花费了太多时间来处理我的数据库(有超过 400K 的元素)。所以这个实现确实更快,但不具备您期望从 K-means 模块获得的所有功能。除此之外,这个网格函数 https://gist.github.com/thiagomata/18ea14853998468c1a1d returns 非常好的结果,当它的目标是在地图中显示大量的图钉时。