A package with several types of Perceptron classifiers. Perceptrons are fast classifiers and can be used even for big data. Up to now, this package contains a linear perceptron, voted perceptron and a Kernel perceptron for binary classification problems. This project will have the following perceptron classifiers: Multiclass, Kernel, Structured, Voted, Average and Sparse. Some state-of-the-art must be included after these.
Pkg.add("Perceptrons")
using Perceptrons
using Perceptrons
# training a linear perceptron (solving the OR problem)
X_train = [1.0 1.0; 0.0 1.0; 1.0 0.0; 0.0 0.0]
Y_train = [1; 1; 1; 0.0]
X_test = [.8 .9; .01 1; .9 0.2; 0.1 0.2]
model = Perceptrons.fit(X_train,Y_train)
Y_pred = Perceptrons.predict(model,X_test)
println("[Perceptron] accuracy : $(acc(Y_train,Y_pred))")
# training a voted perceptron (solving the OR problem)
model = Perceptrons.fit(X_train,Y_train,centralize=true,mode="voted")
Y_pred = Perceptrons.predict(model,X_test)
println("[Voted Perceptron] accuracy : $(acc(Y_train,Y_pred))")
# training a averaged perceptron (solving the OR problem)
model = Perceptrons.fit(X_train,Y_train,centralize=true,mode="averaged")
Y_pred = Perceptrons.predict(model,X_test)
println("[Averaged Perceptron] accuracy : $(acc(Y_train,Y_pred))")
# training a kernel perceptron (solving the XOR problem)
X_train = [1.0 1.0; 0.0 1.0; 1.0 0.0; 0.0 0.0]
Y_train = [0.0 ; 1.0; 1.0; 0.0]
X_test = X_train .+ .03 # adding noise
model = Perceptrons.fit(X_train,Y_train,centralize=true,mode="kernel",kernel="rbf",width=.01)
Y_pred = Perceptrons.predict(model,X_test)
println("[Kernel Perceptron] accuracy : $(acc(Y_train,Y_pred))")
# if you want to save your model
Perceptrons.save(model,filename=joinpath(homedir(),"perceptron_model.jld"))
# if you want to load back your model
model = Perceptrons.load(filename=joinpath(homedir(),"perceptron_model.jld"))
Perceptrons.fit - learns from input data and its related single target
Perceptrons.predict - predicts using the learnt model extracted from fit.
TODO
The Perceptrons.jl is free software: you can redistribute it and/or modify it under the terms of the MIT "Expat"
License. A copy of this license is provided in LICENSE.md