IDEA plugin management

IDEA plug-in cannot be downloaded automatically?
This article mainly introduces two ways to install IDEA plug-in

1 Download the plug-in in the tool

Enter the settings page

Search for the plug-in you need, click Install, support upgrade
 

2 Download the plug-in from the official website

Plugin download address
https://plugins.jetbrains.com/idea?_ga=2.7341105.2082565591.1596586069-194658691.1591701694

Search for the required plug-in

3 Associate local plugins

The downloaded plug-in does not need to be decompressed, and the directory location is not required. It is recommended to place it in the plugins under the IDEA installation directory.

Restart IDEA after adding

Artificial Intelligence Chapter 3: TensorFlow

1 TensorFlow

TensorFlow™ is an open source software library that uses data flow graphs for numerical calculations.
The nodes (Nodes) represent mathematical operations in the graph, and the lines (edges) in the graph represent the multi-dimensional data arrays that are interconnected between nodes, that is, tensors.
Its flexible architecture allows you to perform calculations on multiple platforms, such as one or more CPUs (or GPUs) in desktop computers, servers, mobile devices, and so on. TensorFlow was originally developed by researchers and engineers from the Google Brain Group (belonging to the Google Machine Intelligence Research Institute) for research on machine learning and deep neural networks, but the versatility of this system allows it to be widely used in other calculations. field.

1.1 Why use tensorflow

Support GPU, TPU acceleration,
realize automatic derivation
, rich neural network API,
become TFBOYS ^0^

1.2 Installation of TensorFlow

The currently used version is TensorFlow-2.2.0, because 1.x and 2.x are not compatible with many apis, so if you have studied 1.x, please forget him.

1.2.1 Enter the conda environment

1.2.2 Update pip

python -m pip install --upgrade pip
 

1.2.3 Install tensorflow

pip install tensorflow-cpu==2.2.0 -i https://pypi.douban.com/simple
 

1.2.4 Test

  1. Enter the python command line

 

python

3. Guide the package and print the version

 

import tensorflow as tf
tf.__version__

 

If the package fails, the error is reported as follows

>>> import tensorflow
Traceback (most recent call last):
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\utils\Anaconda\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "D:\utils\Anaconda\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\utils\Anaconda\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\utils\Anaconda\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "D:\utils\Anaconda\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help. To
explain the lack of environment, please visit
https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported -visual-c-downloads
download the corresponding vc_redist.x64.exe to install
 

 

1.2 Regression problem

1.2.1 Function image drawing

https://www.desmos.com/calculator

Linear Equation
y = a * x + b
1.6 = a * 1 + b
3.1 = a * 2 + b
Solve from the above a = 1.5 b = 0.1

But such equations are often difficult to meet in real life.
The following equations are the common cases. They generally include noise (with noise)
y = w * x + b + ε
ε (Epsilon) is the noise value
ε ~ N(0,1) Normal part
when the function exists When there is noise, we need to observe multiple sets of data to approximately determine the values ​​of w and b.
How to solve this problem?

1.2.2 Loss function

Based on the example above, we can get a loss function
Loss = Σi(a * xi + b -yi) ²/n
which is the mean square error MSE

The method for obtaining the minimum value of loss is to perform gradient descent calculation on loss. When the loss value is the smallest,
the optimal value of a'b'is obtained .
Then find the minimum value for loss (Minisize loss) and
finally get f(x) = a'* x + b'in a'and b'

1.2.3 Gradient Descent

If the loss function is represented graphically, as shown in the following figure: the independent variables have a and b, and the dependent variable is f(x)


 

Each point in the figure can be represented in a three-dimensional coordinate system, as follows:
We can calculate the direction of the tangent plane of a point to deduce in which direction the point moves to find the smaller value of f(x) , Repeat the calculation and move the point to find the lowest point of the function image in the entire value range, which is the minimum value of the loss function.

In order to facilitate understanding, we converted the three-dimensional model to two-dimensional for explanation. As the two independent variables become one independent variable, while reducing the dimensionality, the calculation of the cut surface of a certain point has become the calculation of a certain point. The tangent of a point (that is, the derivative).

It is found through observation that when the derivative is positive, the function image is in the ascending phase, so the minimum value should be on the left, so the independent variable should be reduced, and when the derivative is negative, the function image is in the descending phase, and the independent variable is increased accordingly. As for how much to adjust, under normal circumstances, we will directly quote the derivative for calculation. Considering that when the absolute value of the derivative is large, the step length of the independent variable change will be larger, so it is usually shortened by multiplying the derivative by a smaller number. Step size. For
example: ab = ab − f ′ (ab) ∗ 0.001 ab = ab-f'(ab) * 0.001ab=ab−f′(ab)∗0.001
After multiple calculations, the independent variable will be extremely small The value moves back and forth repeatedly until it stops at the minimum value.

Sometimes there will be multiple recessed parts within a certain range as shown in the above picture. In order to prevent the selected point at the beginning of the calculation from not being within the recess with the minimum value, we usually select multiple points at random for simultaneous calculation. Find the minimum value.

1.2.3 TF implementation of linear regression case

The following data is the correspondence table between years of education and average income. Training modeling is carried out according to the characteristics of the data sample, and the salary level of junior, junior, middle school, undergraduate and research is predicted based on this (data source is the network, only knowledge exercises Level discussion.)

ID,Education,Income
1,10.000000 ,26.658839
2,10.401338 ,27.306435
3,10.842809 ,22.132410
4,11.244147 ,21.169841
5,11.645449 ,15.192634
6,12.086957 ,26.398951
7,12.048829 ,17.435307
8,12.889632 ,25.507885
9,13.290970 ,36.884595
10,13.732441 ,39.666109
11,14.133779 ,34.396281
12,14.635117 ,41.497994
13,14.978589 ,44.981575
14,15.377926 ,47.039595
15,15.779264 ,48.252578
16,16.220736 ,57.034251
17,16.622074 ,51.490919
18,17.023411 ,51.336621
19,17.464883 ,57.681998
20,17.866221 ,68.553714
21,18.267559 ,64.310925
22,18.709030 ,68.959009
23,19.110368 ,74.614639
24,19.511706 ,71.867195
25,19.913043 ,76.098135
26,20.354515 ,75.775216
27,20.755853 ,72.486055
28,21.167191 ,77.355021
29,21.598662 ,72.118790
30,22.000000 ,80.260571
 

First draw the image through the data

import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt

# Read the file through pd
data = pd.read_csv('./data.csv')
x = data.Education
y = data.Income
# Draw an image through plt
plt.scatter(x, y)
plt.show()
 

By observing the above figure, we can find out what characteristics the overall data reflects?

  1. The number of years of education is positively correlated with income
  2. In the two-dimensional space, there is a relatively obvious linear relationship between the two,
    so we can use
    f(x) = ax + b
    to try to build the model.

import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt

# Read the file through pd
data = pd.read_csv('./data.csv')
x = data.Education
y = data.Income
# Draw an image through plt
plt.scatter(x, y)
# plt.show()

# Sequential model & Sequential model initialization
model = tf.keras.Sequential()
# Pass in the Dense layer, specify the output dimension as 1 and the input dimension as 1
model.add(tf.keras.layers.Dense(1, input_shape=(1 ,)))
# 展示模型
# model.summary()

# Create the model, specify the optimizer and loss function
model.compile(optimizer='adam', loss='mse')
# Keep the training process, specify the training data and training times, and get the final model. At this time, the model has saved the training The completed model.
history = model.fit(x, y, epochs=50000)

# # Use the trained model prediction data to get the prediction result
x1 = x
y1 = model.predict(x)

# Talk about the prediction results drawn as an image for comparing the original data and evaluating the fit
plt.scatter(x1, y1)
plt.show()

# Predict what the salary level will be when the years of education are 6, 9, 12, 16, and 20 years
fx = model.predict([6, 9, 12, 16, 20])
print(fx)

1.3 Basic API

Basic data types
Tf.constant, tf.string
Tf.ragged.constant, tf.SparseTensor, tf.Variable
custom loss function-tf.reduce_mean
custom level-Keras.layers.Lambda and inheritance
method
Tf.function Tf.function, tf.autograph.to_code,get_concrete_function
graphDef
get_operations,get_opration_by_name
get_tensor_by_name,as_graph_def
automatic derivation
Tf.GradientTape
Optimzier.apply_gradients

HelloWorld
Google provides tensorflow learning platform
https://developers.google.cn/machine-learning/crash-course
tensorflow testing platform
http://playground.tensorflow.org

Normalized

Callback

Artificial Intelligence Chapter 2: What is Artificial Intelligence

1 What is artificial intelligence

Artificial Intelligence (Artificial Intelligence), the English abbreviation is AI. It is a new technological science that studies and develops theories, methods, technologies and application systems used to simulate, extend and expand human intelligence.

Artificial intelligence is a branch of computer science. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, language recognition, image recognition, Natural language processing and expert systems, etc. Since the birth of artificial intelligence, the theory and technology have become increasingly mature, and the field of application has continued to expand. It is conceivable that the technological products brought by artificial intelligence in the future will be the "containers" of human wisdom. Artificial intelligence can simulate the information process of human consciousness and thinking. Artificial intelligence is not human intelligence, but it can think like humans and may exceed human intelligence.
The definition given by John McCarthy :

  1. The science and engineering of building intelligent machines, especially intelligent computer programs.
  2. Artificial intelligence is a way of allowing computer programs to think "intelligently".
  3. The mode of thinking is similar to that of humans.
    There is a difference between intelligence and intelligence: intelligence includes intelligence, and intelligence expresses computational ability (smartness)

Artificial intelligence research direction:

  1. Computer vision
  2. Natural language processing
  3. Data mining analysis
  4. Comprehensive Application
    Unmanned Driving
    Robot
    Industry AI Empowerment (Quantitative)

1.1 How to be smart?

  1. The ability to make corresponding changes based on changes in the environment.
  2. Has the most basic motivation for "survival" (the desire to survive).
  3. Autonomy, self-awareness, etc.

1.2 Turing test

Turing proposed a famous experiment (turing test) about judging whether a machine is smart enough in 1950.

1.3 The required basis

The most basic are mathematics, differential and integral, advanced algebra, statistics, probability theory, etc., and even social science, psychology, etc. are needed.

1.4 A brief history of artificial intelligence

  1. In 1943, the concept of artificial neural network was proposed, and Artificial Neural Network, a neural network computing model appeared.
  2. In 1956, John McCarthy initiated the Dartmouth Conference (defining AI, Artificial Intelligence), marking the official birth of AI.
  3. In 1957, the perceptron, one of the simplest artificial neural networks, was a simple abstraction of biological neural network mechanisms, which pushed artificial intelligence to the first peak.

In the first decade of artificial intelligence after 1970, the amount of calculation consumed by traditional perceptrons was proportional to the square of the number of neurons. At that time, the computing power of computers was far below this level.
In 1982, the Hopfield neural network was proposed, a recurrent neural network (calculated repeatedly according to the receipt), with a feedback mechanism (feed back)

In 1974, the back propagation algorithm was proposed, but it did not receive much attention.
In 1986, the complete algorithm (BP algorithm) was re-proposed to make large-scale neural network training possible, pushing artificial intelligence to the second peak.
The second cold winter of artificial intelligence began in 1990. The US government reduced its investment due to the failure of the Darpa project.
In 2006, it was proposed that deep learning (deep learning) refers to multi-layer neural networks. At the same time enter the era of perceptual intelligence (voice and image recognition).
Division of the artificial intelligence era:
computational intelligence, perceptual intelligence, and cognitive intelligence.
In 2016, AlphaGo once again set off a wave of artificial intelligence. Google acquired DeepMind's AlphaGo (based on TensorFlow)
artificial intelligence knowledge graph:

2 What is machine learning

Machine learning is a way to realize artificial intelligence, and deep learning is a branch of machine learning


 

2.1 What is learning?

Learning is a process: a system that improves its performance by executing a certain program.
The purpose of learning is to "decrease entropy" (entropy: the degree of confusion, the second law of thermodynamics: an independent system, tends to automatically increase entropy)

2.2 The necessity of machine learning

Solve tasks that cannot be completed by manual programming. Such as image recognition, autonomous driving and so on.
There is a difference between good and bad conditions for human beings, but not for machines.
The computing power of machines is far greater than that of humans in some dimensions.

2.3 The concept of machine learning

After improving a certain type of task T (Task) and performance P (Performance) through experience E (Experience), the performance measured by the performance metric P on T has been improved.

2.4 The difference between traditional programming and machine learning

Train the cat to shake hands, issue instructions, and give rewards for the right ones, but no rewards for the wrong ones. Through the data and results, I hope the cat will learn the procedure of shaking hands.
The purpose of machine learning is to find a good function through data and results

2.5 Classification of machine learning

Supervised learning (classification, with labels)

Unsupervised learning (clustering, no labels)

Semi-supervised learning (clustering, some with labels)
reinforcement learning (reward-based learning)

2.6 Machine learning related algorithms

2.7 Machine learning algorithm selection

Divided into four categories: classification, clustering, regression, dimensionality reduction
First determine the number of samples, greater than 50 to continue, insufficient to collect more data
and then determine whether the data has categories, there are category alternative classification and clustering, otherwise alternative regression And dimensionality reduction
If there are categories, judge whether there are labels, label classification, and label clustering. When
there are no categories, judge whether you need to predict the value, whether it is regression, or whether dimensionality reduction

Machine learning vocabulary
node
predicting a category: predicting a category:
predicting a quantity: predicted value
labeled data: whether the data has been labeled
Regression
SGD Regressor: stochastic gradient descent regression
Lasso/ElasticNet Lasso: elastic network regression
SVR (kernel='linear'): support Vector machine regression uses a linear function as the kernel function
SVR (kernel='rbf'): Support vector machine regression uses a radial basis function
RidgeRegressor: Ridge regression
Classification
Linear SVC: Linear support vector machine classification
Navie Bayes: Naive Bayes
KNeighbors Classifier: K-nearest neighbor classifier
SVC: support vector machine classifier
SGD Classifier: stochastic gradient descent classifier
kernel approximation: kernel approximation method
clustering
MiniBatch KMeans: minimal family (bundle) KMeans
KMeans: traditional KMeans
Spectral Clustering: spectral clustering
GMM: mixed Gaussian Model
VBGMM: VB mixture Gaussian model

2.8 Machine learning steps

  1. Data collection
  2. Prepare data
  3. Select/build model
  4. Training model
  5. Test model (stop here if successful)
  6. Tuning parameters
    Key points: modeling, evaluation, tuning

2.9 Other concepts

2.9.1 Overfitting

Underfitting Underfitting
Perfect fitting right
Overfitting overfitting

The reflection in the return

Representation in classification

2.9.2 Methods to solve over-fitting

Reduce the amount of data, reduce unnecessary data and reduce the degree of fit.
Regularization (algebraic geometry) constrains the empirical error function and guides the function to reduce the error.
Dropout, randomly remove some neurons during training, and use all neurons during testing to reach a generalized model to prevent overfitting.

3 What is deep learning

3.1 Concept

In short, it is based on deep (multi-layer hidden layer) neural network learning.

3.2 Necessary conditions for using deep learning

A large amount of data: the larger the amount of data seen in the figure, the better the effect.
Strong computing power: strong computing power can make the impossible possible. CPU, GPU, TPU, cloud computing.
Complex model: the more hidden layers, the better the effect

3.3 Summary of the deep learning process

Forward propagation-calculation error (loss)-back propagation (BP)-adjustment weight (weight)
In addition to parameter adjustment (weight), there is also dropout

 

Guess you like

Origin blog.csdn.net/abu1216/article/details/111027129