PHP Classes

How to Use PHP Machine Learning Library to Implement Artificial Intelligence Models Using the Package PHP ML: Process data and evaluate machine learning models

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-12-17 (10 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
phpml 1.0Custom (specified...5PHP 5, Statistics, Artificial intelli...
Description 

Author

This package can process data and evaluate machine learning models.

It provides several classes that can perform several types of data processing.

Currently, the classes can:

- Normalize a data set to fit within a given value range

- Standardize data (mean or standard)

- Handle missing values

- Encode categorical data

- Get a summary of data with descriptive statistics

- Calculate a correlation matrix

- Identify outliers in data

- Evaluate machine learning models accuracy, precision score, calculate the recall score,

- Generate a confusion matrix

- Calculate the mean squared error for regression

- Calculate the mean absolute error for regression

Picture of MD.Shoeb Lincoln
  Performance   Level  
Name: MD.Shoeb Lincoln <contact>
Classes: 1 package by
Country: Bangladesh Bangladesh
Age: ???
All time rank: Not yet ranked
Week rank: Not yet ranked

Instructions

Please read this document to learn how to process data to use in machine learning models.

Example

<?php
require_once 'vendor/autoload.php';

use
PHPML\Preprocessing\DataPreprocessor;
use
PHPML\Models\LinearRegression;
use
PHPML\Models\KMeans;
use
PHPML\Analysis\DataAnalyzer;
use
PHPML\Evaluation\ModelEvaluator;

// Sample data
 
$data = [
    [
1, 2, 3],
    [
2, 3, 4],
    [
3, 4, 5],
    [
4, 5, 6],
    [
5, 6, 7],
    [
6, 7, 8],
    [
7, 8, 9],
    [
8, 9, 10],
    [
9, 10, 11],
    [
10, 11, 12]
];

 
$labels = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

// Data preprocessing
 
$preprocessor = new DataPreprocessor($data);
 
$normalizedData = $preprocessor->normalize();
 
$standardizedData = $preprocessor->standardize();

// Linear Regression
 
$regression = new LinearRegression(0.01, 1000);
 
$regression->fit($normalizedData, $labels);
 
$predictions = $regression->predict($normalizedData);
 
$score = $regression->score($normalizedData, $labels);

echo
"Linear Regression Score: " . $score . "\n";

// K-Means Clustering
 
$kmeans = new KMeans(3, 100);
 
$centroids = $kmeans->fit($normalizedData);
 
$clusters = $kmeans->predict($normalizedData);

echo
"K-Means Centroids:\n";
print_r($centroids);

echo
"K-Means Clusters:\n";
print_r($clusters);

// Data Analysis
 
$analyzer = new DataAnalyzer($data);
 
$summary = $analyzer->getSummary();
 
$correlationMatrix = $analyzer->correlationMatrix();

echo
"Data Summary:\n";
print_r($summary);

echo
"Correlation Matrix:\n";
print_r($correlationMatrix);

// Model Evaluation
 
$accuracy = ModelEvaluator::accuracy($labels, $predictions);
 
$mse = ModelEvaluator::meanSquaredError($labels, $predictions);

echo
"Accuracy: " . $accuracy . "\n";
echo
"Mean Squared Error: " . $mse . "\n";


Details

phpML

opensource PHP machine learning project


  Files folder image Files (13)  
File Role Description
Files folder image.github (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file DataAnalyzer.php Class Class source
Plain text file Evaluation.php Class Class source
Accessible without login HTML file index.html Doc. Documentation
Accessible without login Plain text file index.php Example Example script
Plain text file KMeans.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Plain text file LinearRegression.php Class Class source
Plain text file ML.php Class Class source
Plain text file Models.php Class Class source
Plain text file Preprocessing.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (13)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (13)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file static.yml Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0