In [7]:
#
# LinearRegression Example
#
# @author becxer
# @email becxer87@gmail.com
#
import numpy as np
from pytrain.LinearRegression import LinearRegression
In [8]:
# Simple dataset
train_mat = [[0.12, 0.25],\
[3.24, 4.33],\
[0.14, 0.45],\
[7.30, 4.23],]
train_label = [[0,1],\
[1,0],\
[0,1],\
[1,0]]
test_a = [0.10,0.33]
test_b = [4.0,4.5]
In [9]:
# Train model
linear_reg = LinearRegression(train_mat, train_label)
linear_reg.fit(lr = 0.001, epoch = 10000, batch_size =4)
In [14]:
# Test model
res_a = np.rint(linear_reg.predict(test_a))
res_b = np.rint(linear_reg.predict(test_b))
print("X %s => Y %s" % (test_a, res_a))
print("X %s => Y %s" % (test_b, res_b))