The difference between deep learning and machine learning

The difference between deep learning and machine learning

Contents of this article:

1. Feature extraction

1.1. Machine Learning

1.2. Deep Learning

1.3. Machine Learning Feature Extraction

1.4, deep learning feature extraction

1.5. Example of deep learning feature extraction

2. Data volume and computing performance requirements

3. Algorithm representative

3.1. Naive Bayes algorithm

3.2. Decision tree

4. Neural Network


1. Feature extraction

 1.1. Machine learning

  Machine learning is an artificial intelligence technique that, given a data set, automatically learns patterns and uses the learning results to predict or make decisions. It relies on mathematical and statistical algorithms to build models that allow computers to learn autonomously without being explicitly programmed.

  Machine learning is a branch of artificial intelligence that refers to the ability of computer systems to automatically identify and predict patterns by analyzing and learning from large amounts of data.

  In simple terms, machine learning is to let computers learn from data to perform tasks at the level of human intelligence.

  Here are some commonly used concepts in machine learning:

  1. Dataset: Refers to the data used to train and test machine learning algorithms.
  2. Features: Refers to the description of the data set, which can be in digital or text format.
  3. Model: A concrete implementation of a machine learning algorithm that can be trained based on features and target values.
  4. Supervised learning: predicting the output of unknown data by training the matching of input data and known results.
  5. Unsupervised learning: discovering patterns in unlabeled data to infer the structure and relationships of the data.
  6. Deep Learning: A neural network-based machine learning technology that can simulate the neural network structure of the human brain and use multiple hidden layers to learn and classify data.

  Machine learning is widely used in many fields, such as e-commerce, finance, healthcare, natural language processing, computer vision, and autonomous vehicles, among others. Common machine learning algorithms include decision trees, logistic regression, support vector machines, neural networks, and random forests.

  The feature engineering step of machine learning is done manually and requires a lot of domain expertise.

1.2. Deep Learning

   Deep learning is a method of machine learning that uses neural networks composed of multiple layers to simulate and solve complex problems. Its core idea is to gradually improve the model's ability to represent and predict data through hierarchical learning and feature extraction. In deep learning, the core technologies include backpropagation algorithm, convolutional neural network, recurrent neural network, generative confrontation network, etc. Deep learning has a wide range of application scenarios, such as image recognition, speech recognition, natural language processing, artificial intelligence and other fields.

  Deep learning typically consists of multiple layers, which often combine simpler models, passing data from one layer to another to build more complex models. The model is automatically obtained by training a large amount of data, without the need for manual feature extraction.

  Deep learning algorithms try to learn high-level features from data, which is a very unique part of deep learning. Thus, the task of developing a new feature extractor for each problem is reduced. It is suitable for image, speech, and natural language processing fields that are difficult to extract features.

1.3. Machine Learning Feature Extraction

  Machine learning feature extraction refers to extracting useful features from raw data for training of machine learning algorithms and establishment of models. These features can be numerical values, text, images or even sounds. Through feature extraction, it can help machine learning algorithms to better understand data and achieve better data analysis and classification.

  The goal of feature extraction is to find a set of features that best represent the data, and these features can enable machine learning algorithms to learn more meaningful information from the data.

  The process of feature extraction includes steps such as data preprocessing, feature selection, feature extraction and feature representation. In these processes, factors such as the type, quantity, quality and distribution of data, as well as the applicability and demand of machine learning algorithms need to be considered.

1.4, deep learning feature extraction

  Deep learning feature extraction refers to the process of using the deep neural network model to automatically learn and extract features from the original data, so that the original data can be better represented as a set of high-level, abstract features, which can be better applied to classification and recognition. , detection and other tasks.

  Deep learning feature extraction is widely used in computer vision, natural language processing, speech recognition and other fields. The specific methods of deep learning feature extraction include convolutional neural network (CNN), recurrent neural network (RNN) and so on. By using deep neural networks to extract features from data, the accuracy and robustness of the model can be greatly improved.

  Deep learning can learn complex features of input data by stacking multiple layers of neural networks.

  In deep learning, each layer of neural network can be regarded as a mapping of input data, and the output of each layer can be used as the input of the next layer. By continuously stacking multiple layers of neural networks and training the weights, more complex features can be gradually extracted to achieve more accurate classification and prediction.

1.5. Example of deep learning feature extraction

  The following is a deep learning model implemented using Keras to classify handwritten digits.

  The model contains two convolutional layers and two fully connected layers, which can automatically learn to extract the features of handwritten digits and classify them as one of the digits 0 to 9. 

import numpy as np
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D
from keras.utils import np_utils

# Load the MNIST dataset and preprocess it 

# 加载MNIST数据集并进行预处理
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1).astype('float32') / 255
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1).astype('float32') / 255
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)

# Build a deep learning model 

# 构建深度学习模型
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))

# Compile the model 

# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# train the model and evaluate the performance

# 训练模型并评估性能
model.fit(X_train, y_train, epochs=10, batch_size=32, verbose=1)
score = model.evaluate(X_test, y_test, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

  In this example, we used convolutional and max-pooling layers to extract visual features of handwritten digits, which were then transformed into digit label predictions through fully connected layers. By training the weights through the backpropagation algorithm, we can let the model automatically learn the process of extracting features, so as to achieve more efficient and accurate classification.

2. Data volume and computing performance requirements

  The execution time required by machine learning is much less than that of deep learning. The parameters of deep learning are often very large, and the parameters need to be trained through multiple optimizations of a large amount of data.

First, deep learning requires a large training data set.
Second, training a deep neural network requires a lot of computing power.

It can take days, or even weeks, to train a deep network using a dataset of millions of images.

So deep learning in general.
1. A powerful GPU server is required for calculation.
2. Fully managed distributed training and prediction services - such as Google's TensorFlow cloud machine learning platform.

3. Algorithm representative

  Machine Learning: Naive Bayes, Decision Trees, and more

3.1. Naive Bayes algorithm

  The Naive Bayesian algorithm is a classification algorithm based on Bayesian theorem and the assumption of independence of feature conditions. Bayes' theorem is a theory of probability that describes the probability of another event occurring given certain conditions.

  The Naive Bayesian algorithm assumes that all features are independent of each other, that is, each feature variable has nothing to do with other feature variables. Based on this assumption, the Naive Bayes algorithm can predict the label category of new data by observing the already labeled data set.

  Naive Bayes algorithms are commonly used in applications such as text classification, spam filtering, and sentiment analysis.

  The following is a sample code to implement the Naive Bayes algorithm model using Python:

import numpy as np

class NaiveBayes:
    def __init__(self, n_classes):
        self.n_classes = n_classes
        self.priors = None
        self.posteriors = None
    
    def fit(self, X, y):
        n_samples, n_features = X.shape
        self.priors = np.zeros(self.n_classes)
        self.posteriors = np.zeros((self.n_classes, n_features))
        for c in range(self.n_classes):
            X_c = X[y == c]
            self.priors[c] = len(X_c) / n_samples
            self.posteriors[c] = (X_c.sum(axis=0) + 1) / (len(X_c) + 1)
    
    def predict(self, X):
        y_pred = []
        for x in X:
            posteriors = []
            for c in range(self.n_classes):
                prior = np.log(self.priors[c])
                likelihood = np.sum(np.log(self.posteriors[c]) * x)
                posterior = prior + likelihood
                posteriors.append(posterior)
            y_pred.append(np.argmax(posteriors))
        return y_pred

  This implementation uses Laplace smoothing to avoid zero probability problems, and converts probabilities to logarithmic form to avoid numerical underflow problems. The fit method is used to train the Naive Bayesian model, while the predict method is used to classify new samples.

3.2. Decision tree

  Decision tree is a classification and regression model based on tree structure, which is often used in the field of data mining and machine learning. It recursively splits the data set and continuously selects features until a recursive decision tree is finally obtained.

  The node of the decision tree represents a feature in the data set, the edge represents the value of this feature, and the leaf node represents the classification result or regression result.

  In the classification problem, the decision tree divides a sample from the root node to a specific leaf node, and the category of the leaf node is the category of the sample;

  In the regression problem, the decision tree divides a sample from the root node to a specific leaf node, and the value of the leaf node is the predicted value of the sample.

  Decision tree has the advantages of good interpretability, easy to understand and use, and is widely used in practical applications.

4. Neural Network

  A neural network is a computer program that simulates the way the nervous system of the human brain works. It is composed of a large number of artificial neurons (simulated biological neurons) through a certain connection method. Through learning and training, it can identify, classify, simulate and predict various things. It has good adaptability and nonlinear mapping capabilities. It is widely used in artificial intelligence, image recognition, natural language processing, speech recognition and other fields.

  Neural networks include feedforward neural networks, recurrent neural networks and other structures, among which feedforward neural networks are the most common.

  Sample code for neural network to implement logic and operation

  The neural network realizes logic and operation.

  The logical AND operation is an operation in which the result is 1 when both binary numbers are 1, and 0 otherwise.

  Neural networks can implement logic and operations by learning the mapping between the input and output of logic and operations.

  The following is a sample code for a simple neural network to implement logical AND operations:

import numpy as np
# 输入数据和标签
x = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([[0], [0], [0], [1]])

# define the neural network 

# 定义神经网络
class NeuralNetwork:
    def __init__(self):
        np.random.seed(1)
        self.weights = 2 * np.random.random((2, 1)) - 1

    def sigmoid(self, x):
        return 1 / (1 + np.exp(-x))

    def sigmoid_derivative(self, x):
        return x * (1 - x)

    def train(self, x, y, iterations):
        for i in range(iterations):
            output = self.predict(x)
            error = y - output
            adjustment = np.dot(x.T, error * self.sigmoid_derivative(output))
            self.weights += adjustment

    def predict(self, x):
        return self.sigmoid(np.dot(x, self.weights))

# train the neural network

# 训练神经网络
neural_network = NeuralNetwork()
neural_network.train(x, y, 10000)

# predict

# 预测
print(neural_network.predict(np.array([0, 0])))
print(neural_network.predict(np.array([0, 1])))
print(neural_network.predict(np.array([1, 0])))
print(neural_network.predict(np.array([1, 1])))

The output is:

[0.5]
[0.2689864]
[0.2689864]
[0.11738518]

Since the neural network is a probability-based model, the output results are not completely accurate,

But it can be seen that when the input is (0, 0), (0, 1) and (1, 0), the output is close to 0,

When the input is (1, 1), the output is close to 1, which is consistent with the result of the logical AND operation.

             Recommended reading:

Change the background color of the photo (python+opencv) Twelve categories of cats Virtual digital human based on large model__virtual anchor instance

Computer Vision__Basic Image Operations (Display, Read, Save) Histogram (color histogram, grayscale histogram) Histogram equalization (adjust image brightness, contrast)

 Speech recognition practice (python code) (1)

 Artificial Intelligence Basics

 Basics of Computer Vision__Image Features

93d65dbd09604c4a8ed2c01df0eebc38.png

 Quick check of matplotlib's own drawing style effect display (28 types, all)

074cd3c255224c5aa21ff18fdc25053c.png

Detailed explanation of Three.js example ___ rotating elf girl (with complete code and resources) (1)

fe88b78e78694570bf2d850ce83b1f69.png

cb4b0d4015404390a7b673a2984d676a.png

Three-dimensional multi-layer rose drawing source code__Rose python drawing source code collection

 Python 3D visualization (1)

 Make your work better - the method of making word cloud Word Cloud (based on python, WordCloud, stylecloud)

e84d6708316941d49a79ddd4f7fe5b27.png

938bc5a8bb454a41bfe0d4185da845dc.jpeg

0a4256d5e96d4624bdca36433237080b.png

 Usage of python Format() function___Detailed example (1) (full, many examples)___Various formatting replacements, format alignment printing

 Write romance with code__Collection (python, matplotlib, Matlab, java to draw hearts, roses, front-end special effects roses, hearts)

Python love source code collection (18 models)

dc8796ddccbf4aec98ac5d3e09001348.jpeg

0f09e73712d149ff90f0048a096596c6.png

40e8b4631e2b486bab2a4ebb5bc9f410.png

 Usage of the Print() function in Python___Detailed examples (full, many examples)

 The complete collection of detailed explanations of Python function and method examples (updating...)

 "Python List List Full Example Detailed Explanation Series (1)" __ series general catalog, list concept

09e08f86f127431cbfdfe395aa2f8bc9.png

Celebrate the Mid-Autumn Festival with code, do you want to have a bite of python turtle mooncake?

 directory of python exercises

03ed644f9b1d411ba41c59e0a5bdcc61.png

daecd7067e7c45abb875fc7a1a469f23.png

17b403c4307c4141b8544d02f95ea06c.png

Strawberry bear python turtle drawing (windmill version) with source code

 ​Strawberry Bear python turtle drawing code (rose version) with source code

 ​Strawberry bear python drawing (Spring Festival version, Christmas countdown snowflake version) with source code

4d9032c9cdf54f5f9193e45e4532898c.png

c5feeb25880d49c085b808bf4e041c86.png

 Buzz Lightyear python turtle drawing__with source code

Pikachu python turtle turtle drawing (power ball version) with source code

80007dbf51944725bf9cf4cfc75c5a13.png

1ab685d264ed4ae5b510dc7fbd0d1e55.jpeg

1750390dd9da4b39938a23ab447c6fb6.jpeg

 Node.js (v19.1.0npm 8.19.3) vue.js installation and configuration tutorial (super detailed)

 Color and color comparison table (1) (hexadecimal, RGB, CMYK, HSV, Chinese and English names)

A number of authoritative organizations in April 2023____Programming language rankings__Salary status

aa17177aec9b4e5eb19b5d9675302de8.png

38266b5036414624875447abd5311e4d.png

6824ba7870344be68efb5c5f4e1dbbcf.png

 The phone screen is broken____how to export the data inside (18 methods)

[CSDN Cloud IDE] Personal experience and suggestions (including ultra-detailed operation tutorials) (python, webGL direction)

 Check the jdk installation path, realize the coexistence solution of multiple java jdk on windows, and solve the terminal garbled characters after installing java19

​​

Vue3 project building tutorial (based on create-vue, vite, Vite + Vue)

fea225cb9ec14b60b2d1b797dd8278a2.png

bba02a1c4617422c9fbccbf5325850d9.png

37d6aa3e03e241fa8db72ccdfb8f716b.png

The second part of the 2023 Spring Festival blessings - send you a guardian rabbit, let it warm every one of you [html5 css3] drawing and moving bunny, cool charging, special font

 Unique, original, beautiful and romantic Valentine's Day confession album, (copy is available) (html5, css3, svg) confession love code (4 sets)

Detailed explanation series of SVG examples (1) (overview of svg, difference between bitmap and vector graphics (diagram), SVG application examples)

5d409c8f397a45c986ca2af7b7e725c9.png

6176c4061c72430eb100750af6fc4d0e.png

1f53fb9c6e8b4482813326affe6a82ff.png

[Programming Life] Python turtle drawing of World Cup elements in Qatar (with source code), 5 World Cup theme front-end special effects (with source code) HTML+CSS+svg draws exquisite colorful flashing lights Christmas tree, HTML+CSS+Js real-time New Year countdown (with source code)

 The first part of the 2023 Spring Festival Blessing Series (Part 1) (flying Kongming lanterns for blessings, wishing everyone good health) (with complete source code and resources for free download)

fffa2098008b4dc68c00a172f67c538d.png

5218ac5338014f389c21bdf1bfa1c599.png

c6374d75c29942f2aa577ce9c5c2e12b.png

 Tomcat11, tomcat10 installation configuration (Windows environment) (detailed graphics)

 Tomcat port configuration (detailed)

 Tomcat startup flashback problem solving set (eight categories in detail)

Guess you like

Origin blog.csdn.net/weixin_69553582/article/details/131406297