Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Petra
DM_course
Commits
ec999fa5
Commit
ec999fa5
authored
Feb 14, 2020
by
Petra
Browse files
neural nets XOR
parent
6311ffc7
Changes
1
Hide whitespace changes
Inline
Side-by-side
9_neural_nets-4-xor.py
0 → 100644
View file @
ec999fa5
from
keras.models
import
Sequential
from
keras.layers.core
import
Dense
,
Dropout
,
Activation
from
keras.optimizers
import
SGD
import
numpy
as
np
X
=
np
.
array
([[
0
,
0
],
[
0
,
1
],
[
1
,
0
],
[
1
,
1
]])
y
=
np
.
array
([[
0
],
[
1
],
[
1
],
[
0
]])
model
=
Sequential
()
model
.
add
(
Dense
(
100
,
input_dim
=
2
))
#model.add(Activation('tanh'))
model
.
add
(
Dense
(
1
))
model
.
add
(
Activation
(
'sigmoid'
))
sgd
=
SGD
(
lr
=
0.1
)
model
.
compile
(
loss
=
'binary_crossentropy'
,
optimizer
=
sgd
)
model
.
fit
(
X
,
y
,
batch_size
=
1
,
nb_epoch
=
1000
)
print
(
model
.
predict_proba
(
X
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment