Home >Backend Development >PHP Tutorial >Simple linear regression implemented in PHP: (1)_PHP tutorial

Simple linear regression implemented in PHP: (1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:33822browse

The importance of databases in PHP
There is a powerful tool missing in the PHP world: language-based math libraries. In this two-part series, Paul Meagher hopes to inspire PHP developers to develop and implement PHP-based math libraries by providing an example of how to develop an analytical model library. In Part 1, he demonstrates how to develop and implement the core portion of the Simple Linear Regression algorithm package using PHP as the implementation language. In Part 2, the authors add functionality to the package: useful data analysis tools for small to medium-sized datasets.
Introduction
Compared to other open source languages ​​such as Perl and Python, the PHP community lacks a strong effort to develop math libraries.
One reason for this may be that there are already a large number of mature mathematical tools, which may hinder the community's efforts to develop PHP tools on their own. For example, I worked on a powerful tool, S System, which had an impressive set of statistical libraries, was specifically designed to analyze data sets, and won an ACM Award in 1998 for its language design. If S or its open source cousin R is just an exec_shell call, why go to the trouble of implementing the same statistical computing functionality in PHP? For more information about the S System, its ACM Award, or R, see Resources.
Isn’t this a waste of developer energy? If the motivation for developing a PHP math library was to save developer effort and use the best tool for the job, then PHP's current topic makes sense.
On the other hand, pedagogical motivations may encourage the development of PHP math libraries. For about 10% of people, mathematics is an interesting subject to explore. For those who are also proficient in PHP, the development of a PHP math library can enhance the math learning process. In other words, don't just read the chapter about T-tests, but also implement a program that can calculate the corresponding intermediate values ​​and display them in a standard format. their classes.
Through coaching and training, I hope to demonstrate that developing a PHP math library is not a difficult task and may represent an interesting technical and learning challenge. In this article, I will provide a PHP math library example called SimpleLinearRegression that demonstrates a general approach that can be used to develop PHP math libraries. Let's start by discussing some general principles that guided me in developing this SimpleLinearRegression class.
Guiding Principles
I used six general principles to guide the development of the SimpleLinearRegression class.
1. Create a class for each analysis model.
2. Use reverse linking to develop classes.
3. Expect a large number of getters.
4. Store intermediate results.
5. Set preferences for detailed APIs.
6. Perfection is not the goal.
7. Let’s examine each of these guidelines in more detail.
Create a class for each analysis model
Each major analysis test or process should have a PHP class with the same name as the test or process name. This class contains input functions, functions for calculating intermediate values ​​and summary values. and output functions (which display intermediate and summary values ​​all on the screen in text or graphical format).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631761.htmlTechArticleThe Importance of Databases in PHP There is a powerful tool missing in the PHP field: language-based mathematics libraries. In this two-part series, Paul Meagher hopes to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn