经典机器学习算法系列7-svd

1.svd简介

2.svd分解例子

eigen库是一个c++库,实现了线性矩阵部分,其他还有openblas等。如果有时间自己要实现一个SVD的c++代码,现在只用库来代替。eigen不用cmake只要一步配置即可使用。在右键项目,在c/c++常规中附加包含目录包含eigen的解压目录即可。博客 [1]给出了eigen库的配置和使用例程。在官网[2]上给出了一个例子。

完整的代码如下

#include "stdafx.h"
#include <iostream>
#include <Eigen/SVD> 
using namespace Eigen;  
using namespace Eigen::internal;  
using namespace Eigen::Architecture;  
  
using namespace std;
int main(){
	MatrixXf m = MatrixXf::Random(3,2);
	cout << "Here is the matrix m:" << endl << m << endl;
	JacobiSVD<MatrixXf> svd(m, ComputeThinU | ComputeThinV);
	cout << "Its singular values are:" << endl << svd.singularValues() << endl;
	cout << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl;
	cout << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl;
	Vector3f rhs(1, 0, 0);
	cout << "Now consider this rhs vector:" << endl << rhs << endl;
	cout << "A least-squares solution of m*x = rhs is:" << endl << svd.solve(rhs) << endl;
	getchar();
	return 0;
}

运行的效果如下



3.协同过滤简单例子

4.利用大点的数据集设计推荐系统的例子

[1] 小美女的博客

[2] JocabiSVD官网

转载于:https://www.cnblogs.com/hellokittyblog/p/8186170.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值