03_Deeplearning_build a neural network
.png)
.png)
x = np.array([[200.0, 17.0]])
layer_1 = Dense(units=3,activation='sigmoid') #layer1,neurons:3,activation
#activation function is sigmoid
a1 = layer_1(x) #a1 is a vector which has three elements
layer_2 = Dense(units=1,activation='sigmoid')#layer2:neurons:1,activation:sigmoid
a2 = layer_2(a1) #a2 has a number
.png)
just as same as before
arrays and metrix
.png)
.png)
metrix:two []
.png)
.png)
tensorflow deal with metrix.
.png)
np.array([[]]):2D-array - metrix
np.array([]):1-d, number list
building a neuron network
the first method to creat the layer.
x = np.array([[200.0,17.0]]) #initialize x
layer_1 =Dense(units=3,activation='sigmoid') # creat layer_1
a1 = layer_1(x) #get the layer_1 output
layer_2 = Dense(units=1, activation = 'sigmoid') #creat layer_2
a2 = layer_2(a1) #get the layer_2 output
.png)
the second one
layer_1 = Dense(units = 3,activation = "sigmoid")
layer_2 = Dense(units = 1, activation = "sigmoid")
model = Sequential([layer_1, layer_2]) #connect the two layers
x = np.array([[200.0,17.0],
[120.0,5.0],
[425.0,20.0],
[212.0,18.0]]) #initialize the x
y = np.array([1,0,0,1])
model.compile(...)
model.fit(x,y) #get the data to practise
model.predict(x_new)
.png)
the third way
model = Sequential([
Dense(units=3,activation="sigmoid")
Dense(units=1,activation="sigmoid")
])
x = np.array([[200.0,17.0],
[120.0,5.0],
[425.0,20.0],
[212.0,18.0]]) #initialize the x
y = np.array([1,0,0,1])
model.compile(...)
model.fit(x,y) #get the data to practise
model.predict(x_new)
Digit Classification model
layer_1 = Dense(units = 25,activation= "sigmoid")
layer_2 = Dense(units = 15,activation = "sigmoid")
layer_3 = Dense(units = 1,activation = "sigmoid")
model = Sequential([layer_1,layer_2,layer_3])
model.compile(...)
x = np.array([0...,245,...,17],
[0...,200,...,184])
y = np.array([1,0])
model.fit(x,y)
model.predict(x_new)
.png)

浙公网安备 33010602011771号