In [1]:
import numpy as np
import models as ml

In [2]:
feature_size = 2
class_cnt = 3
sample_cnt = 4

In [3]:
x = np.random.randn(sample_cnt*feature_size).reshape((sample_cnt, feature_size))
y = np.array([1 if r>0.5 else 0 for r in np.random.randn(sample_cnt*class_cnt)]).reshape((sample_cnt, class_cnt))
w = np.random.randn(feature_size*class_cnt).reshape((feature_size, class_cnt))
b = np.random.randn(class_cnt).reshape((1, class_cnt))

In [4]:
x


Out[4]:
array([[ 2.01064079,  1.73415377],
       [ 0.58242553, -0.2330557 ],
       [-1.78161554,  0.90050094],
       [-0.83769506,  0.78734582]])

In [5]:
y


Out[5]:
array([[1, 0, 0],
       [1, 0, 1],
       [1, 1, 0],
       [0, 0, 0]])

In [6]:
w


Out[6]:
array([[ 0.24278564, -0.02860119, -0.24494274],
       [ 0.33082995,  1.33482475, -0.92898523]])

In [7]:
b


Out[7]:
array([[-1.4099169, -1.0210776, -1.6109984]])

In [8]:
w, b = ml.create_parameters(2, 3)

for epoch in range(0, 10):
    h = ml.softmax_regression_model(x, w, b)
    dw, db = ml.crossentropy_cost_dev(x, y, h)
    w, b = ml.gd_update(w, b, dw, db, lr=0.01)
    
    cost = ml.crossentropy_cost(h, y)
    print("epoch {0}, cost {1}".format(epoch, cost))


epoch 0, cost 0.8253937042570428
epoch 1, cost 0.820536618882293
epoch 2, cost 0.8156896576434965
epoch 3, cost 0.8108529726361228
epoch 4, cost 0.8060267202829369
epoch 5, cost 0.801211061419453
epoch 6, cost 0.7964061613783894
epoch 7, cost 0.7916121900728901
epoch 8, cost 0.7868293220782547
epoch 9, cost 0.7820577367119063

In [ ]: