import numpy as np import sys sys.path.append('./src') sys.path.append('./src/lib') from simple_net import SimpleNet from gradient import numerical_gradient net = SimpleNet() print(net.W) # >>> [[-0.44439281 0.30789016 -1.50579685] # [-0.93170709 0.08170439 -0.12740328]] x = np.array([0.6, 0.9]) p = net.predict(x) print(p) # >>> [ 1.00824761 -1.47819523 0.03650346] print(np.argmax(p)) # >> 1 t = np.array([0, 0, 1]) print(net.loss(x, t)) # >>> 1.704819611629646 f = lambda w: net.loss(x, t) dW = numerical_gradient(f, net.W) print(dW) # >>> [[ 0.09999078 0.39092591 -0.49091668] # [ 0.14998616 0.58638886 -0.73637502]]
# load model # network = SimpleNet(input_size=1 , hidden_size=10, output_size=1 ) network = SimpleNet(input_size=3, hidden_size=10, output_size=1) network.load_params("params.pkl") #print( network.params["W1"] ) #pred train_acc = network.accuracy(x_train, y_train) test_acc = network.accuracy(x_test, y_test) # print("train acc, test acc | " + str(train_acc) + ", " + str(test_acc)) # # x_test_dt= conv_num_date(x_test_pred ) # x_train_dt= conv_num_date(x_train ) #print(x_test_dt.shape ) print(x_test[:10]) y_val = network.predict(x_test[:10]) y_val = y_val * num_max_y print(y_val) # quit() y_train = y_train * num_max_y y_val = y_val * num_max_y print('time : ', time.time() - global_start_time) #print(y_val[:10] ) #print(x_test_dt[:10] ) quit() #plt plt.plot(x_train_dt, y_train, label="temp") plt.plot(x_test_dt, y_val, label="predict") plt.legend() plt.grid(True)
print(x_train.shape, y_train.shape) print(x_test.shape, y_test.shape) # load network = SimpleNet(input_size=1, hidden_size=10, output_size=1) network.load_params("params.pkl") #print( network.params["W1"] ) #pred train_acc = network.accuracy(x_train, y_train) test_acc = network.accuracy(x_test, y_test) # print("train acc, test acc | " + str(train_acc) + ", " + str(test_acc)) # x_test_dt = conv_num_date(x_test_pred) x_train_dt = conv_num_date(x_train) #print(x_test_dt.shape ) y_val = network.predict(x_test_pred) y_train = y_train * num_max_y y_val = y_val * num_max_y print('time : ', time.time() - global_start_time) #print(y_val[:10] ) #print(x_test_dt[:10] ) #quit() #plt plt.plot(x_train_dt, y_train, label="temp") plt.plot(x_test_dt, y_val, label="predict") plt.legend() plt.grid(True) plt.title("IoT data") plt.xlabel("x_test") plt.ylabel("temperature") plt.show()