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

本文涉及的产品
PolarDB Agent Express,2核4GB
云数据库 PolarDB MySQL 版,列存表分析加速 8核16GB
PolarSearch,搜索节点 4核8GB
简介: PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.本文将介绍PolarDB结合madlib, 让PolarDB具备机器学习功能.madlib库无疑是大而全的数据库机器学习库-Deep Learning-Graph-Model Selection-Sampling-Statistics-Supervised Learning-Time Series Analysis-Unsupervised Learning

背景

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环境

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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
8月前
|
SQL 关系型数据库 MySQL
阿里云RDS云数据库全解析:产品功能、收费标准与活动参考
与云服务器ECS一样,关系型数据库RDS也是很多用户上云必买的热门云产品之一,阿里云的云数据库RDS主要包含RDS MySQL、RDS SQL Server、RDS PostgreSQL、RDS MariaDB等几个关系型数据库,并且提供了容灾、备份、恢复、监控、迁移等方面的全套解决方案,帮助您解决数据库运维的烦恼。本文为大家介绍阿里云的云数据库 RDS主要产品及计费方式、收费标准以及活动等相关情况,以供参考。
|
11月前
|
存储 关系型数据库 分布式数据库
喜报|阿里云PolarDB数据库(分布式版)荣获国内首台(套)产品奖项
阿里云PolarDB数据库管理软件(分布式版)荣获「2024年度国内首版次软件」称号,并跻身《2024年度浙江省首台(套)推广应用典型案例》。
|
12月前
|
关系型数据库 分布式数据库 数据库
再获殊荣,阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
内存池化技术新突破,阿里云PolarDB蝉联SIGMOD最佳论文奖
|
9月前
|
Cloud Native 关系型数据库 MySQL
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
PolarDB-X 是阿里云推出的云原生分布式数据库,支持PB级存储扩展、高并发访问与数据强一致,助力企业实现MySQL平滑迁移。现已开放免费体验,点击即享高效、稳定的数据库升级方案。
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
|
9月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
11月前
|
SQL 存储 关系型数据库
MySQL功能模块探秘:数据库世界的奇妙之旅
]带你轻松愉快地探索MySQL 8.4.5的核心功能模块,从SQL引擎到存储引擎,从复制机制到插件系统,让你在欢声笑语中掌握数据库的精髓!
344 26
|
11月前
|
关系型数据库 分布式数据库 数据库
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
阿里云PolarDB凭借全球首创基于CXL Switch的分布式内存池技术,在SIGMOD 2025上荣获工业赛道“最佳论文奖”,连续两年蝉联该顶会最高奖项。其创新架构PolarCXLMem打破传统RDMA技术瓶颈,性能提升2.1倍,并已落地应用于内存池化场景,推动大模型推理与多模态存储发展,展现CXL Switch在高速互联中的巨大潜力。
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
|
9月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
571 158
|
9月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
9月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1483 152

热门文章

最新文章

相关产品

  • 云原生数据库 PolarDB