Deep-Learning Neural Network Model¶
Installation of jupyter notebook¶
This note is created for those who have little knowledge about Python. There are many IDE's (Integrated Development Environment) for users to compose Python scripts. Among them, I chose jupyter notebook, as it is easy to use. We need to create a new environment, in which we compose our Python scripts. In MAC terminal console, you can type the command below to create an environment.
- conda create --name MyEnv
Then, you need to activate this environment by using the below command.
- conda activate MyEnv
Now you will find that the prompt has changed to the environment you set up. We can install jupyter notebook here by this command.
- conda install jupyter
If everything goes well, now you can call jupyter notebook for use in the console.
- jupyter notebook
The working environment of jupyter notebook has a formate of webpage. First, we need to create a new file by clicking on the button NEW. Or you can go to menu -> file -> New and choose notbook as your file type. Your jypyter notebook will automatically assign Python3 as the kernel for your notebook file.
Python basics¶
A notebook file comprises a number of cells. Every cell can have its own type, such as code or markdown. The below cell is of the type of code. That means that we write down our Python codes here and press ctrl-enter to execute them. In the below cell, I declare two integer variables a and b as 1 and 2 respectively. I also compute the sum of these two variables, which is 3.
a=1
b=2
a+b
3
In additio to integer, there are other types of variables in Python, such as float and string. The below cell shows the codes to declare a float number and a string. Note a string must be emcopassed by " " or ' '. We can use the function print() to print these two variables on computer screen.
c=3.141592
d="hello world"
print(c,d)
3.141592 hello world
In print(), we can use + to link two strings.
M="What is your name?"
print(M+" May")
What is your name? May
In Python, the structure of a variable can vary from a single value, a vector, to an array. The below code delcares a vector by including elements in [ ].
x=[1,c,[5,6,7]]
x
[1, 3.141592, [5, 6, 7]]
We can get the value of an element in a vector by calling its position. For a vector of k elements, the sequence numbers of its elements start from 0 until k-1. Thus, we can retrieve the value of an element by calling its sequence number. The sequence number can be negative, which indicates the element backwards. Also, we can use the operator m : n to retrieve the values on the position m to the position n-1.
x[2]
[5, 6, 7]
x[-1]
[5, 6, 7]
print(x[0:2])
[1, 3.141592]
We can get the sequence number of a value in a vector by calling the function index().
x.index([5,6,7])
2
We can append or insert an element to a vector. With append(), we always add the new value to the last position of the vector. With insert(p,v), we can insert the variable v to the position number p.
x.append('good weather')
x
[1, 3.141592, [5, 6, 7], 'good weather']
x.insert(2,'good weather')
x
[1, 3.141592, 'good weather', [5, 6, 7], 'good weather']
A particular type of variable is called dictionary, in which at least there are two columns; one for the column title and the other for the value. See the below codes.
y={"name":"Smith","age":"45","gener":"male"}
y
{'name': 'Smith', 'age': '45', 'gener': 'male'}
How about creating a dictionary with more than one row?
z={"name":["Smith","Apple","May"],"age":[30,23,25]}
z
{'name': ['Smith', 'Apple', 'May'], 'age': [30, 23, 25]}
We can retrieve the data in a dictionary by its label. See the blow codes.
z['name']
['Smith', 'Apple', 'May']