配置 madlib for PolarDB 实现数据库机器学习功能

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: 背景PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.本文将介绍PolarDB结合madlib, 让PolarDB具备机器学习功能.mad...

背景

PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.

本文将介绍PolarDB结合madlib, 让PolarDB具备机器学习功能.

madlib库无疑是大而全的数据库机器学习库,

  • Deep Learning

  • Graph

  • Model Selection

  • Sampling

  • Statistics

  • Supervised Learning

  • Time Series Analysis

  • Unsupervised Learning

将madlib安装到PolarDB, 让PolarDB具备机器学习功能

这个例子直接在PolarDB容器中部署pgcat.

PolarDB部署请参考《如何用 PolarDB 证明巴菲特的投资理念 - 包括PolarDB简单部署》

进入PolarDB环境

docker exec -it 67e1eed1b4b6 bash    

下载madlib rpm

https://cwiki.apache.org/confluence/display/MADLIB/Installation+Guide

wget https://dist.apache.org/repos/dist/release/madlib/1.20.0/apache-madlib-1.20.0-CentOS7.rpm  

安装madlib

sudo rpm -ivh apache-madlib-1.20.0-CentOS7.rpm  

加载madlib到PolarDB数据库对应DB中(非extension管理)

/usr/local/madlib/bin/madpack -s madlib -p postgres -c [user[/password]@][host][:port][/database] install  
  
or  
  
/usr/local/madlib/bin/madpack -s madlib -p postgres install  

测试madlib安装正确性

/usr/local/madlib/bin/madpack -s madlib -p postgres install-check  

使用madlib

[postgres@67e1eed1b4b6 ~]$ psql -h 127.0.0.1  
psql (11.9)  
Type "help" for help.  
  
postgres=# set search_path =madlib, "$user", public;  
SET  
  
  
postgres=# \dT+  
                                                               List of data types  
 Schema |               Name                |           Internal name           | Size  | Elements |  Owner   | Access privileges | Description   
--------+-----------------------------------+-----------------------------------+-------+----------+----------+-------------------+-------------  
 madlib | args_and_value_double             | args_and_value_double             | tuple |          | postgres |                   |   
 madlib | __arima_lm_result                 | __arima_lm_result                 | tuple |          | postgres |                   |   
 madlib | __arima_lm_stat_result            | __arima_lm_stat_result            | tuple |          | postgres |                   |   
 madlib | __arima_lm_sum_result             | __arima_lm_sum_result             | tuple |          | postgres |                   |   
 madlib | assoc_rules_results               | assoc_rules_results               | tuple |          | postgres |                   |   
 madlib | bytea8                            | bytea8                            | var   |          | postgres |                   |   
 madlib | _cat_levels_type                  | _cat_levels_type                  | tuple |          | postgres |                   |   
 madlib | chi2_test_result                  | chi2_test_result                  | tuple |          | postgres |                   |   
 madlib | closest_column_result             | closest_column_result             | tuple |          | postgres |                   |   
 madlib | closest_columns_result            | closest_columns_result            | tuple |          | postgres |                   |   
 madlib | __clustered_agg_result            | __clustered_agg_result            | tuple |          | postgres |                   |   
 madlib | __clustered_lin_result            | __clustered_lin_result            | tuple |          | postgres |                   |   
 madlib | __clustered_log_result            | __clustered_log_result            | tuple |          | postgres |                   |   
 madlib | __clustered_mlog_result           | __clustered_mlog_result           | tuple |          | postgres |                   |   
 madlib | complex                           | complex                           | tuple |          | postgres |                   |   
 madlib | __coxph_a_b_result                | __coxph_a_b_result                | tuple |          | postgres |                   |   
 madlib | __coxph_cl_var_result             | __coxph_cl_var_result             | tuple |          | postgres |                   |   
 madlib | coxph_result                      | coxph_result                      | tuple |          | postgres |                   |   
 madlib | coxph_step_result                 | coxph_step_result                 | tuple |          | postgres |                   |   
 madlib | cox_prop_hazards_result           | cox_prop_hazards_result           | tuple |          | postgres |                   |   
 madlib | __cox_resid_stat_result           | __cox_resid_stat_result           | tuple |          | postgres |                   |   
 madlib | __dbscan_edge                     | __dbscan_edge                     | tuple |          | postgres |                   |   
 madlib | __dbscan_losses                   | __dbscan_losses                   | tuple |          | postgres |                   |   
 madlib | __dbscan_record                   | __dbscan_record                   | tuple |          | postgres |                   |   
 madlib | dense_linear_solver_result        | dense_linear_solver_result        | tuple |          | postgres |                   |   
 madlib | __elastic_net_result              | __elastic_net_result              | tuple |          | postgres |                   |   
 madlib | _flattened_tree                   | _flattened_tree                   | tuple |          | postgres |                   |   
 madlib | f_test_result                     | f_test_result                     | tuple |          | postgres |                   |   
 madlib | __glm_result_type                 | __glm_result_type                 | tuple |          | postgres |                   |   
 madlib | _grp_state_type                   | _grp_state_type                   | tuple |          | postgres |                   |   
 madlib | heteroskedasticity_test_result    | heteroskedasticity_test_result    | tuple |          | postgres |                   |   
 madlib | kmeans_result                     | kmeans_result                     | tuple |          | postgres |                   |   
 madlib | kmeans_state                      | kmeans_state                      | tuple |          | postgres |                   |   
 madlib | ks_test_result                    | ks_test_result                    | tuple |          | postgres |                   |   
 madlib | lda_result                        | lda_result                        | tuple |          | postgres |                   |   
 madlib | lincrf_result                     | lincrf_result                     | tuple |          | postgres |                   |   
 madlib | linear_svm_result                 | linear_svm_result                 | tuple |          | postgres |                   |   
 madlib | linregr_result                    | linregr_result                    | tuple |          | postgres |                   |   
 madlib | lmf_result                        | lmf_result                        | tuple |          | postgres |                   |   
 madlib | __logregr_result                  | __logregr_result                  | tuple |          | postgres |                   |   
 madlib | marginal_logregr_result           | marginal_logregr_result           | tuple |          | postgres |                   |   
 madlib | marginal_mlogregr_result          | marginal_mlogregr_result          | tuple |          | postgres |                   |   
 madlib | margins_result                    | margins_result                    | tuple |          | postgres |                   |   
 madlib | matrix_result                     | matrix_result                     | tuple |          | postgres |                   |   
 madlib | __mlogregr_cat_coef               | __mlogregr_cat_coef               | tuple |          | postgres |                   |   
 madlib | mlogregr_result                   | mlogregr_result                   | tuple |          | postgres |                   |   
 madlib | mlogregr_summary_result           | mlogregr_summary_result           | tuple |          | postgres |                   |   
 madlib | mlp_result                        | mlp_result                        | tuple |          | postgres |                   |   
 madlib | __multinom_result_type            | __multinom_result_type            | tuple |          | postgres |                   |   
 madlib | mw_test_result                    | mw_test_result                    | tuple |          | postgres |                   |   
 madlib | one_way_anova_result              | one_way_anova_result              | tuple |          | postgres |                   |   
 madlib | __ordinal_result_type             | __ordinal_result_type             | tuple |          | postgres |                   |   
 madlib | path_match_result                 | path_match_result                 | tuple |          | postgres |                   |   
 madlib | _pivotalr_lda_model               | _pivotalr_lda_model               | tuple |          | postgres |                   |   
 madlib | _prune_result_type                | _prune_result_type                | tuple |          | postgres |                   |   
 madlib | __rb_coxph_hs_result              | __rb_coxph_hs_result              | tuple |          | postgres |                   |   
 madlib | __rb_coxph_result                 | __rb_coxph_result                 | tuple |          | postgres |                   |   
 madlib | residual_norm_result              | residual_norm_result              | tuple |          | postgres |                   |   
 madlib | robust_linregr_result             | robust_linregr_result             | tuple |          | postgres |                   |   
 madlib | robust_logregr_result             | robust_logregr_result             | tuple |          | postgres |                   |   
 madlib | robust_mlogregr_result            | robust_mlogregr_result            | tuple |          | postgres |                   |   
 madlib | sparse_linear_solver_result       | sparse_linear_solver_result       | tuple |          | postgres |                   |   
 madlib | summary_result                    | summary_result                    | tuple |          | postgres |                   |   
 madlib | __svd_bidiagonal_matrix_result    | __svd_bidiagonal_matrix_result    | tuple |          | postgres |                   |   
 madlib | __svd_lanczos_result              | __svd_lanczos_result              | tuple |          | postgres |                   |   
 madlib | __svd_vec_mat_mult_result         | __svd_vec_mat_mult_result         | tuple |          | postgres |                   |   
 madlib | svec                              | svec                              | var   |          | postgres |                   |   
 madlib | _tree_result_type                 | _tree_result_type                 | tuple |          | postgres |                   |   
 madlib | t_test_result                     | t_test_result                     | tuple |          | postgres |                   |   
 madlib | __utils_scales                    | __utils_scales                    | tuple |          | postgres |                   |   
 madlib | wsr_test_result                   | wsr_test_result                   | tuple |          | postgres |                   |   
 madlib | xgb_gridsearch_train_results_type | xgb_gridsearch_train_results_type | tuple |          | postgres |                   |   
 public | vector                            | vector                            | var   |          | postgres |                   |   
(73 rows)  
  
postgres=#   \do+  
                                                    List of operators  
 Schema | Name |   Left arg type    |   Right arg type   |   Result type    |           Function            | Description   
--------+------+--------------------+--------------------+------------------+-------------------------------+-------------  
 madlib | %*%  | double precision[] | double precision[] | double precision | madlib.svec_dot               |   
 madlib | %*%  | double precision[] | svec               | double precision | madlib.svec_dot               |   
 madlib | %*%  | svec               | double precision[] | double precision | madlib.svec_dot               |   
 madlib | %*%  | svec               | svec               | double precision | madlib.svec_dot               |   
 madlib | *    | double precision[] | double precision[] | svec             | float8arr_mult_float8arr      |   
 madlib | *    | double precision[] | svec               | svec             | float8arr_mult_svec           |   
 madlib | *    | svec               | double precision[] | svec             | svec_mult_float8arr           |   
 madlib | *    | svec               | svec               | svec             | svec_mult                     |   
 madlib | *||  | integer            | svec               | svec             | svec_concat_replicate         |   
 madlib | +    | double precision[] | double precision[] | svec             | float8arr_plus_float8arr      |   
 madlib | +    | double precision[] | svec               | svec             | float8arr_plus_svec           |   
 madlib | +    | svec               | double precision[] | svec             | svec_plus_float8arr           |   
 madlib | +    | svec               | svec               | svec             | svec_plus                     |   
 madlib | -    | double precision[] | double precision[] | svec             | float8arr_minus_float8arr     |   
 madlib | -    | double precision[] | svec               | svec             | float8arr_minus_svec          |   
 madlib | -    | svec               | double precision[] | svec             | svec_minus_float8arr          |   
 madlib | -    | svec               | svec               | svec             | svec_minus                    |   
 madlib | /    | double precision[] | double precision[] | svec             | float8arr_div_float8arr       |   
 madlib | /    | double precision[] | svec               | svec             | float8arr_div_svec            |   
 madlib | /    | svec               | double precision[] | svec             | svec_div_float8arr            |   
 madlib | /    | svec               | svec               | svec             | svec_div                      |   
 madlib | <    | svec               | svec               | boolean          | svec_lt                       |   
 madlib | <=   | svec               | svec               | boolean          | svec_le                       |   
 madlib | <>   | svec               | svec               | boolean          | svec_ne                       |   
 madlib | =    | svec               | svec               | boolean          | svec_eq                       |   
 madlib | ==   | svec               | svec               | boolean          | svec_eq                       |   
 madlib | >    | svec               | svec               | boolean          | svec_gt                       |   
 madlib | >=   | svec               | svec               | boolean          | svec_ge                       |   
 madlib | ^    | svec               | svec               | svec             | svec_pow                      |   
 madlib | ||   | svec               | svec               | svec             | svec_concat                   |   
 public | +    | vector             | vector             | vector           | vector_add                    |   
 public | -    | vector             | vector             | vector           | vector_sub                    |   
 public | <    | vector             | vector             | boolean          | vector_lt                     |   
 public | <#>  | vector             | vector             | double precision | vector_negative_inner_product |   
 public | <->  | vector             | vector             | double precision | l2_distance                   |   
 public | <=   | vector             | vector             | boolean          | vector_le                     |   
 public | <=>  | vector             | vector             | double precision | cosine_distance               |   
 public | <>   | vector             | vector             | boolean          | vector_ne                     |   
 public | =    | vector             | vector             | boolean          | vector_eq                     |   
 public | >    | vector             | vector             | boolean          | vector_gt                     |   
 public | >=   | vector             | vector             | boolean          | vector_ge                     |   
(41 rows)  

参考

https://madlib.apache.org/docs/latest/index.html

https://cwiki.apache.org/confluence/display/MADLIB/Installation+Guide

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
10天前
|
关系型数据库 Apache 流计算
手把手教你实现 OceanBase 数据到阿里云数据库 SelectDB 内核版 Apache Doris 的便捷迁移|实用指南
本文介绍了如何将数据从 OceanBase 迁移到阿里云数据库 SelectDB 内核版 Apache Doris。提供 3 种数据同步方法 1. 使用 DataX,下载 DataX 并编写配置文件,通过 OceanBaseReader 和 DorisWriter 进行数据迁移。 2. 利用 Apache Doris 的 Catalog功 能,将 OceanBase 表映射到 Doris 并插入数据。 3. 通过Flink CDC,设置 OceanBase 环境,配置 Flink 连接器,实现实时数据同步。
手把手教你实现 OceanBase 数据到阿里云数据库 SelectDB 内核版 Apache Doris 的便捷迁移|实用指南
|
5月前
|
存储 SQL Java
数据库TiDB-01.数据库架构概述
TiDB兼容MySQL 5.7协议,支持水平扩容或者缩容的金融级高可用的云原生分布式数据库。
328 2
数据库TiDB-01.数据库架构概述
|
7月前
|
SQL 关系型数据库 测试技术
沉浸式学习PostgreSQL|PolarDB 20: 学习成为数据库大师级别的优化技能
在上一个实验《沉浸式学习PostgreSQL|PolarDB 19: 体验最流行的开源企业ERP软件 odoo》 中, 学习了如何部署odoo和polardb|pg. 由于ODOO是非常复杂的ERP软件, 对于关系数据库的挑战也非常大, 所以通过odoo业务可以更快速提升同学的数据库优化能力, 发现业务对数据库的使用问题(如索引、事务对锁的运用逻辑问题), 数据库的代码缺陷, 参数或环境配置问题, 系统瓶颈等.
764 1
|
SQL Cloud Native 安全
快速入门—PolarDB-X首次使用流程—连接到数据库
本文将介绍如何通过数据管理DMS连接到PolarDB-X。PolarDB-X还支持通过SQL命令行、第三方客户端(MySQL WorkBench、SQLyog、Sequel Pro、Navicat for MySQL)以及符合MySQL官方交互协议的第三方程序代码进行连接。
2174 0
|
7月前
|
关系型数据库 Java 分布式数据库
快速体验PolarDB开源数据库的步骤
快速体验PolarDB开源数据库的步骤
321 0
|
3月前
|
关系型数据库 分布式数据库 数据库
云原生数据库PolarDB快速入门实验
【2月更文挑战第2天】很基础的PolarDB入门操作实验考试,假期闲着无聊考着玩玩。云原生数据库 PolarDB MySQL 版是阿里云自研产品,100%兼容 MySQL。PolarDB产品具有多主多写、多活容灾、HTAP 等特性,交易性能最高可达开源数据库的6倍,分析性能最高可达开源数据库的400倍,TCO 低于自建数据库50%。
|
5月前
|
SQL 关系型数据库 分布式数据库
西电数据库实验二:XDSQL与PolarDB对比实验
实验二 XDSQL与PolarDB对比实验 姓名:贾瑞  学号:21009201172
|
10月前
|
SQL 存储 人工智能
NineData已支持「最受欢迎数据库」PostgreSQL
NineData 也在近期支持了 PostgreSQL,用户可以在 NineData 平台上进行创建数据库/Schema、管理用户与角色、导出数据、执行 SQL 等操作。另外,NineData SQL 开发企业版,还可以统一管理企业内部 PostgreSQL 的访问、规范与流程、变更发布等。
311 0
NineData已支持「最受欢迎数据库」PostgreSQL
|
12月前
|
存储 NoSQL 安全
「数据库深度探索」图型数据库JanusGraph支持知识图谱和图型分析
「数据库深度探索」图型数据库JanusGraph支持知识图谱和图型分析
|
12月前
|
存储 SQL 运维
阿里云数据库ClickHouse产品和技术解读
社区ClickHouse的单机引擎性能十分惊艳,但是部署运维ClickHouse集群,以及troubleshoot都不是很好上手。本次分享阿里云数据库ClickHouse产品能力和特性,包含同步MySQL库、ODPS库、本地盘及多盘性价比实例以及自建集群上云的迁移工具。最后介绍阿里云在云原生ClickHouse的进展情况。
279 0