Learn's api is something like a combination between Torch and Scikit Learn. The purpose of Learn is to provide a flexible and portable neural network implementation that only depends on Lua. Learn is not multithreaded and does not use hardware acceleration, if you are looking for a high performance library I would suggest looking at Torch instead.
Learn can be installed as a submodule for your git project by using the command:
git submodule add https://github.com/Polkm/learn.git learn
After you have Learn installed you can use it in an existing Lua project.
require("learn/learn")
-- XOR training data
local train_features = {{0, 0}, {0, 1}, {1, 0}, {1, 1}}
local train_labels = {{0}, {1}, {1}, {0}}
local n_input = #train_features[1]
local n_output = #train_labels[1]
local model = learn.model.nnet({modules = {
learn.layer.linear({n_input = n_input, n_output = n_input * 3}),
learn.transfer.sigmoid({}),
learn.layer.linear({n_input = n_input * 3, n_output = n_output}),
learn.transfer.sigmoid({}),
}})
By default nnet will use the MSE criterion, appropriate for regression tasks.
local epochs = 1000
local error = model.fit(train_features, train_labels, epochs)
for _, prediction in pairs(model.predict(train_features)) do
print(table.concat(prediction, ", "))
end