Machine Learning with Python

Machine Learning with Python

How implement Machine Learning algorithms with Python?

Python is also one of the most used programming languages ​​in the world.

In fact, this language offers essential libraries for making statistics, for processing images or even for data analysis.

Furthermore, Python is characterized by having a simple but feature-rich syntax. Certainly being an interpreted language it has a lower execution speed but many of its modules have been developed in C language.

Recall that Machine Learning is a branch of Artificial Intelligence and studies algorithms that are able to process the input data and then be able to make predictions. Today, these algorithms are very useful if you think about the large amount of data that exists on the web and offer an alternative to traditional algorithms.

The development community around Machine Learning in Python is increasingly large and therefore it is easy to find information or tutorials to get explanations. The modules and libraries are in large quantities and we will see them in detail in the next paragraph.

So we just have to start studying and have fun putting into practice what we have learned!

Machine Learning with Python – What Tools Do You Need?

So what are the tools we need in Pytnon?

Jupiter Notebook

First of all, a development environment like Jupyter Notebook, very easy to download and install.

In fact, on the installation page you will find the instructions:

pip install notebook

To execute it, just type:

jupyter notebook

Numpy

A module that allows you to do Machine Learning with Python is Numpy.

In fact, thanks to the many properties and methods for scientific calculation, it allows you to easily work with arrays and matrices.

It simply installs like this:

pip install numpy

In Linux systems it is necessary to write:

sudo apt-get install python3-numpy

The installation will not last long.

It is then used in Python scripts simply by writing:

import numpy

Pandas

One tool that allows you to easily manage DataFrame and Series is the Pandas library.

To install it simply write:

pip install pandas

It is then called in Python scripts like this:

import pandas

Matplotlib e Seaborn

As a tool for machine learning in Python, the Matplotlib and Seaborn libraries cannot be missing, which allow you to graphically view the processed data.

Installation takes place by writing on the command line:

pip install matplotlib 

and we import it as before using import:

pip install seaborn

To be able to use them then I write:

import matplotlib

We then use import as usual:

import seaborn

Scikit-learn

The scikit-learn library implements Machine in Learning algorithms with Python.

Intuitively, the installation takes place as follows:

pip install scikit-learn

To use it, therefore, we import it:

import scikit-learn

Tensorflow

The tensorflow library implements Machine in Learning and Deep Learning algorithms in Python.

pip install tensorflow

We then import the library to be able to use it for our Python scripts:

import tensorflow

Conclusion

We have listed only some of the modules to do Machine Learning in Python, there are others that we will talk about later in the guide.

If you already have some basic Python I suggest you choose the module you don’t know, otherwise start with the basics. Here, then, is the link to the complete tutorial: Python language tutorial index.

Some useful links

Python lambda function

Use Python dictionaries

Python readline()

Python max()

Break Python

Insertion Sort

Merge Sort

Machine Learning Python

Machine Learning Python

Il linguaggio più utilizzato oggi per implementare gli algoritmi di Machine Learning è proprio Python, ed è anche uno dei linguaggi di programmazione più utilizzato al mondo.

Infatti questo linguaggio offre delle librerie essenziali per fare statistiche, per elaborare le immagini o ancora per l’analisi dei dati.

Inoltre Python si caratterizza per avere una sintassi semplice ma ricca di funzionalità. Sicuramente essendo un linguaggio interpretato ha una velocità di esecuzione inferiore ma molti dei suoi moduli sono stati sviluppati in linguaggio C.

Ricordiamo che il Machine Learning è un ramo dell’Intelligenza Artificiale e studia algoritmi che sono in grado di elaborare i dati in input e poter poi effettuare delle previsioni. Oggi, questi algoritmi sono molto utili se si pensa alla grande quantità di dati che ci sono nel web e offrono un’alternativa agli algoritmi tradizionali.

La comunità di sviluppo che sta attorno al Machine Learning in Python è sempre più ampia e dunque è semplice reperire informazioni o tutorial per ottenere spiegazioni. I moduli e le librerie sono in grande quantità e li vedremo in dettaglio nel prossimo paragrafo.

Non ci rimane dunque che iniziare a studiare e divertirci a mettere in pratica quanto appreso!

Machine Learning Python – Quali strumenti servono?

Quali sono allora gli strumenti che ci servono in Pytnon?

Jupiter Notebook

Innanzitutto un ambiente di sviluppo come Jupyter Notebook, molto semplice da scaricare ed installare.

Nella pagina di installazione infatti troverete le istruzioni:

pip install notebook

Per l’esecuzione basterà digitare:

jupyter notebook

Numpy

Un modulo che consente di fare Machine Learning in Python è Numpy.

Infatti, grazie alle tante proprietà e metodi per il calcolo scientifico consente di lavorare facilmente con array e matrici.

Si installa semplicemente così:

pip install numpy

Nei sistemi Linux occorre scrivere:

sudo apt-get install python3-numpy

L’installazione non durerà molto.

Si utilizza poi negli script Python semplicemente scrivendo:

import numpy

Pandas

Uno strumento che consente di gestire facilmente DataFrame e Series è la libreria Pandas.

Per installarla basterà semplicemente scrivere:

pip install pandas

Si richiama poi negli script Python in questo modo:

import pandas

Matplotlib e Seaborn

Come strumento per il machine learning in Python non possono mancare le librerie Matplotlib e Seaborn che consentono di visualizzare graficamente i dati elaborati.

L’installazione avviene scrivendo nella linea di comando:

pip install matplotlib 

e la importiamo come prima utilizzando import:

pip install seaborn

Per poterle utilizzare poi scrivo:

import matplotlib

Utilizziamo poi come al solito import:

import seaborn

Scikit-learn

La libreria scikit-learn implementa gli algoritmi di Machine in Learning in Python.

Intuitivamente l’installazione avviene in questo modo:

pip install scikit-learn

Per utilizzarla, dunque, la importiamo:

import scikit-learn

Tensorflow

La libreria tensorflow implementa gli algoritmi di Machine in Learning e Deep Learning in Python.

pip install tensorflow

Importiamo poi la libreria per poterla utilizzare per i nostri script in Python

import tensorflow

Conclusioni

Abbiamo elencato solo alcuni dei moduli per fare Machine Learning in Python, ce ne sono altri di cui parleremo più avanti nella guida.

Se avete già delle basi di Python vi consiglio di scegliere il modulo che non conoscente, altrimenti iniziate dalle basi. Ecco, dunque, il link al tutorial completo: Indice tutorial sul linguaggio Python.

Alcuni link utili

1 – Introduzione al linguaggio Python

2 – Le variabili

3 – Operatori aritmetici e di assegnazione

4 – Stringhe

5 – Casting

6 – Input e print

Machine Learning

Machine Learning

Today we often hear about Machine Learning and Artificial Intelligence. Machine Learning algorithms are currently used in various fields. For example, we find applications in online shopping, in interactions with social media, in financial services, in health care, in the marketing sector to manage targeted advertising, etc.

Therefore it is essential to know the term of Machine Learning and understand where it is applied.

Machine Learning definition

Machine Learning, abbreviated ML, is a branch of Artificial Intelligence. The basic idea is that robots (or more generally systems) can perform actions as if they were humans or animals.

Knowledge is acquired through machine learning programs, as with humans who acquire knowledge based on experience.

Machine Learning algorithms use mathematical-computational methods that analyze data thanks to which the construction of analytical models is automated.

Machine Learning example

After giving the definition of Machine Learning, let’s analyze some examples.

Let’s first look at this simple artificial intelligence program created on the Program the Future site: Artificial Intelligence for the sea.

After logging in at the time of the code, start the game which is based on the identification of waste by an Artificial Intelligence.

You will therefore be presented with an AI that must be trained. In fact, the Artificial Intelligence does not know if an object is a fish or a waste but we can give it instructions, labeling images or diagrams.

Each image can be labeled as fish or as waste. This acts as training and will then allow the Artificial Intelligence to recognize a refusal from a fish when new images are presented to it.

Machine Learning algorithms

We continue, in the context of Machine Learning, to give some other definitions by presenting the algorithms that determine the approach to a given problem.

The main types of algorithms are:

  • Supervised
  • Unsupervised
  • Semi supervised
  • For reinforcement

What is the difference? Simply in the way they acquire data to make predictions.

Supervised learning

In this type of algorithm, which is the most used one of Machine Learning algorithms, learning is managed just like a child memorizes animals by looking at some example images. As in the example seen on Program the future, where Artificial Intelligence is educated with images.

The algortimo therefore learns from a labeled data set. For example, this can be used in marketing, identifying products that the user may like based on the images he or she has chosen in the past. It is therefore based on experience.

Among these algorithms we will study, later in the guide, the linear and logistic regression algorithms.

Unsupervised learning

Unsupervised learning, on the other hand, is a Machine Learning alghoritm used on data that does not have a classification, that is, on non-labeled data.

Therefore, the right answer is not provided but the goal is to leave the algorithm to search for hidden characteristics or data.

The use of this algorithm occurs above all with transactional data. So, for example, the algorithm can identify users who have similar needs to address ad hoc marketing campaigns. In fact, by analyzing this data, for us human beings there may not be a sense that the algorithm is able to give.

Let’s take a purely explanatory example: the algorithm could identify that the population that buys more organic food needs less medical care (because for example they never buy drugs), therefore the algorithm could recommend a greater purchase of organic food, to safeguard health, to the people who need it most.

Semi Supervised Machine Learning

As we can easily guess, it is a ‘hybrid’ model that has the same applications as the supervised model, that is, a set of data is provided where certain inputs correspond to outputs, but also data with no output as in the unsupervised one.

An example of application is found for example in cameras that are able to identify a human face.

Machine Learning for Reinforcement

In this case we move on to a reinforcement learning according to which we learn from experiments and errors to reach a goal. The idea is to improve the functionality of the system by reinforcement, that is, the reward. Kind of like when you promise children candy if they reach a goal.

So when you reach the goal you have a reward, while if you don’t reach it, you don’t give anything or give you a punishment. The aim is to maximize the rewards by choosing the correct actions.

This type of approach is used in robotics and video games for example where a computer learns to beat an opponent based on the moves that have given him the most benefits previously.

Deep Learning algorithms are part of it.

Conclusion

In this lesson we talked about Machine Learning and we gave its definition by also talking about the different algorithms used in this sector. In future lessons I will continue to talk about this topic again.

Some useful links

Python lambda function

Use Python dictionaries

Python readline()

Python max()

Break Python

Insertion Sort

Merge Sort