AI (artificial intelligence) is popular, but we will understand what artificial intelligence, machine learning, and deep learning are like while actually moving them. However, we'll just get a feel for what it's like, so we'll leverage the library framework instead of implementing it from scratch.
――People studying artificial intelligence from now on --People who want to know the difference between artificial intelligence, machine learning, and deep learning
--Understand the relationship between artificial intelligence, machine learning, and deep learning ――I can imagine what artificial intelligence, machine learning, and deep learning are like.
Think about what artificial intelligence is in the first place. "[Does artificial intelligence surpass humans?](Https://www.amazon.co.jp/%E4%BA%BA%E5%B7%A5%E7%9F%A5%E8%83%BD%E3% 81% AF% E4% BA% BA% E9% 96% 93% E3% 82% 92% E8% B6% 85% E3% 81% 88% E3% 82% 8B% E3% 81% 8B-% E3% 83 % 87% E3% 82% A3% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 83% BC% E3% 83% 8B% E3% 83% B3% E3% 82% B0 % E3% 81% AE% E5% 85% 88% E3% 81% AB% E3% 81% 82% E3% 82% 8B% E3% 82% 82% E3% 81% AE-% E8% A7% 92% E5% B7% 9DEPUB% E9% 81% B8% E6% 9B% B8-% E6% 9D% BE% E5% B0% BE-% E8% B1% 8A / dp / 4040800206) ”explains as follows: It has been.
True artificial intelligence-that is, a "computer that thinks like a human" has not been created.
In other words, the technology that seems to be acting like a human being is generally called ** artificial intelligence **. Furthermore, the definition of artificial intelligence itself has not been established among experts.
What is called artificial intelligence in the world can be divided into four levels: "[Does artificial intelligence exceed humans](https://www.amazon.co.jp/%E4%BA%BA%E5%B7] % A5% E7% 9F% A5% E8% 83% BD% E3% 81% AF% E4% BA% BA% E9% 96% 93% E3% 82% 92% E8% B6% 85% E3% 81% 88 % E3% 82% 8B% E3% 81% 8B-% E3% 83% 87% E3% 82% A3% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 83% BC% E3% 83% 8B% E3% 83% B3% E3% 82% B0% E3% 81% AE% E5% 85% 88% E3% 81% AB% E3% 81% 82% E3% 82% 8B% E3% 82% 82% E3% 81% AE-% E8% A7% 92% E5% B7% 9DEPUB% E9% 81% B8% E6% 9B% B8-% E6% 9D% BE% E5% B0% BE-% E8 % B1% 8A / dp / 4040800206) ”.
--Level 1: ** Simple control program (control engineering) ** ――It is called "AI" in marketing. --Belonging to the fields of control engineering and system engineering
--Level 2: ** Classic artificial intelligence ** ――It is from this level that it is being researched as artificial intelligence --Various behavior patterns --Inference, search, knowledge base, etc. --Do not learn by yourself
--Level 3: ** Machine learning ** --The relationship between input and output is learned based on the data --Learn by yourself
--Level 4: ** Deep Learning ** --Learning features for learning from data
Artificial intelligence, machine learning, and deep learning are as follows.
--Artificial intelligence: One field (definition itself is ambiguous) --Machine learning: A collection of methods that realize artificial intelligence that the program itself learns --Deep learning: A deeper layer of neural networks, which is one of the machine learning methods.
The relationship between artificial intelligence / machine learning / deep learning and artificial intelligence by level is as shown in the figure.
Let's actually move it. It will be Level 2, Level 3, and Level 4 artificial intelligence to be implemented. At each level, the correct answer rate (0.0 to 1.0) is calculated as a score.
First, let's talk about the data that artificial intelligence predicts. Use the iris dataset from scikit-learn.
Artificial intelligence predicts the result from the input data (features). This time, there are 3 varieties of irises to predict, and we will predict which iris to use. The features for prediction are as follows.
--The length of the calyx --Width of calyx --Petal length --Petal width
Let's take a look at the contents of the data. The last target column is the name of the iris.
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) target
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
5 5.4 3.9 1.7 0.4 setosa
6 4.6 3.4 1.4 0.3 setosa
7 5.0 3.4 1.5 0.2 setosa
8 4.4 2.9 1.4 0.2 setosa
9 4.9 3.1 1.5 0.1 setosa
First, we will implement classical artificial intelligence. This time, I found a trend from the data and put in some simple knowledge.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
#Data import
iris = load_iris()
#Divide into features and objective variables
X = iris['data']
y = iris['target']
#Divide into data to be trained and data to measure the accuracy of the trained model
#Level 2 implementation does not learn by itself, so only data that measures accuracy is used
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
#A function with embedded rules (knowledge) to predict
#Predict by branching according to the feature value
def predict_iris(feature):
if feature[2] < 2 and feature[3] < 0.6:
return 0
elif 2 <= feature[2] < 5 and 0.6 <= feature[3] < 1.7:
return 1
else:
return 2
#Function to measure score
def compute_score(pred, ans):
correct_answer_num = 0
for p, a in zip(pred, ans):
if p == a:
correct_answer_num += 1
return correct_answer_num / len(pred)
pred = []
for feature in X_test:
pred.append(predict_iris(feature))
score = compute_score(pred, y_test)
print('Score is', score)
result
Score is 0.9555555555555556
Next, we will implement machine learning. In machine learning, a program learns from data.
The algorithm used this time is logistic regression, which uses the Python machine learning library scikit-learn
.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
#Data import
iris = load_iris()
#Divide into features and objective variables
X = iris['data']
y = iris['target']
#Divide into data to be trained and data to measure the accuracy of the trained model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
#The algorithm used is logistic regression
model = LogisticRegression()
#Learning
model.fit(X_train, y_train)
#Score measurement
score = model.score(X_test, y_test)
print('Score is', score)
result
Score is 0.8888888888888888
Finally, the implementation of deep learning. In deep learning, a program generates features from data and learns them.
The deep learning implemented this time will be a neural network consisting of 5 layers. The library to use will be keras
.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from keras import layers
from keras import models
from keras.utils import np_utils
#Data import
iris = load_iris()
#Divide into features and objective variables
X = iris['data']
y = np_utils.to_categorical(iris['target'])
#Divide into data to be trained and data to measure the accuracy of the trained model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
#Define a model of a 5-layer neural network
model = models.Sequential()
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(3, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
#Learning
model.fit(X_train, y_train, epochs=10, batch_size=10)
#Score measurement
score = model.evaluate(X_test, y_test)
print('Score is', score[1])
result
Score is 0.8888888955116272
Artificial intelligence, machine learning, and deep learning had the following meanings.
--Artificial intelligence: Field (definition itself is ambiguous) --Machine learning: A collection of methods to realize artificial intelligence that the program itself learns --Deep learning: One of the machine learning methods
For each score, the result was that the simplest rule base was high. However, please note that this time the data was very simple, so the true value of machine learning and deep learning has not been demonstrated.
Artificial intelligence / AI has become a hot topic these days, but I felt that what I wanted to do (purpose) was more important than means (whether it was AI or not).
-[Is artificial intelligence surpassing humans](https://www.amazon.co.jp/%E4%BA%BA%E5%B7%A5%E7%9F%A5%E8%83%BD%E3% 81% AF% E4% BA% BA% E9% 96% 93% E3% 82% 92% E8% B6% 85% E3% 81% 88% E3% 82% 8B% E3% 81% 8B-% E3% 83 % 87% E3% 82% A3% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 83% BC% E3% 83% 8B% E3% 83% B3% E3% 82% B0 % E3% 81% AE% E5% 85% 88% E3% 81% AB% E3% 81% 82% E3% 82% 8B% E3% 82% 82% E3% 81% AE-% E8% A7% 92% E5% B7% 9DEPUB% E9% 81% B8% E6% 9B% B8-% E6% 9D% BE% E5% B0% BE-% E8% B1% 8A / dp / 4040800206) -[Deep Learning Textbook Deep Learning G Test (Generalist) Official Text](https://www.amazon.co.jp/%E6%B7%B1%E5%B1%A4%E5%AD%A6%E7%BF % 92% E6% 95% 99% E7% A7% 91% E6% 9B% B8-% E3% 83% 87% E3% 82% A3% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 83% BC% E3% 83% 8B% E3% 83% B3% E3% 82% B0-G% E6% A4% 9C% E5% AE% 9A-% E3% 82% B8% E3% 82 % A7% E3% 83% 8D% E3% 83% A9% E3% 83% AA% E3% 82% B9% E3% 83% 88-% E5% 85% AC% E5% BC% 8F% E3% 83% 86% E3% 82% AD% E3% 82% B9% E3% 83% 88 / dp / 4798157554)
Recommended Posts