高斯消元法解多项式回归

本文介绍了如何运用高斯消元法解决单特征量、单输出值数据集的多项式回归问题。通过构建损失函数,找到使损失函数达到极小值的参数,进而求解线性方程组。然而,这种方法存在局限性,如需要线性方程组有唯一解,大数据量下效率较低,以及需要预先设定多项式阶数。
摘要由CSDN通过智能技术生成

问题背景:给定一个单特征量、单输出值的数据集,找到一个拟合效果最佳的多项式关系y=\Theta0+\Theta1x^1+\Theta2x^2+...+\Theta m x^m,并预测其趋势。

基本思路:用预测值与真实值的差方和来表征多项式的拟合效果,称为损失函数,损失函数极值点即为最佳拟合效果的参数,而多元函数的极值点可以通过求偏导并联立方程组解得。

具体过程:1.求损失函数偏导,得到线性方程组:

                    

void ini()
{
	for (int i=1;i<=30;i++)
	   for (int j=0;j<=5;j++)
	      power[i][j]=fastpower(i,j);	
	for (int i=1;i<=m+1;i++)					//系数矩阵为对称阵,还可以优化 
	   for (int j=1;j<=m+1;j++)
	      {
	          A[i][j]=0;
			  for (int k=1;k<=n;k++)
	
% This folder contains a collection of "fitting" functions. % (Some has demo options - the third section) % The GENERAL input to the functions should be samples of the distribution. % % for example, if we are to fit a normal distribution ('gaussian') with a mean "u" and varaince "sig"^2 % then the samples will distribute like: % samples = randn(1,10000)*sig + u % %fitting with Least-Squares is done on the histogram of the samples. % fitting with Maximum likelihood is done directly on the samples. % % % Contents of this folder % ======================= % 1) Maximum likelihood estimators % 2) Least squares estimators % 3) EM algorithm for estimation of multivariant gaussian distribution (mixed gaussians) % 4) added folders: Create - which create samples for the EM algorithm test % Plot - used to plot each of the distributions (parametric plot) % % % % % % Maximum likelihood estimators % ============================= % fit_ML_maxwell - fit maxwellian distribution % fit_ML_rayleigh - fit rayleigh distribution % (which is for example: sqrt(abs(randn)^2+abs(randn)^2)) % fit_ML_laplace - fit laplace distribution % fit_ML_log_normal- fit log-normal distribution % fit_ML_normal - fit normal (gaussian) distribution % % NOTE: all estimators are efficient estimators. for this reason, the distribution % might be written in a different way, for example, the "Rayleigh" distribution % is given with a parameter "s" and not "s^2". % % % least squares estimators % ========================= % fit_maxwell_pdf - fits a given curve of a maxwellian distribution % fit_rayleigh_pdf - fits a given curve of a rayleigh distribution % % NOTE: these fit function are used on a histogram output which is like a sampled % distribution function. the given curve MUST be normalized, since the estimator % is trying to fit a normalized distribution function. % % % % % Multivariant Gaussian distribution % ================================== % for demo of 1
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值