blog
Development

Machine learning & PHP

back
Dev

4 min read

February 27, 2022

Wondering how you can enable machine learning just with PHP? Here are a couple of ideas for PHP libraries making that possible.

Let’s start by explaining what machine learning (ML) is. ML is a form of artificial intelligence (AI) where algorithms, with the use of data are trained to perform tasks learning to become more accurate in their predictions. Unlike traditional programming where rules are programmed, ML allows systems to automatically learn and enhance from their own experience, not by being instructed to do exact tasks.

Machine Learning predominantly focuses on developing computer programs that can learn for themselves from data that they have access to. This form of AI is important as it gives enterprises a view of trends in customer behavior and business operational patterns, and greatly supports the development of new products. Over time, these algorithms powered by ML can acquire associations and facilitate the tailoring of product development to exactly what customers are looking for.

Types of machine learning

As mentioned above, classical machine learning is providing an algorithm with data and allowing it to learn to become more accurate in its predictions. There are four types of ML: supervised learning, unsupervised learning, semi-supervised learning and reinforcement learning. The type of algorithm data that is applied depends on what type of data is to be predicted.

In supervised learning both the input and the output of the algorithm is specified. Specific data is supplied to the algorithms and the variables to be assessed for correlations by the algorithm, is specified. Unsupervised learning on the other hand involves work with unlabeled data. Algorithms scan through data sets looking for any meaningful correlations. The data along with the predictions the algorithms output, are predetermined.

Semi-supervised learning is a mix of supervised and unsupervised learning. I this type of machine learning, data scientists feed an algorithm mostly labeled data, but the outcome is not predetermined. The model is free to explore the data on its own and develop its own understanding of the input data.

Reinforcement learning is often used to teach a model to complete a multi-step process which has clear, defined rules. This type of machine learning is provided with a programed algorithm to complete a task, giving it a positive or negative cue as it works out how to complete a task. For the most part, the algorithm decides on solving the problem on its own.

Who’s using it and what is it used for

Familiar with Facebook? Then you’ve seen machine learning in action, that’s what powers Facebook’s news feed. If you’ve ever wondered how your personalized feed is delivered, here’s how it works with the help of ML and artificial intelligence. If you tend to stop and read a certain person’s or groups posts, you will soon be shown more post of that person our group and if you continue to be interested in their content you will shortly be one of the first to see their newest posts.

Behind the scenes, the engine is attempting to reinforce patterns in your online behavior. Should you change patterns and fail to read posts from that individual or group in the coming weeks, your news feed will adjust accordingly — this is machine learning.

Other uses for machine learning

While machine learning is a recommendation engine it has other uses as well. ML is used for CRM (Customer relationship management). CRM software is capable of using machine learning models to analyze email and prompt members of the sales team to respond to the most important messages first. While systems that are more advanced can even provide potentially effective responses.

  • Business intelligence. BI and analytics vendors are known to use machine learning in their software in order to identify potentially important data points, patterns of data points and anomalies.
  • Human resource information systems (HRIS) use machine learning to filter through applications and determine the best candidates for a position.
  • Self-driving cars. Machine learning algorithms have made it possible for semi-autonomous cars to recognize partially visible objects and alert the driver.
  • Virtual assistants. Such as Siri or Bixby usually combine supervised and unsupervised machine learning models to interpret natural speech and provide context.

PHP Libraries

Not so long ago, while I was exploring the idea of artificial intelligence and machine learning, Python was the language I took into consideration. This language is heavily used for machine learning, AI as well as data science I believed it was the right choice to use to attain my set goals.

However, after doing some research I came to understand that PHP can also be used for machine learning with the right library. PHP becomes faster and faster with every version that comes out and there are libraries such as Rubix ML or PHP-ml which can be used for machine learning and artificial intelligence.

The Rubix ML is a machine learning library which is open-source, this means it is free to use. This library includes implementations of several machine learning algorithms and allows you to build programs that learn from your data, using PHP as a language. Some of Rubix ML provides tools for the entire machine learning life cycle from ETL (extracting, transforming, loading, manipulating and summarising data) to training, cross-validation, and production with over 40 supervised and unsupervised learning algorithms.

PHP-ml is another library that can be used for ML but, unfortunately, it is no longer being developed. Both PHP-ml and RubixML libraries have a lot of functionalities for:

  • Clarification — image recognition or advanced text analysis
  • Regression — prediction of continuous-valued outcomes, for example the estimation of product prices
  • Clustering — a weaker form of classification. The grouping of elements where labels are unknown based on their similarities

Besides libraries, AWS (Amazon Web Services) can also be used for machine learning. AWS provide a lot of different services for ML like Amazon SageMaker, Amazon Kendra, Amazon Comprehend, Amazon Rekognition, Amazon Forecast, and many, many more.

AWS provides full SDK (software development kit) for PHP so one can feel free to use all those services in their PHP project.

So, while one would like to think Python is the best choice, there are other languages and libraries that support ML and AI. With the available possibilities, it may not be that simple to select and apply a language. However, whatever you decide to use, take advantage of all its available and relevant features, while keeping the above-mentioned ML learning types and your end goal in mind.

Created by

Dariusz Żelasko

CTO

Read more

Dev

Julia Haleniuk

Back-End Developer

4 min read
August 8, 2022

Is PHP Going To Die In 2023?

Is PHP Going To Die In 2023? In 2010, PHP was ranked as the third most widely used programming language, by Tiobe. In June 2022 PHP's position dropped to thirteenth place. Is it a significant evidence that PHP is slowly dying,

Dev

Julia Haleniuk

Back-End Developer

6 min read
August 1, 2022

Cypress – What Is It And What Should You Know About It?

Cypress, or Cypress framework: what is it exactly? What can it help you with? When to use it? And more importantly – how to use it? This informative introduction will give you a head start on this topic.

Dev

Julia Haleniuk

Back-End Developer

5 min read
July 25, 2022

Software Development For Startups: In-house Development Or Outsourcing?

Many successful products we know today have started as startups with just an idea. But is it just good enough to succeed? To avoid being too optimistic, let's look at some data. In the US, each month, 543,000 new companies are established.