Skip to content

Commit

Permalink
updated keras models (#259)
Browse files Browse the repository at this point in the history
* updated keras models

* few more changes
  • Loading branch information
gghati authored and kkweon committed Jan 11, 2020
1 parent 5795f79 commit b5c4c9e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
17 changes: 10 additions & 7 deletions keras/klab-04-1-multi_input_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
from keras.optimizers import RMSprop
import numpy as np

x_data = [[73., 80., 75.],
x_data = np.array([[73., 80., 75.],
[93., 88., 93.],
[89., 91., 90.],
[96., 98., 100.],
[73., 66., 70.]]
y_data = [[152.],
[73., 66., 70.]])
y_data = np.array([[152.],
[185.],
[180.],
[196.],
[142.]]
[142.]])

print(x_data.shape)
print(y_data.shape)

model = Sequential()
model.add(Dense(input_dim=3, units=1))
model.add(Activation('linear'))

rmsprop = RMSprop(lr=1e-10)
model.compile(loss='mse', optimizer=rmsprop)
rmsprop = RMSprop(lr=0.1)
model.compile(loss='mse', optimizer=rmsprop, metrics=['accuracy'])
model.fit(x_data, y_data, epochs=1000)

y_predict = model.predict(np.array([[95., 100., 80]]))
print(y_predict)
print(y_predict)
14 changes: 7 additions & 7 deletions keras/klab-04-2-multi_input_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
from keras.layers import Dense
import numpy as np

x_data = [[73., 80., 75.],
x_data = np.array([[73., 80., 75.],
[93., 88., 93.],
[89., 91., 90.],
[96., 98., 100.],
[73., 66., 70.]]
y_data = [[152.],
[73., 66., 70.]])
y_data = np.array([[152.],
[185.],
[180.],
[196.],
[142.]]
[142.]])

model = Sequential()
model.add(Dense(input_dim=3, units=1))

model.compile(loss='mse', optimizer='rmsprop')
model.fit(x_data, y_data)
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
model.fit(x_data, y_data, epochs=500)

y_predict = model.predict(np.array([[0, 2, 1]]))
print(y_predict)
print(y_predict)
12 changes: 6 additions & 6 deletions keras/klab-05-1-logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
from keras.optimizers import SGD
import numpy as np

x_data = [[1, 2],
x_data = np.array([[1, 2],
[2, 3],
[3, 1],
[4, 3],
[5, 3],
[6, 2]]
y_data = [[0],
[6, 2]])
y_data = np.array([[0],
[0],
[0],
[1],
[1],
[1]]
[1]])

model = Sequential()
model.add(Dense(1, input_dim=2, activation='sigmoid'))

sgd = SGD(lr=0.1)
model.compile(loss='binary_crossentropy', optimizer=sgd)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])

model.summary()
model.fit(x_data, y_data, epochs=2000)

print("2,1", model.predict_classes(np.array([[2, 1]])))
print("6,5", model.predict_classes(np.array([[6, 5]])))
print("6,5", model.predict_classes(np.array([[6, 5]])))
8 changes: 4 additions & 4 deletions keras/klab-05-2-logistic_regression_diabetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
from keras.optimizers import SGD
import numpy as np

x_data = [[1, 2],
x_data = np.array([[1, 2],
[2, 3],
[3, 1],
[4, 3],
[5, 3],
[6, 2]]
y_data = [[0],
[6, 2]])
y_data = np.array([[0],
[0],
[0],
[1],
[1],
[1]]
[1]])

model = Sequential()
model.add(Dense(1, input_dim=2, activation='sigmoid'))
Expand Down
12 changes: 6 additions & 6 deletions keras/klab-07-1-learning_rate_and_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import numpy as np
np.random.seed(777) # for reproducibility

x_data = [[1, 2, 1], [1, 3, 2], [1, 3, 4], [1, 5, 5],
[1, 7, 5], [1, 2, 5], [1, 6, 6], [1, 7, 7]]
y_data = [[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 1, 0],
[0, 1, 0], [0, 1, 0], [1, 0, 0], [1, 0, 0]]
x_data = np.array([[1, 2, 1], [1, 3, 2], [1, 3, 4], [1, 5, 5],
[1, 7, 5], [1, 2, 5], [1, 6, 6], [1, 7, 7]])
y_data = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 1, 0],
[0, 1, 0], [0, 1, 0], [1, 0, 0], [1, 0, 0]])

# Evaluation our model using this test dataset
x_test = [[2, 1, 1], [3, 1, 2], [3, 3, 4]]
y_test = [[0, 0, 1], [0, 0, 1], [0, 0, 1]]
x_test = np.array([[2, 1, 1], [3, 1, 2], [3, 3, 4]])
y_test = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1]])


model = Sequential()
Expand Down
8 changes: 4 additions & 4 deletions keras/klab-09-1-xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from keras.layers import Dense
from keras.optimizers import SGD

x_data = [[0., 0.],
x_data = np.array([[0., 0.],
[0., 1.],
[1., 0.],
[1., 1.]]
y_data = [[0.],
[1., 1.]])
y_data = np.array([[0.],
[1.],
[1.],
[0.]]
[0.]])

model = Sequential()
model.add(Dense(1, input_dim=2, activation='sigmoid'))
Expand Down
8 changes: 4 additions & 4 deletions keras/klab-09-2-xor-nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from keras.layers import Dense
from keras.optimizers import SGD

x_data = [[0., 0.],
x_data = np.array([[0., 0.],
[0., 1.],
[1., 0.],
[1., 1.]]
y_data = [[0.],
[1., 1.]])
y_data = np.array([[0.],
[1.],
[1.],
[0.]]
[0.]])

model = Sequential()
model.add(Dense(2, input_dim=2, activation='sigmoid'))
Expand Down

0 comments on commit b5c4c9e

Please sign in to comment.