Skip to main content

Artificial intelligence a pragmatic introduction 🧠

·1432 words·7 mins
Table of Contents

Je veux te voir
Je veux t’avoir

It was only a matter of time before I started talking about artificial intelligence.

The entire world is buzzing about AI, and the new ways it’s being implemented in our everyday lives are truly impressive. Just look at how AI can now generate stunning images based on simple prompts, like this one.

AI

This image was created by Dall-E, a new AI system developed by OpenAI (one of the leading companies in AI development). OpenAI recently released another powerful tool called SORA, which can create incredible videos based on simple descriptions. Check out the video below!

It’s truly amazing to see all this new advancement in AI happening around the world.

However, despite the buzz, many people discuss using AI without fully understanding its core principles. In this first post about AI, we’ll aim to provide a basic understanding of what AI is and how anyone can grasp its fundamental concepts. We’ll keep things simple for now, but delve deeper into specifics in future posts.

What is AI? 🤔
#

The internet and books offer a wealth of AI definitions. For this post, let’s explore the common definition you’d find on Wikipedia.

… It is a discipline and a set of cognitive and intellectual capabilities expressed by computer systems or combinations of algorithms whose purpose is the creation of machines that mimic human intelligence to perform tasks …
AI - Wikipedia 🥸

Understanding AI can be simplified with a visual aid, like the one below.

AI

As we’ve seen, AI is a complex field that draws from many disciplines. While the previous definition and diagram offer a starting point, a deeper understanding can be achieved.

Some experts (experts = Rivaldito🥸) suggest that AI can be broken down into three key components:

  • Geometry
  • Mathematics
  • Programming

AI

It might seem simplistic to say AI is just these three things, but each plays a vital role.

Why AI = 📐 + 🧮 + 💻?
#

Now, let’s explore another concept: ‘Everything is data.’ This might sound strange at first, but the idea is that we can represent anything with numbers. Numbers can be used to encode information about objects, events, and even concepts.

AI

Maybe it seems weird the first time we see this relation, but think in this way, we can assign a number to represent anything. I will give you some examples so that you can understand me.

Movement, and easy one 🚀
#

At some point in our school or college life we learned in physics class that movement can be represented by equation or equation matrix like the following example:

AI

Let’s look at another example of how life is data…

Images 📷
#

Have you ever wondered how your phone represents an image after you take a picture? It’s a complex process, but let’s break it down simply.

Your phone can decompose the color information of a picture into separate color layers. The most common way to do this is with three channels: red, green, and blue. This color decomposition is known as RGB (Red, Green, Blue).

Each layer is a matrix of tiny squares called pixels. Each pixel contains a single number representing the intensity of that specific color at that location in the image. A higher number indicates a stronger presence of that color in that pixel, while a lower number means the color is less present.

AI

Words 📑
#

Perhaps the most surprising example for me was assigning numbers to words. It might seem strange, but there are many approaches to this.

One method involves assigning a number to a word based on the previous word.

We could continue listing examples, but I believe the general idea is clear. Assigning a number to anything essentially translates it into data.

Okay, data…and now what? 🤔
#

Now that we have data, the next step is to put it into a vector space to begin working with AI.

AI

These vector spaces are usually limited to three dimensions, which we can easily visualize. Fortunately, computers can handle even higher dimensions.

Geometry
#

Once we have our data in a vector space, we can start applying geometric concepts – essentially, drawing lines and figures – for two main purposes:

  • Estimation: This involves drawing lines to make predictions. For example, we might predict house prices over time based on historical data, or even rainfall patterns based on specific climate conditions.

AI

  • Classification: Here, we draw figures to group similar data points. This allows us to predict a specific value based on others. For instance, we could classify images as cats or dogs, or identify different types of flowers based on their features.

AI

Maths
#

We have the data in vector space, but now how do we do the Geometry (draws)?

We do this with mathematical models, ands looks like:

It can be intimidating at first, but the good news is that many of these models have been studied for centuries. The underlying mathematics is largely established, and computers can handle the complex calculations for us.

In essence, the groundwork has been laid. We just need to put the pieces together.

Programming: Putting the Pieces Together
#

This is where the magic happens! We leverage the power of computers to perform the geometric calculations and mathematical manipulations required for AI. Python is a popular choice for AI development due to its large and active community. Over the years, this community has created numerous libraries and frameworks that simplify AI development.

Some of these tools are:

Think of it like Legos – we don’t need to build every brick from scratch. Instead, we have a vast collection of pre-built components that we can assemble to create our AI solutions. This is a significant improvement compared to the past, where developers had to build everything from the ground up.

Let’s write some code.
#

I dont explain much in detail about the code. I just whan to show how simple it is.

Our first model 🌺
#

For our first AI model we use the iris dataset.

This is one of the earliest datasets used in the literature on classification methods and widely used in statistics and machine learning. The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant.

The iris we are working with it are:

AI

The dataset take the length and the width of the sepal and petal of each flower of the plant.

AI

Like I wrote before, I don’t gonna explain the code, I’ll only show a brief notation of how creating IA is like playing lego.

You can see the entire code in this github repository.

Import the libraries
#

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

import mpl_toolkits.mplot3d  # noqa: F401
from sklearn.decomposition import PCA

%matplotlib inline

from sklearn.datasets import load_iris
iris_data = load_iris()

See the data set
#

iris_df = pd.DataFrame(data = iris_data['data'], columns = iris_data['feature_names'])
iris_df.head()

Plot
#

# im just making a function in order not to repeat the same code
def plot_violin(y2,i):
    plt.subplot(2,2,i)

    sns.violinplot(x='Iris name',y= y2, data=iris_df)

plt.figure(figsize=(17,12))
i = 1
for measurement in iris_df.columns[:-2]:
    plot_violin(measurement,i)
    sns.despine(offset=10, trim=True)
    i += 1

AI

Plot, again…
#

sns.pairplot(iris_df, hue = 'Iris name', vars = ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'], palette = 'Set1' );

AI

Train the model
#

knn.fit(X_train, y_train)

Make predictions
#

y_pred = knn.predict(X_test)

fig = plt.figure(figsize=(15,7))

ax1 = fig.add_subplot(1,2,1)
ax1 = sns.scatterplot(x = X_test['petal length (cm)'], y = X_test['petal width (cm)'], hue = y_pred, alpha = 0.5)
plt.title('Predicted')
plt.legend(title='Iris name')

ax2 = fig.add_subplot(1,2,2)
ax2 = sns.scatterplot(x = X_test['petal length (cm)'], y = X_test['petal width (cm)'], hue = y_test, alpha = 0.5)
plt.title('Actual');

AI

And that ’s all. Easy right?

In the following posts, we will go into more detail about AI.

The songs of the post
#

This time I recommend one of my favorite bands, La femme. They have a unique sound, and they are always experimenting with new things, each album is different from the last.

Je veux te voir, je veux t’avoir
New York dans le night club, tu t’es rapprochée de moi
Je ne veux pas oublier le contact de ta peau
Ton sourire et ton rire c’est comme si on se connaissait déjà
Quand on s’est mis à danser, tu m’as donné un baiser
De crystal à déposer là sur la langue
Elle fait sauter son top en jean
Je crève en voyant sa poitrine

Tatiana - La femme