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

简介: 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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
Oracle 关系型数据库 Linux
【赵渝强老师】Oracle数据库配置助手:DBCA
Oracle数据库配置助手(DBCA)是用于创建和配置Oracle数据库的工具,支持图形界面和静默执行模式。本文介绍了使用DBCA在Linux环境下创建数据库的完整步骤,包括选择数据库操作类型、配置存储与网络选项、设置管理密码等,并提供了界面截图与视频讲解,帮助用户快速掌握数据库创建流程。
1000 93
|
12月前
|
SQL 关系型数据库 MySQL
阿里云RDS云数据库全解析:产品功能、收费标准与活动参考
与云服务器ECS一样,关系型数据库RDS也是很多用户上云必买的热门云产品之一,阿里云的云数据库RDS主要包含RDS MySQL、RDS SQL Server、RDS PostgreSQL、RDS MariaDB等几个关系型数据库,并且提供了容灾、备份、恢复、监控、迁移等方面的全套解决方案,帮助您解决数据库运维的烦恼。本文为大家介绍阿里云的云数据库 RDS主要产品及计费方式、收费标准以及活动等相关情况,以供参考。
|
关系型数据库 MySQL 数据库连接
Django数据库配置避坑指南:从初始化到生产环境的实战优化
本文介绍了Django数据库配置与初始化实战,涵盖MySQL等主流数据库的配置方法及常见问题处理。内容包括数据库连接设置、驱动安装、配置检查、数据表生成、初始数据导入导出,并提供真实项目部署场景的操作步骤与示例代码,适用于开发、测试及生产环境搭建。
695 1
|
Ubuntu 安全 关系型数据库
安装与配置MySQL 8 on Ubuntu,包括权限授予、数据库备份及远程连接指南
以上步骤提供了在Ubuntu上从头开始设置、配置、授权、备份及恢复一个基础但完整的MySQL环境所需知识点。
1323 7
|
缓存 Java 应用服务中间件
Spring Boot配置优化:Tomcat+数据库+缓存+日志,全场景教程
本文详解Spring Boot十大核心配置优化技巧,涵盖Tomcat连接池、数据库连接池、Jackson时区、日志管理、缓存策略、异步线程池等关键配置,结合代码示例与通俗解释,助你轻松掌握高并发场景下的性能调优方法,适用于实际项目落地。
2000 5
|
SQL 存储 关系型数据库
MySQL功能模块探秘:数据库世界的奇妙之旅
]带你轻松愉快地探索MySQL 8.4.5的核心功能模块,从SQL引擎到存储引擎,从复制机制到插件系统,让你在欢声笑语中掌握数据库的精髓!
425 26
|
安全 Java 数据库
Jasypt加密数据库配置信息
本文介绍了使用 Jasypt 对配置文件中的公网数据库认证信息进行加密的方法,以提升系统安全性。主要内容包括:1. 背景介绍;2. 前期准备,如依赖导入及版本选择;3. 生成密钥并实现加解密测试;4. 在配置文件中应用加密后的密码,并通过测试接口验证解密结果。确保密码安全的同时,保障系统的正常运行。
1002 3
Jasypt加密数据库配置信息
|
SQL XML Java
配置Spring框架以连接SQL Server数据库
最后,需要集成Spring配置到应用中,这通常在 `main`方法或者Spring Boot的应用配置类中通过加载XML配置或使用注解来实现。
870 0
|
12月前
|
机器学习/深度学习 数据采集 人工智能
【机器学习算法篇】K-近邻算法
K近邻(KNN)是一种基于“物以类聚”思想的监督学习算法,通过计算样本间距离,选取最近K个邻居投票决定类别。支持多种距离度量,如欧式、曼哈顿、余弦相似度等,适用于分类与回归任务。结合Scikit-learn可高效实现,需合理选择K值并进行数据预处理,常用于鸢尾花分类等经典案例。(238字)
|
机器学习/深度学习 算法 数据挖掘
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构。本文介绍了K-means算法的基本原理,包括初始化、数据点分配与簇中心更新等步骤,以及如何在Python中实现该算法,最后讨论了其优缺点及应用场景。
1929 6

热门文章

最新文章

相关产品

  • 云原生数据库 PolarDB