Code Monkey home page Code Monkey logo

perceptrons.jl's Introduction

Perceptrons.jl

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.

Build Status

Coverage Status

codecov.io

Install

Pkg.add("Perceptrons")

Using

using Perceptrons

Examples

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"))

What is Implemented

  • Voted Perceptron
  • Averaged Perceptron
  • Kernel Perceptron
  • Linear Perceptron

What is Upcoming

  • Multiclass Perceptron
  • Structured Perceptron
  • Sparse Perceptron

Method Description

  • Perceptrons.fit - learns from input data and its related single target

    • X::Matrix{:<AbstractFloat} - A matrix that columns are the features and rows are the samples
    • Y::Vector{:<AbstractFloat} - A vector with float values.
    • copydata::Bool = true: If you want to use the same input matrix or a copy.
    • centralize::Bool = true: If you want to z-score columns. Recommended if not z-scored yet.
    • mode::AbstractString = "linear": modes are "linear", "kernel", "voted" and "averaged" perceptron.
    • kernel::AbstractString = "rbf": If you want to apply a nonlinear Perceptron with gaussian Kernel.
    • width::AbstractFloat = 1.0: Rbf Kernel width (Only if kernel="rbf").
    • alpha::Real = 1.0e-2: learning rate.
    • shuffle_epoch::Bool = true: Shuffle dataset for each epoch. Improves convergency.
    • random_state::Int = 42: Use a seed to force same results trhough the same dataset.
    • max_epochs::Int = 5: Maximum epochs.
  • Perceptrons.predict - predicts using the learnt model extracted from fit.

    • model::Perceptrons.Model - A Perceptron model learnt from fit.
    • X::Matrix{:<AbstractFloat} - A matrix that columns are the features and rows are the samples.
    • copydata::Bool = true - If you want to use the same input matrix or a copy.

References

TODO

License

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

perceptrons.jl's People

Contributors

lalvim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

perceptrons.jl's Issues

Info about upcoming removal of packages in the General registry

As described in https://discourse.julialang.org/t/ann-plans-for-removing-packages-that-do-not-yet-support-1-0-from-the-general-registry/ we are planning on removing packages that do not support 1.0 from the General registry. This package has been detected to not support 1.0 and is thus slated to be removed. The removal of packages from the registry will happen approximately a month after this issue is open.

To transition to the new Pkg system using Project.toml, see https://github.com/JuliaRegistries/Registrator.jl#transitioning-from-require-to-projecttoml.
To then tag a new version of the package, see https://github.com/JuliaRegistries/Registrator.jl#via-the-github-app.

If you believe this package has erroneously been detected as not supporting 1.0 or have any other questions, don't hesitate to discuss it here or in the thread linked at the top of this post.

Having issues appding package on 1.0.2

Trying to use the package through the package manager and getting dependency issues:

julia> Pkg.add("Perceptrons") Resolving package versions... ERROR: Unsatisfiable requirements detected for package Perceptrons [17a20078]: Perceptrons [17a20078] log: ├─possible versions are: 1.0.0 or uninstalled ├─restricted to versions * by an explicit requirement, leaving only versions 1.0.0 └─restricted by julia compatibility requirements to versions: uninstalled — no versions left Stacktrace: [1] #propagate_constraints!#61(::Bool, ::Function, ::Pkg.GraphType.Graph, ::Set{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/GraphType.jl:1005

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.