lab 1: 4 variables fix
This commit is contained in:
parent
ea3668ea54
commit
d5017dc61a
30
lab_1.py
30
lab_1.py
@ -1,17 +1,37 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from tensorflow.keras import Sequential, Input, layers, optimizers
|
from tensorflow.keras import Sequential, Input, layers, optimizers
|
||||||
|
|
||||||
x = np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0], [1, 1, 1]])
|
x = np.array([
|
||||||
y = np.array([0, 1, 1, 1, 0, 0, 0, 1])
|
[0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1],
|
||||||
|
[0, 0, 1, 0],
|
||||||
|
[0, 0, 1, 1],
|
||||||
|
|
||||||
|
[0, 1, 0, 0],
|
||||||
|
[0, 1, 0, 1],
|
||||||
|
[0, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1],
|
||||||
|
|
||||||
|
[1, 0, 0, 0],
|
||||||
|
[1, 0, 0, 1],
|
||||||
|
[1, 0, 1, 0],
|
||||||
|
[1, 0, 1, 1],
|
||||||
|
|
||||||
|
[1, 1, 0, 0],
|
||||||
|
[1, 1, 0, 1],
|
||||||
|
[1, 1, 1, 0],
|
||||||
|
[1, 1, 1, 1],
|
||||||
|
])
|
||||||
|
y = np.array([0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0])
|
||||||
|
|
||||||
model = Sequential([
|
model = Sequential([
|
||||||
Input(shape=(3,)),
|
Input(shape=(4,)),
|
||||||
layers.Dense(3, activation="tanh"),
|
layers.Dense(3, activation="tanh"),
|
||||||
layers.Dense(1, activation="sigmoid"),
|
layers.Dense(1, activation="sigmoid"),
|
||||||
])
|
])
|
||||||
|
|
||||||
model.compile(optimizer=optimizers.Adam(learning_rate=0.05), loss="binary_crossentropy", metrics=["accuracy"])
|
model.compile(optimizer=optimizers.Adam(learning_rate=0.05), loss="binary_crossentropy", metrics=["accuracy"])
|
||||||
model.fit(x, y, epochs=100)
|
model.fit(x, y, epochs=200)
|
||||||
|
|
||||||
loss, accuracy = model.evaluate(x, y)
|
loss, accuracy = model.evaluate(x, y)
|
||||||
print(f"Loss: {loss}")
|
print(f"Loss: {loss}")
|
||||||
@ -19,4 +39,4 @@ print(f"Accuracy: {accuracy}")
|
|||||||
|
|
||||||
prediction = model.predict(x)
|
prediction = model.predict(x)
|
||||||
for inp, pred in zip(x, prediction):
|
for inp, pred in zip(x, prediction):
|
||||||
print(inp, round(pred[0]))
|
print(inp, round(pred[0]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user