DelphiPythonPython GUIWindows

Build A Machine Learning Solutions With Scikit-Learn Library In A Delphi Windows App


Are you looking for an end-to-end open-source machine learning platform, and build a nice GUI for them? You can deliver enterprise-grade machine learning solutions easily by combining Scikit-Learn and Python4Delphi library, inside Delphi and C++Builder. And as a bonus, integrating Python with Delphi can speed up the execution time (read our other articles about TensorFlow and PyTorch). 

Scikit-Learn is an open-source Python library for machine learning. Scikit-Learn has simple and efficient tools for predictive data analysis that are built on top of SciPy, NumPy, and Matplotlib. Scikit-Learn features various classification, regression, and clustering algorithms including support vector machines, random forests, gradient boosting, k-means, and DBSCAN.

The Scikit-Learn project (formerly scikits.learn and also known as sklearn) was started in 2007 by David Cournapeau as a Google Summer of Code project, and since then many volunteers have contributed. Scikit-Learn is distributed under the 3-Clause BSD license.

This post will guide you on how to run the Scikit-Learn library and use Python for Delphi to display it in the Delphi Windows GUI app.First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.


Let’s try two interesting Scikit-Learn demos in Python GUI: Classifier comparison and Color Quantization using K-Means clustering.


Demo 1: Comparison between Classification Algorithms

This demo shows a performance comparison of several classifiers in scikit-learn on synthetic datasets. The point of this example is to illustrate the nature of decision boundaries of different classifiers.The following code for comparing classifiers is credited to Gaël Varoquaux, Andreas Müller, and Jaques Grobler (visit the source here).

The result in Python GUI:


Notes about the result:

The intuition conveyed by these examples does not necessarily carry over to real datasets. Particularly in high-dimensional spaces, data can more easily be separated linearly and the simplicity of classifiers such as naive Bayes and linear SVMs might lead to better generalization than is achieved by other classifiers.


Demo 2: Quantize Colors using K-Means Clustering

In this second demo, we perform a pixel-wise Vector Quantization (VQ) of an image of the summer palace (China), to reduce the number of colors required to show the image from 96,615 unique colors to 64, while preserving the overall appearance quality.

In this example, pixels are represented in a 3D-space and K-means clustering is used to find 64 color clusters. In the image processing literature, the codebook obtained from K-means (the cluster centers) is called the color palette. Using a single byte, up to 256 colors can be addressed, whereas an RGB encoding requires 3 bytes per pixel. The GIF file format, for example, uses such a palette.

For comparison, we also show a quantized image using a random codebook (colors picked up randomly).The following code for color quantization using K-Means is credited to Robert Layton, Olivier Grisel, and Mathieu Blondel (visit the original source here).

The result in Python GUI by Python4Delphi:



Congratulations, now you have learned how to run the Scikit-Learn library and use Python for Delphi to display it in the Delphi Windows GUI app. Now you can try a comprehensive guide to Machine Learning from these documentations using the Scikit-Learn library and Python4Delphi.

Check out the Scikit-Learn library for Python and use it in your projects: and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi:

Related posts
DelphiDelphiVCLPythonPython GUIWindows

What is DelphiVCL.Application.CreateHandle?

DelphiDelphiVCLPythonPython GUIWindows

Creating A New Application With DelphiVCL.Application.Create

DelphiDelphiVCLPythonPython GUIWindows

All You Need To Know About Application.DialogHandle

DelphiDelphiVCLPythonPython GUIWindows

What is the FieldAddress Property in DelphiVCL.Application?

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *