科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件PHP实现简单线性回归之数据研究工具

PHP实现简单线性回归之数据研究工具

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

简单线性回归建模背后的基本目标是从成对的 X值和 Y值组成的二维平面中找到最吻合的直线。

作者:Paul Meagher 来源:ibm 2007年10月21日

关键字: Linux

  • 评论
  • 分享微博
  • 分享邮件
数据研究脚本

  该数据研究工具由单个脚本( explore.php)构成,该脚本调用 SimpleLinearRegressionHTML 类和 JpGraph 库的方法。

  该脚本使用了简单的处理逻辑。该脚本的第一部分对所提交的表单数据执行基本验证。如果这些表单数据通过验证,则执行该脚本的第二部分。

  该脚本的第二部分所包含的代码用于分析数据,并以 HTML 和图形格式显示汇总结果。 清单 4中显示了 explore.php脚本的基本结构:

  清单 4. explore.php 的结构


 
<?php  

  // explore.php  

  if (!empty($x_values)) {  
    $X    = explode(",", $x_values);  
    $numX = count($X);  
  }    

  if (!empty($y_values)) {  
    $Y    = explode(",", $y_values);  
    $numY = count($Y);  
  }    

  // display entry data entry form if variables not set  

  if ( (empty($title)) OR (empty($x_name)) OR (empty($x_values)) OR   
       (empty($y_name)) OR (empty($conf_int)) OR (empty($y_values)) OR   
       ($numX != $numY) ) {           

    // Omitted code for displaying entry form  
      
  } else {  
      
    include_once "slr/SimpleLinearRegressionHTML.php";                        
    $slr = new SimpleLinearRegressionHTML($X, $Y, $conf_int);     

    echo "<h2>$title</h2>";  
      
    $slr->showTableSummary($x_name, $y_name);  
    echo "<br><br>";  
      
    $slr->showAnalysisOfVariance();    
    echo "<br><br>";  

    $slr->showParameterEstimates($x_name, $y_name);   
    echo "<br>";  

    $slr->showFormula($x_name, $y_name);  
    echo "<br><br>";  

    $slr->showRValues($x_name, $y_name);  
    echo "<br>";  

    include ("jpgraph/jpgraph.php");  
    include ("jpgraph/jpgraph_scatter.php");  
    include ("jpgraph/jpgraph_line.php");    
                        
    // The code for displaying the graphics is inline in the  
    // explore.php script.  The code for these two line plots  
    // finishes off the script:  
      
    // Omitted code for displaying scatter plus line plot  
    // Omitted code for displaying residuals plot  
      
  }  

  ?> 
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章