【发布时间】:2015-06-19 07:39:26
【问题描述】:
我正在尝试使用 Statistics::Regression 模块在 perl 中实现线性回归,而无需 INTERCEPT。如何在没有截距的情况下实现回归模型?我使用以下代码通过拦截得到正确的结果:
#!/usr/bin/perl
use strict;
use warnings;
use Statistics::Regression
my @row=();
my $reg=Statistics::Regression->new("sample regression",["const", "x"]);
open(my $f1, "<","ema_bid_44671_11536") or
die "cant open ema_bid_44671_11536";
while(my $line=<$f1>){
my @row=split(",",$line);
chomp($row[2]);
chomp($row[1]);
$reg->include($row[2],[ 1.0, $row[1]]);
}
$reg->print();
close $f1;
但是当我在 while 循环中的最后一条语句中将 1.0 更改为 0.0 时(包括零常量),代码如下所示:
#!/usr/bin/perl
use strict;
use warnings;
use Statistics::Regression
my @row=();
my $reg=Statistics::Regression->new("sample regression",["const", "x"]);
open(my $f1, "<","ema_bid_44671_11536") or
die "cant open ema_bid_44671_11536";
while(my $line=<$f1>){
my @row=split(",",$line);
chomp($row[2]);
chomp($row[1]);
$reg->include($row[2],[ 0.0, $row[1]]);
}
$reg->print();
close $f1;
它给了我错误:
regression_ema.pl::Statistics::Regression:standarderrors: I cannot compute the theta-covariance matrix for variable 1 0
at /usr/local/share/perl/5.20.2/Statistics/Regression.pm line 619, <$f1> line 2472.
Statistics::Regression::standarderrors(Statistics::Regression=HASH(0x23f41f0)) called at /usr/local/share/perl/5.20.2/Statistics/Regression.pm line 430
Statistics::Regression::print(Statistics::Regression=HASH(0x23f41f0)) called at regression_ema.pl line 23
【问题讨论】:
标签: perl regression linear-regression intercept