DelphiPythonPython GUIWindows

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

pexels manuel geissinger 325229

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 script 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.

0 rundemo1 6813476

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 in Reference [4]).

The result in Python GUI:

2comparisonsbetweenclassifiers 8182763

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 in Reference [2]).

The result in Python GUI by Python4Delphi:

3colorquantization 3245932

 

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: https://pypi.org/project/scikit-learn/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

 

References & further readings

[1] Buitinck, L., Louppe, G., Blondel, M., Pedregosa, F., Mueller, A., Grisel, O., … & Varoquaux, G. (2013). API design for machine learning software: experiences from the scikit-learn project. arXiv preprint arXiv:1309.0238.

[2] Layton, R., Grisel, O., & Blondel, M. (2007-2023). Color Quantization using K-Means. Scikit-learn developers. scikit-learn.org/stable/auto_examples/cluster/plot_color_quantization.html

[3] Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., … & Duchesnay, E. (2011). Scikit-learn: Machine learning in Python. The Journal of machine Learning research, 12, 2825-2830.

[4] Varoquaux, G., Müller, A., & Grobler, J. (2007-2023). Classifier comparison. Scikit-learn developers. scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html

Related posts
CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Radial Basis Function Networks (RBFNs)

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

CodeIDELearn PythonPythonPython GUITkinter

How To Make 20 ChatGPT Prompts Work With Python GUI Builders And Matplotlib Library?

Leave a Reply

Your email address will not be published. Required fields are marked *