Start refactoring the README (let's see how it looks!).
This commit is contained in:
@@ -29,10 +29,24 @@ src="https://cdn.rawgit.com/mlpack/mlpack.org/e7d36ed8/mlpack-black.svg" style="
|
||||
**mlpack** is an intuitive, fast, and flexible header-only C++ machine learning
|
||||
library with bindings to other languages. It is meant to be a machine learning
|
||||
analog to LAPACK, and aims to implement a wide array of machine learning methods
|
||||
and functions as a "swiss army knife" for machine learning researchers. In
|
||||
addition to its powerful C++ interface, mlpack also provides command-line
|
||||
and functions as a "swiss army knife" for machine learning researchers.
|
||||
|
||||
mlpack's lightweight C++ implementation makes it ideal for deployment, and it
|
||||
can also be used for interactive prototyping via C++ notebooks (these can be
|
||||
seen in action on mlpack's [homepage](https://www.mlpack.org/)).
|
||||
|
||||
In addition to its powerful C++ interface, mlpack also provides command-line
|
||||
programs, Python bindings, Julia bindings, Go bindings and R bindings.
|
||||
|
||||
***Quick links:***
|
||||
|
||||
- Quickstart guides: [C++]( ), [CLI]( ), [Python]( ), [R]( ), [Julia]( ), [Go]( )
|
||||
- [mlpack homepage](https://www.mlpack.org/)
|
||||
- [mlpack documentation](https://www.mlpack.org/docs.html)
|
||||
- [Examples repository](https://github.com/mlpack/examples/)
|
||||
- [Tutorials](https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html)
|
||||
- [Development Site (Github)](https://www.github.com/mlpack/mlpack/)
|
||||
|
||||
[//]: # (numfocus-fiscal-sponsor-attribution)
|
||||
|
||||
mlpack uses an [open governance model](./GOVERNANCE.md) and is fiscally
|
||||
@@ -50,31 +64,21 @@ variety of other needs.
|
||||
</div>
|
||||
<br>
|
||||
|
||||
### 0. Contents
|
||||
### 0. Contents and Quick Links
|
||||
|
||||
1. [Introduction](#1-introduction)
|
||||
2. [Citation details](#2-citation-details)
|
||||
3. [Dependencies](#3-dependencies)
|
||||
4. [Building mlpack from source](#4-building-mlpack-from-source)
|
||||
5. [Running mlpack programs](#5-running-mlpack-programs)
|
||||
6. [Using mlpack from Python](#6-using-mlpack-from-python)
|
||||
7. [Further documentation](#7-further-documentation)
|
||||
8. [Bug reporting](#8-bug-reporting)
|
||||
1. [Citation details](#1-citation-details)
|
||||
2. [Dependencies](#2-dependencies)
|
||||
3. [Installing and using mlpack in C++](#4-installing-and-using-mlpack-in-c++)
|
||||
4. [Building mlpack bindings to other languages](#5-building-mlpack-bindings-to-other-languages)
|
||||
a. [Command-line programs](#4a-command-line-programs)
|
||||
b. [Python bindings](#4b-python-bindings)
|
||||
c. [R bindings](#4c-r-bindings)
|
||||
d. [Julia bindings](#4d-julia-bindings)
|
||||
e. [Go bindings](#4d-go-bindings)
|
||||
5. [Building mlpack's test suite](#5-building-mlpacks-test-suite)
|
||||
6. [Further resources](#6-further-resources)
|
||||
|
||||
### 1. Introduction
|
||||
|
||||
The mlpack website can be found at https://www.mlpack.org and it contains
|
||||
numerous tutorials and extensive documentation. This README serves as a guide
|
||||
for what mlpack is, how to install it, how to run it, and where to find more
|
||||
documentation. The website should be consulted for further information:
|
||||
|
||||
- [mlpack homepage](https://www.mlpack.org/)
|
||||
- [mlpack documentation](https://www.mlpack.org/docs.html)
|
||||
- [Tutorials](https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html)
|
||||
- [Development Site (Github)](https://www.github.com/mlpack/mlpack/)
|
||||
- [API documentation (Doxygen)](https://www.mlpack.org/doc/mlpack-git/doxygen/index.html)
|
||||
|
||||
### 2. Citation details
|
||||
### 1. Citation details
|
||||
|
||||
If you use mlpack in your research or software, please cite mlpack using the
|
||||
citation below (given in BibTeX format):
|
||||
@@ -95,169 +99,258 @@ citation below (given in BibTeX format):
|
||||
|
||||
Citations are beneficial for the growth and improvement of mlpack.
|
||||
|
||||
### 3. Dependencies
|
||||
### 2. Dependencies
|
||||
|
||||
mlpack has the following dependencies:
|
||||
mlpack requires a C++14 compiler and has the following additional dependencies:
|
||||
|
||||
Armadillo >= 9.800
|
||||
CMake >= 3.6
|
||||
ensmallen >= 2.10.0
|
||||
cereal >= 1.1.2
|
||||
|
||||
All of those should be available in your distribution's package manager. If
|
||||
not, you will have to compile each of them by hand. See the documentation for
|
||||
each of those packages for more information.
|
||||
|
||||
If you would like to use or build the mlpack Python bindings, make sure that the
|
||||
following Python packages are installed:
|
||||
|
||||
setuptools
|
||||
cython >= 0.24
|
||||
numpy
|
||||
pandas >= 0.15.0
|
||||
|
||||
If you would like to build the Julia bindings, make sure that Julia >= 1.3.0 is
|
||||
installed.
|
||||
|
||||
If you would like to build the Go bindings, make sure that Go >= 1.11.0 is
|
||||
installed with this package:
|
||||
|
||||
Gonum
|
||||
|
||||
If you would like to build the R bindings, make sure that R >= 4.0 is
|
||||
installed with these R packages.
|
||||
|
||||
Rcpp >= 0.12.12
|
||||
RcppArmadillo >= 0.8.400.0
|
||||
RcppEnsmallen >= 0.2.10.0
|
||||
BH >= 1.58
|
||||
roxygen2
|
||||
- Armadillo >= 9.800
|
||||
- ensmallen >= 2.10.0
|
||||
- cereal >= 1.1.2
|
||||
|
||||
If the STB library headers are available, image loading support will be
|
||||
compiled.
|
||||
available.
|
||||
|
||||
If you are compiling Armadillo by hand, ensure that LAPACK and BLAS are enabled.
|
||||
|
||||
### 4. Building mlpack from source
|
||||
### 3. Installing and using mlpack in C++
|
||||
|
||||
This document discusses how to build mlpack from source. These build directions
|
||||
will work for any Linux-like shell environment (for example Ubuntu, macOS,
|
||||
FreeBSD etc). However, mlpack is in the repositories of many Linux distributions
|
||||
and so it may be easier to use the package manager for your system. For example,
|
||||
on Ubuntu, you can install the mlpack library and command-line executables (e.g.
|
||||
mlpack_pca, mlpack_kmeans etc.) with the following command:
|
||||
Since mlpack is a header-only library, installing just the headers for use in a
|
||||
C++ application is trivial. From the root of the sources, configure and install
|
||||
in the standard CMake way:
|
||||
|
||||
$ sudo apt-get install libmlpack-dev mlpack-bin
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake ../
|
||||
sudo make install
|
||||
```
|
||||
|
||||
On Fedora or Red Hat (EPEL):
|
||||
You can add a few arguments to the `cmake` command to control the behavior of
|
||||
the configuration and build process. Simply add these to the `cmake` command.
|
||||
Some options are given below:
|
||||
|
||||
$ sudo dnf install mlpack-devel mlpack-bin
|
||||
- `-DCMAKE_INSTALL_PREFIX=/install/root/` will set the root of the install
|
||||
directory to `/install/root` when `make install` is run.
|
||||
- `-DDOWNLOAD_DEPENDENCIES=ON` will automatically download mlpack's
|
||||
dependencies (ensmallen, Armadillo, and cereal).
|
||||
- `-DDEBUG=ON` will enable debugging symbols in any compiled bindings or tests.
|
||||
|
||||
*Note*: Older Ubuntu versions may not have the most recent version of mlpack
|
||||
available---for instance, at the time of this writing, Ubuntu 16.04 only has
|
||||
mlpack 3.4.2 available. Options include upgrading your Ubuntu version, finding
|
||||
a PPA or other non-official sources, or installing with a manual build.
|
||||
There are also options to enable building bindings to each language that mlpack
|
||||
supports; those are detailed in the following sections.
|
||||
|
||||
*Note*: If you are using RHEL7/CentOS 7, gcc 4.8 is too old to compile mlpack.
|
||||
One option is to use `devtoolset-8`; see
|
||||
[here](https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/) for more
|
||||
information.
|
||||
Once headers are installed with `make install`, using mlpack in an application
|
||||
consists only of including it. So, your program should include mlpack:
|
||||
|
||||
There are some useful pages to consult in addition to this section:
|
||||
```c++
|
||||
#include <mlpack.hpp>
|
||||
```
|
||||
|
||||
- [Building mlpack From Source](https://www.mlpack.org/doc/mlpack-git/doxygen/build.html)
|
||||
- [Building mlpack From Source on Windows](https://www.mlpack.org/doc/mlpack-git/doxygen/build_windows.html)
|
||||
and when you link, be sure to link against Armadillo. If your example program
|
||||
is `my_program.cpp`, your compiler is GCC, and you would like to compile with
|
||||
OpenMP support (recommended) and optimizations, compile like this:
|
||||
|
||||
mlpack uses CMake as a build system and allows several flexible build
|
||||
configuration options. You can consult any of the CMake tutorials for
|
||||
further documentation, but this tutorial should be enough to get mlpack built
|
||||
and installed.
|
||||
```sh
|
||||
g++ -O3 -std=c++14 -o my_program my_program.cpp -larmadillo -fopenmp
|
||||
```
|
||||
|
||||
First, unpack the mlpack source and change into the unpacked directory. Here we
|
||||
use mlpack-x.y.z where x.y.z is the version.
|
||||
See the [examples](https://github.com/mlpack/examples) repository for some
|
||||
examples of mlpack applications in C++, with corresponding `Makefile`s.
|
||||
|
||||
$ tar -xzf mlpack-x.y.z.tar.gz
|
||||
$ cd mlpack-x.y.z
|
||||
### 4. Building mlpack bindings to other languages
|
||||
|
||||
Then, make a build directory. The directory can have any name, but 'build' is
|
||||
sufficient.
|
||||
mlpack is not just a header-only library: it also comes with bindings to a
|
||||
number of other languages, this allows flexible use of mlpack's efficient
|
||||
implementations from languages that aren't C++.
|
||||
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
In general, you should *not* need to build these by hand---they should be
|
||||
provided by either your system package manager or your language's package
|
||||
manager.
|
||||
|
||||
The next step is to run CMake to configure the project. Running CMake is the
|
||||
equivalent to running `./configure` with autotools. If you run CMake with no
|
||||
options, it will configure the project to build with no debugging symbols and
|
||||
no profiling information:
|
||||
Building the bindings for a particular language is done by calling `cmake` with
|
||||
different options; each example below shows how to configure an individual set
|
||||
of bindings, but it is of course possible to combine the options and build
|
||||
bindings for many languages at once.
|
||||
|
||||
$ cmake ../
|
||||
#### 4a. Command-line programs
|
||||
|
||||
Options can be specified to compile with debugging information and profiling information:
|
||||
The command-line programs have no extra dependencies. The set of programs that
|
||||
will be compiled is detailed and documented on the [command-line program
|
||||
documentation page](https://www.mlpack.org/doc/stable/cli_documentation.html).
|
||||
|
||||
$ cmake -D DEBUG=ON -D PROFILE=ON ../
|
||||
From the root of the mlpack sources, run the following commands to build and
|
||||
install the command-line bindings:
|
||||
|
||||
Options are specified with the -D flag. The allowed options include:
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_CLI_PROGRAMS=ON ../
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
DEBUG=(ON/OFF): compile with debugging symbols
|
||||
PROFILE=(ON/OFF): compile with profiling symbols
|
||||
ARMA_EXTRA_DEBUG=(ON/OFF): compile with extra Armadillo debugging symbols
|
||||
ARMADILLO_INCLUDE_DIR=(/path/to/armadillo/include/): path to Armadillo headers
|
||||
ARMADILLO_LIBRARY=(/path/to/armadillo/libarmadillo.so): Armadillo library
|
||||
BUILD_CLI_EXECUTABLES=(ON/OFF): whether or not to build command-line programs
|
||||
BUILD_PYTHON_BINDINGS=(ON/OFF): whether or not to build Python bindings
|
||||
PYTHON_EXECUTABLE=(/path/to/python_version): Path to specific Python executable
|
||||
PYTHON_INSTALL_PREFIX=(/path/to/python/): Path to root of Python installation
|
||||
BUILD_JULIA_BINDINGS=(ON/OFF): whether or not to build Julia bindings
|
||||
JULIA_EXECUTABLE=(/path/to/julia): Path to specific Julia executable
|
||||
BUILD_GO_BINDINGS=(ON/OFF): whether or not to build Go bindings
|
||||
GO_EXECUTABLE=(/path/to/go): Path to specific Go executable
|
||||
BUILD_GO_SHLIB=(ON/OFF): whether or not to build shared libraries required by Go bindings
|
||||
BUILD_R_BINDINGS=(ON/OFF): whether or not to build R bindings
|
||||
R_EXECUTABLE=(/path/to/R): Path to specific R executable
|
||||
BUILD_TESTS=(ON/OFF): whether or not to build tests
|
||||
BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries and executables as
|
||||
opposed to static libraries
|
||||
DISABLE_DOWNLOADS=(ON/OFF): whether to disable all downloads during build
|
||||
ENSMALLEN_INCLUDE_DIR=(/path/to/ensmallen/include): path to include directory
|
||||
for ensmallen
|
||||
STB_IMAGE_INCLUDE_DIR=(/path/to/stb/include): path to include directory for
|
||||
STB image library
|
||||
USE_OPENMP=(ON/OFF): whether or not to use OpenMP if available
|
||||
BUILD_DOCS=(ON/OFF): build Doxygen documentation, if Doxygen is available
|
||||
(default ON)
|
||||
You can use `make -j<N>`, where `N` is the number of cores on your machine, to
|
||||
build in parallel; e.g., `make -j4` will use 4 cores to build.
|
||||
|
||||
For example, to build mlpack's CLI bindings statically the following command can
|
||||
be used:
|
||||
#### 4b. Python bindings
|
||||
|
||||
$ cmake -D BUILD_SHARED_LIBS=OFF ../
|
||||
mlpack's Python bindings are available on
|
||||
[PyPI](https://pypi.org/project/mlpack) and
|
||||
[conda-forge](https://conda-forge.org/packages/mlpack), and can be installed
|
||||
with either `pip install mlpack` or `conda install -c conda-forge mlpack`.
|
||||
These sources are recommended, as building the Python bindings by hand can be
|
||||
complex.
|
||||
|
||||
Other tools can also be used to configure CMake, but those are not documented
|
||||
here. See [this section of the build guide](https://www.mlpack.org/doc/mlpack-git/doxygen/build.html#build_config)
|
||||
for more details, including a full list of options, and their default values.
|
||||
With that in mind, if you would still like to manually build the mlpack Python
|
||||
bindings, first make sure that the following Python packages are installed:
|
||||
|
||||
By default, command-line programs will be built, and if the Python dependencies
|
||||
(Cython, setuptools, numpy, pandas) are available, then Python bindings will
|
||||
also be built. OpenMP will be used for parallelization when possible by
|
||||
default.
|
||||
- setuptools
|
||||
- cython >= 0.24
|
||||
- numpy
|
||||
- pandas >= 0.15.0
|
||||
|
||||
Once CMake is configured, building the library is as simple as typing 'make'.
|
||||
This will build all library components and bindings.
|
||||
Now, from the root of the mlpack sources, run the following commands to build
|
||||
and install the Python bindings:
|
||||
|
||||
$ make
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_PYTHON_BINDINGS=ON ../
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
If you do not want to build everything in the library, individual components
|
||||
of the build can be specified:
|
||||
You can use `make -j<N>`, where `N` is the number of cores on your machine, to
|
||||
build in parallel; e.g., `make -j4` will use 4 cores to build. You can also
|
||||
specify a custom Python interpreter with the CMake option
|
||||
`-DPYTHON_EXECUTABLE=/path/to/python`.
|
||||
|
||||
$ make mlpack_pca mlpack_knn mlpack_kfn
|
||||
#### 4c. R bindings
|
||||
|
||||
If you want to build the tests, just make the `mlpack_test` target, and use
|
||||
`ctest` to run the tests:
|
||||
mlpack's R bindings are available as the R package
|
||||
[mlpack](https://cran.r-project.org/web/packages/mlpack/index.html) on CRAN.
|
||||
You can install the package by running `install.packages('mlpack')`, and this is
|
||||
the recommended way of getting mlpack in R.
|
||||
|
||||
$ make mlpack_test
|
||||
$ ctest .
|
||||
If you still wish to build the R bindings by hand, first make sure the following
|
||||
dependencies are installed:
|
||||
|
||||
If the build fails and you cannot figure out why, register an account on Github
|
||||
and submit an issue. The mlpack developers will quickly help you figure it out:
|
||||
- R >= 4.0
|
||||
- Rcpp >= 0.12.12
|
||||
- RcppArmadillo >= 0.9.800.0
|
||||
- RcppEnsmallen >= 0.2.10.0
|
||||
- roxygen2
|
||||
- testthat
|
||||
- pkgbuild
|
||||
|
||||
These can be installed with `install.packages()` inside of your R environment.
|
||||
Once the dependencies are available, you can configure mlpack and build the R
|
||||
bindings by running the following commands from the root of the mlpack sources:
|
||||
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_R_BINDINGS=ON ../
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
You may need to specify the location of the R program in the `cmake` command
|
||||
with the option `-DR_EXECUTABLE=/path/to/R`.
|
||||
|
||||
Once the build is complete, a tarball can be found under the build directory in
|
||||
`src/mlpack/bindings/R/`, and then that can be installed into your R environment
|
||||
with a command like `install.packages(mlpack_3.4.3.tar.gz, repos=NULL,
|
||||
type='source')`.
|
||||
|
||||
#### 4d. Julia bindings
|
||||
|
||||
mlpack's Julia bindings are available by installing the
|
||||
[mlpack.jl](https://github.com/mlpack/mlpack.jl) package using
|
||||
`Pkg.add("mlpack.jl")`. The process of building, packaging, and distributing
|
||||
mlpack's Julia bindings is very nontrivial, so it is recommended to simply use
|
||||
the version available in `Pkg`, but if you want to build the bindings by hand
|
||||
anyway, you can configure and build them by running the following commands from
|
||||
the root of the mlpack sources:
|
||||
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_JULIA_BINDINGS=ON ../
|
||||
make
|
||||
```
|
||||
|
||||
If CMake cannot find your Julia installation, you can add
|
||||
`-DJULIA_EXECUTABLE=/path/to/julia` to the CMake configuration step.
|
||||
|
||||
Note that the `make install` step is not done above, since the Julia binding
|
||||
build system was not meant to be installed directly. Instead, to use handbuilt
|
||||
bindings (for instance, to test them), one option is to start Julia with
|
||||
`JULIA_PROJECT` set as an environment variable:
|
||||
|
||||
```sh
|
||||
cd build/src/mlpack/bindings/julia/mlpack/
|
||||
JULIA_PROJECT=$PWD julia
|
||||
```
|
||||
|
||||
and then `using mlpack` should work.
|
||||
|
||||
#### 4e. Go bindings
|
||||
|
||||
To build mlpack's Go bindings, ensure that Go >= 1.11.0 is installed, and that
|
||||
the Gonum package is available.
|
||||
***TODO: how do you install these?***
|
||||
|
||||
Then, configuring and building the bindings can be done by running the following
|
||||
commands from the root of the mlpack sources:
|
||||
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_GO_BINDINGS=ON ../
|
||||
make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
### 5. Building mlpack's test suite
|
||||
|
||||
mlpack contains an extensive test suite that exercises every part of the
|
||||
codebase. It is easy to build and run the tests with CMake and CTest, as below:
|
||||
|
||||
```sh
|
||||
mkdir build && cd build/
|
||||
cmake -DBUILD_TESTS=ON ../
|
||||
make
|
||||
ctest .
|
||||
```
|
||||
|
||||
If you want to test the bindings, too, you will have to adapt the CMake
|
||||
configuration command to turn on the language bindings that you want to
|
||||
test---see the previous sections for details.
|
||||
|
||||
### 6. Further Resources
|
||||
|
||||
|
||||
|
||||
****
|
||||
Tutorials to keep for users:
|
||||
|
||||
formats.hpp (fine as-is)
|
||||
build_windows.hpp (needs adaptation)
|
||||
cv.hpp (as-is)
|
||||
hpt.hpp (as-is)
|
||||
sample_ml_app.hpp (pass through and adapt)
|
||||
|
||||
needs earlier links:
|
||||
cli_quickstart.hpp
|
||||
go_quickstart.hpp
|
||||
julia_quickstart.hpp
|
||||
python_quickstart.hpp
|
||||
r_quickstart.hpp
|
||||
|
||||
Developer tutorials:
|
||||
|
||||
timer.hpp
|
||||
version.hpp
|
||||
policies/
|
||||
bindings.hpp (but it's advanced)
|
||||
iodoc.hpp (also advanced, needs adaptation)
|
||||
|
||||
remove sample.hpp, and point instead towards examples/ repository
|
||||
****
|
||||
|
||||
[mlpack on Github](https://www.github.com/mlpack/mlpack/)
|
||||
|
||||
@@ -274,73 +367,6 @@ You can now run the executables by name; the mlpack headers are found in
|
||||
and if Python bindings were built, you can access them with the `mlpack`
|
||||
package in Python.
|
||||
|
||||
### 5. Running mlpack programs
|
||||
|
||||
After building mlpack, the executables will reside in `build/bin/`. You can
|
||||
call them from there, or you can install the library and (depending on system
|
||||
settings) they should be added to your PATH and you can call them directly. The
|
||||
documentation below assumes the executables are in your PATH.
|
||||
|
||||
Consider the 'mlpack_knn' program, which finds the k nearest neighbors in a
|
||||
reference dataset of all the points in a query set. That is, we have a query
|
||||
and a reference dataset. For each point in the query dataset, we wish to know
|
||||
the k points in the reference dataset which are closest to the given query
|
||||
point.
|
||||
|
||||
Alternately, if the query and reference datasets are the same, the problem can
|
||||
be stated more simply: for each point in the dataset, we wish to know the k
|
||||
nearest points to that point.
|
||||
|
||||
Each mlpack program has extensive help documentation which details what the
|
||||
method does, what each of the parameters is, and how to use them:
|
||||
|
||||
```shell
|
||||
$ mlpack_knn --help
|
||||
```
|
||||
|
||||
Running `mlpack_knn` on one dataset (that is, the query and reference
|
||||
datasets are the same) and finding the 5 nearest neighbors is very simple:
|
||||
|
||||
```shell
|
||||
$ mlpack_knn -r dataset.csv -n neighbors_out.csv -d distances_out.csv -k 5 -v
|
||||
```
|
||||
|
||||
The `-v (--verbose)` flag is optional; it gives informational output. It is not
|
||||
unique to `mlpack_knn` but is available in all mlpack programs. Verbose
|
||||
output also gives timing output at the end of the program, which can be very
|
||||
useful.
|
||||
|
||||
### 6. Using mlpack from Python
|
||||
|
||||
If mlpack is installed to the system, then the mlpack Python bindings should be
|
||||
automatically in your PYTHONPATH, and importing mlpack functionality into Python
|
||||
should be very simple:
|
||||
|
||||
```python
|
||||
>>> from mlpack import knn
|
||||
```
|
||||
|
||||
Accessing help is easy:
|
||||
|
||||
```python
|
||||
>>> help(knn)
|
||||
```
|
||||
|
||||
The API is similar to the command-line programs. So, running `knn()`
|
||||
(k-nearest-neighbor search) on the numpy matrix `dataset` and finding the 5
|
||||
nearest neighbors is very simple:
|
||||
|
||||
```python
|
||||
>>> output = knn(reference=dataset, k=5, verbose=True)
|
||||
```
|
||||
|
||||
This will store the output neighbors in `output['neighbors']` and the output
|
||||
distances in `output['distances']`. Other mlpack bindings function similarly,
|
||||
and the input/output parameters exactly match those of the command-line
|
||||
programs.
|
||||
|
||||
### 7. Further documentation
|
||||
|
||||
The documentation given here is only a fraction of the available documentation
|
||||
for mlpack. If doxygen is installed, you can type `make doc` to build the
|
||||
documentation locally. Alternately, up-to-date documentation is available for
|
||||
@@ -355,8 +381,6 @@ older versions of mlpack:
|
||||
To learn about the development goals of mlpack in the short- and medium-term
|
||||
future, see the [vision document](https://www.mlpack.org/papers/vision.pdf).
|
||||
|
||||
### 8. Bug reporting
|
||||
|
||||
(see also [mlpack help](https://www.mlpack.org/questions.html))
|
||||
|
||||
If you find a bug in mlpack or have any problems, numerous routes are available
|
||||
|
||||
@@ -1,45 +1,34 @@
|
||||
/**
|
||||
* @file r_quickstart.hpp
|
||||
* @author Yashwant Singh Parihar
|
||||
|
||||
@page r_quickstart mlpack in R quickstart guide
|
||||
|
||||
@section r_quickstart_intro Introduction
|
||||
# mlpack in R quickstart guide
|
||||
|
||||
This page describes how you can quickly get started using mlpack from R and
|
||||
gives a few examples of usage, and pointers to deeper documentation.
|
||||
|
||||
This quickstart guide is also available for @ref python_quickstart "Python",
|
||||
@ref cli_quickstart "the command-line", @ref julia_quickstart "Julia" and
|
||||
@ref go_quickstart "Go".
|
||||
This quickstart guide is also available for [Python]( ), [Julia]( ),
|
||||
[the command line]( ), and [Go]( ).
|
||||
|
||||
@section r_quickstart_install Installing mlpack binary package
|
||||
## Installing mlpack
|
||||
|
||||
Installing the mlpack bindings for R is straightforward; you can just use
|
||||
CRAN:
|
||||
|
||||
@code{.R}
|
||||
```r
|
||||
install.packages('mlpack')
|
||||
@endcode
|
||||
|
||||
@section r_quickstart_source_install Installing mlpack package from source
|
||||
```
|
||||
|
||||
Building the R bindings from scratch is a little more in-depth, though. For
|
||||
information on that, follow the instructions on the @ref build page, and be sure
|
||||
to specify @c -DBUILD_R_BINDINGS=ON to CMake; you may need to also set the
|
||||
location of the R program with @c -DR_EXECUTABLE=/path/to/R.
|
||||
information on that, follow the instructions in the [main README]( ).
|
||||
|
||||
@section r_quickstart_example Simple mlpack quickstart example
|
||||
## Simple mlpack quickstart example
|
||||
|
||||
As a really simple example of how to use mlpack from R, let's do some
|
||||
simple classification on a subset of the standard machine learning @c covertype
|
||||
simple classification on a subset of the standard machine learning `covertype`
|
||||
dataset. We'll first split the dataset into a training set and a testing set,
|
||||
then we'll train an mlpack random forest on the training data, and finally we'll
|
||||
print the accuracy of the random forest on the test dataset.
|
||||
|
||||
You can copy-paste this code directly into R to run it.
|
||||
|
||||
@code{.R}
|
||||
```r
|
||||
if(!requireNamespace("data.table", quietly = TRUE)) { install.packages("data.table") }
|
||||
suppressMessages({
|
||||
library("mlpack")
|
||||
@@ -79,38 +68,26 @@ output <- random_forest(input_model = rf_model,
|
||||
correct <- sum(output$predictions == prepdata$test_labels)
|
||||
cat(correct, "out of", length(prepdata$test_labels), "test points correct",
|
||||
correct / length(prepdata$test_labels) * 100.0, "%\n")
|
||||
@endcode
|
||||
```
|
||||
|
||||
We can see that we achieve reasonably good accuracy on the test dataset (80%+);
|
||||
if we use the full @c covertype.csv.gz, the accuracy should increase
|
||||
if we use the full `covertype.csv.gz`, the accuracy should increase
|
||||
significantly (but training will take longer).
|
||||
|
||||
It's easy to modify the code above to do more complex things, or to use
|
||||
different mlpack learners, or to interface with other machine learning toolkits.
|
||||
|
||||
@section r_quickstart_whatelse What else does mlpack implement?
|
||||
|
||||
The example above has only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of each of these commands and full documentation can be found on the following
|
||||
page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/r_documentation.html">r documentation</a>
|
||||
|
||||
For more information on what mlpack does, see https://www.mlpack.org/.
|
||||
Next, let's go through another example for providing movie recommendations with
|
||||
mlpack.
|
||||
|
||||
@section r_quickstart_movierecs Using mlpack for movie recommendations
|
||||
## Using mlpack for movie recommendations
|
||||
|
||||
In this example, we'll train a collaborative filtering model using mlpack's
|
||||
<tt><a href="https://www.mlpack.org/doc/mlpack-git/r_documentation.html#cf">cf()</a></tt> method. We'll train this on the MovieLens dataset from
|
||||
https://grouplens.org/datasets/movielens/, and then we'll use the model that we
|
||||
train to give recommendations.
|
||||
[`cf()`](https://www.mlpack.org/doc/stable/r_documentation.html#cf) method.
|
||||
We'll train this on the
|
||||
[MovieLens dataset](https://grouplens.org/datasets/movielens/), and then we'll
|
||||
use the model that we train to give recommendations.
|
||||
|
||||
You can copy-paste this code directly into R to run it.
|
||||
|
||||
@code{.R}
|
||||
```r
|
||||
if(!requireNamespace("data.table", quietly = TRUE)) { install.packages("data.table") }
|
||||
suppressMessages({
|
||||
library("mlpack")
|
||||
@@ -148,12 +125,12 @@ cat("Recommendations for user 1:\n")
|
||||
for (i in 1:10) {
|
||||
cat(" ", i, ":", as.character(movies[output$output[i], 3]), "\n")
|
||||
}
|
||||
@endcode
|
||||
```
|
||||
|
||||
Here is some example output, showing that user 1 seems to have good taste in
|
||||
movies:
|
||||
|
||||
@code{.unparsed}
|
||||
```
|
||||
Recommendations for user 1:
|
||||
0: Casablanca (1942)
|
||||
1: Pan's Labyrinth (Laberinto del fauno, El) (2006)
|
||||
@@ -165,29 +142,20 @@ Recommendations for user 1:
|
||||
7: Out for Justice (1991)
|
||||
8: Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
|
||||
9: Schindler's List (1993)
|
||||
@endcode
|
||||
```
|
||||
|
||||
@section r_quickstart_nextsteps Next steps with mlpack
|
||||
## Next steps with mlpack
|
||||
|
||||
After working through this overview to `mlpack`'s R package, we hope you are
|
||||
inspired to use `mlpack`' in your data science workflow. We recommend as part
|
||||
of your next steps to look at more documentation for the R mlpack bindings:
|
||||
inspired to use `mlpack`' in your data science workflow. However, the two
|
||||
examples above have only shown a little bit of the functionality of mlpack.
|
||||
Lots of other functions are available with different functionality. A full list
|
||||
of each of these functions and full documentation can be found on the following
|
||||
page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/r_documentation.html">R mlpack
|
||||
binding documentation</a>
|
||||
- [R documentation](https://www.mlpack.org/doc/stable/r_documentation.html)
|
||||
|
||||
Also, mlpack is much more flexible from C++ and allows much greater
|
||||
functionality. So, more complicated tasks are possible if you are willing to
|
||||
write C++ (or perhaps Rcpp). To get started learning about mlpack in C++, the
|
||||
following resources might be helpful:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html">mlpack
|
||||
C++ tutorials</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/build.html">mlpack
|
||||
build and installation guide</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/sample.html">Simple
|
||||
sample C++ mlpack programs</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/index.html">mlpack
|
||||
Doxygen documentation homepage</a>
|
||||
|
||||
*/
|
||||
write C++ (or perhaps Rcpp). To get started learning about mlpack in C++, a
|
||||
good starting point is the [C++ quickstart guide]( ).
|
||||
@@ -1,58 +1,50 @@
|
||||
/**
|
||||
* @file cli_quickstart.hpp
|
||||
* @author Ryan Curtin
|
||||
|
||||
@page cli_quickstart mlpack command-line quickstart guide
|
||||
|
||||
@section cli_quickstart_intro Introduction
|
||||
# mlpack command-line quickstart guide
|
||||
|
||||
This page describes how you can quickly get started using mlpack from the
|
||||
command-line and gives a few examples of usage, and pointers to deeper
|
||||
documentation.
|
||||
|
||||
This quickstart guide is also available for @ref python_quickstart "Python",
|
||||
@ref r_quickstart "R", @ref julia_quickstart "Julia" and
|
||||
@ref go_quickstart "Go".
|
||||
This quickstart guide is also available for [Python]( ), [R]( ), [Julia]( ), and
|
||||
[Go]( ).
|
||||
|
||||
@section cli_quickstart_install Installing mlpack
|
||||
## Installing mlpack
|
||||
|
||||
Installing the mlpack is straightforward and can be done with your system's
|
||||
package manager.
|
||||
Installing mlpack is straightforward and can be done with your system's package
|
||||
manager. For instance, for Ubuntu or Debian the command is simply
|
||||
|
||||
For instance, for Ubuntu or Debian the command is simply
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
sudo apt-get install mlpack-bin
|
||||
@endcode
|
||||
```
|
||||
|
||||
On Fedora or Red Hat:
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
sudo dnf install mlpack
|
||||
@endcode
|
||||
```
|
||||
|
||||
If you use a different distribution, mlpack may be packaged under a different
|
||||
name. And if it is not packaged, you can use a Docker image from Dockerhub:
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
docker run -it mlpack/mlpack /bin/bash
|
||||
@endcode
|
||||
```
|
||||
|
||||
This Docker image has mlpack already built and installed.
|
||||
This Docker image has mlpack's command-line bindings already built and
|
||||
installed.
|
||||
|
||||
If you prefer to build mlpack from scratch, see @ref build.
|
||||
If you prefer to build mlpack from scratch, see the [main README]( ).
|
||||
|
||||
@section cli_quickstart_example Simple mlpack quickstart example
|
||||
## Simple quickstart example
|
||||
|
||||
As a really simple example of how to use mlpack from the command-line, let's do
|
||||
some simple classification on a subset of the standard machine learning @c
|
||||
covertype dataset. We'll first split the dataset into a training set and a
|
||||
some simple classification on a subset of the standard machine learning
|
||||
`covertype` dataset. We'll first split the dataset into a training set and a
|
||||
testing set, then we'll train an mlpack random forest on the training data, and
|
||||
finally we'll print the accuracy of the random forest on the test dataset.
|
||||
|
||||
You can copy-paste this code directly into your shell to run it.
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
# Get the dataset and unpack it.
|
||||
wget https://www.mlpack.org/datasets/covertype-small.data.csv.gz
|
||||
wget https://www.mlpack.org/datasets/covertype-small.labels.csv.gz
|
||||
@@ -89,42 +81,30 @@ mlpack_random_forest \
|
||||
--test_labels_file covertype-small.test.labels.csv \
|
||||
--predictions_file predictions.csv \
|
||||
--verbose
|
||||
@endcode
|
||||
```
|
||||
|
||||
We can see by looking at the output that we achieve reasonably good accuracy on
|
||||
the test dataset (80%+). The file @c predictions.csv could also be used by
|
||||
the test dataset (80%+). The file `predictions.csv` could also be used by
|
||||
other tools; for instance, we can easily calculate the number of points that
|
||||
were predicted incorrectly:
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
$ diff -U 0 predictions.csv covertype-small.test.labels.csv | grep '^@@' | wc -l
|
||||
@endcode
|
||||
```
|
||||
|
||||
It's easy to modify the code above to do more complex things, or to use
|
||||
different mlpack learners, or to interface with other machine learning toolkits.
|
||||
|
||||
@section cli_quickstart_whatelse What else does mlpack implement?
|
||||
|
||||
The example above has only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of commands and full documentation for each can be found on the following page:
|
||||
|
||||
- <a href="https://mlpack.org/doc/mlpack-git/cli_documentation.html">CLI documentation</a>
|
||||
|
||||
For more information on what mlpack does, see https://www.mlpack.org/. Next,
|
||||
let's go through another example for providing movie recommendations with
|
||||
mlpack.
|
||||
|
||||
@section cli_quickstart_movierecs Using mlpack for movie recommendations
|
||||
## Using mlpack for movie recommendations
|
||||
|
||||
In this example, we'll train a collaborative filtering model using mlpack's
|
||||
@c mlpack_cf program. We'll train this on the MovieLens dataset from
|
||||
https://grouplens.org/datasets/movielens/, and then we'll use the model that we
|
||||
train to give recommendations.
|
||||
`mlpack_cf` program. We'll train this on the
|
||||
[MovieLens dataset](https://grouplens.org/datasets/movielens/), and then we'll
|
||||
use the model that we train to give recommendations.
|
||||
|
||||
You can copy-paste this code directly into the command line to run it.
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
wget https://www.mlpack.org/datasets/ml-20m/ratings-only.csv.gz
|
||||
wget https://www.mlpack.org/datasets/ml-20m/movies.csv.gz
|
||||
gunzip ratings-only.csv.gz
|
||||
@@ -165,12 +145,12 @@ for i in `seq 1 10`; do
|
||||
sed 's/^[^,]*,[^,]*,//' | \
|
||||
sed 's/\(.*\),.*$/\1/' | sed 's/"//g';
|
||||
done
|
||||
@endcode
|
||||
```
|
||||
|
||||
Here is some example output, showing that user 1 seems to have good taste in
|
||||
movies:
|
||||
|
||||
@code{.unparsed}
|
||||
```
|
||||
Recommendations for user 1:
|
||||
Casablanca (1942)
|
||||
Pan's Labyrinth (Laberinto del fauno, El) (2006)
|
||||
@@ -182,30 +162,22 @@ Dark Knight, The (2008)
|
||||
Out for Justice (1991)
|
||||
Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
|
||||
Schindler's List (1993)
|
||||
@endcode
|
||||
```
|
||||
## Next steps wtih mlpack
|
||||
|
||||
@section cli_quickstart_nextsteps Next steps with mlpack
|
||||
For more information on what mlpack does, see the [mlpack
|
||||
homepage](https://www.mlpack.org). Next, let's go through another example for
|
||||
providing movie recommendations with mlpack.
|
||||
|
||||
Now that you have done some simple work with mlpack, you have seen how it can
|
||||
easily plug into a data science production workflow for the command line. A
|
||||
great thing to do next would be to look at more documentation for the mlpack
|
||||
command-line programs:
|
||||
easily plug into a data science production workflow for the command line. But
|
||||
these two examples have only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of commands and full documentation for each can be found on the following page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/cli_documentation.html">mlpack
|
||||
command-line program documentation</a>
|
||||
- [CLI program documentation](https://www.mlpack.org/doc/stable/cli_documentation.html)
|
||||
|
||||
Also, mlpack is much more flexible from C++ and allows much greater
|
||||
functionality. So, more complicated tasks are possible if you are willing to
|
||||
write C++. To get started learning about mlpack in C++, the following resources
|
||||
might be helpful:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html">mlpack
|
||||
C++ tutorials</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/build.html">mlpack
|
||||
build and installation guide</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/sample.html">Simple
|
||||
sample C++ mlpack programs</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/index.html">mlpack
|
||||
Doxygen documentation homepage</a>
|
||||
|
||||
*/
|
||||
write C++. To get started learning about mlpack in C++, the [C++ quickstart]( )
|
||||
is a good place to start.
|
||||
@@ -1,43 +1,35 @@
|
||||
/**
|
||||
* @file go_quickstart.hpp
|
||||
* @author Yashwant Singh Parihar
|
||||
|
||||
@page go_quickstart mlpack in Go quickstart guide
|
||||
|
||||
@section go_quickstart_intro Introduction
|
||||
# mlpack in Go quickstart guide
|
||||
|
||||
This page describes how you can quickly get started using mlpack from Go and
|
||||
gives a few examples of usage, and pointers to deeper documentation.
|
||||
|
||||
This quickstart guide is also available for @ref python_quickstart "Python",
|
||||
@ref cli_quickstart "the command-line", @ref julia_quickstart "Julia" and
|
||||
@ref r_quickstart "R".
|
||||
This quickstart guide is also available for [Python]( ), [Julia]( ),
|
||||
[the command line]( ), and [R]( ).
|
||||
|
||||
@section go_quickstart_install Installing mlpack
|
||||
## Installing mlpack
|
||||
|
||||
Installing the mlpack bindings for Go is somewhat time-consuming as the library
|
||||
must be built; you can run the following code:
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
go get -u -d mlpack.org/v1/mlpack
|
||||
cd ${GOPATH}/src/mlpack.org/v1/mlpack
|
||||
make install
|
||||
@endcode
|
||||
|
||||
```
|
||||
Building the Go bindings from scratch is a little more in-depth, though. For
|
||||
information on that, follow the instructions on the @ref build page, and be sure
|
||||
to specify @c -DBUILD_GO_BINDINGS=ON to CMake;
|
||||
information on that, follow the instructions in the [main README]( ).
|
||||
|
||||
@section go_quickstart_example Simple mlpack quickstart example
|
||||
## Simple mlpack quickstart example
|
||||
|
||||
As a really simple example of how to use mlpack from Go, let's do some
|
||||
simple classification on a subset of the standard machine learning @c covertype
|
||||
simple classification on a subset of the standard machine learning `covertype`
|
||||
dataset. We'll first split the dataset into a training set and a testing set,
|
||||
then we'll train an mlpack random forest on the training data, and finally we'll
|
||||
print the accuracy of the random forest on the test dataset.
|
||||
|
||||
You can copy-paste this code directly into main.go to run it.
|
||||
@code{.go}
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -95,41 +87,26 @@ func main() {
|
||||
fmt.Print(sum, " correct out of ", rows, " (",
|
||||
(float64(sum) / float64(rows)) * 100, "%).\n")
|
||||
}
|
||||
@endcode
|
||||
```
|
||||
|
||||
We can see that we achieve reasonably good accuracy on the test dataset (80%+);
|
||||
if we use the full @c covertype.csv.gz, the accuracy should increase
|
||||
if we use the full `covertype.csv.gz`, the accuracy should increase
|
||||
significantly (but training will take longer).
|
||||
|
||||
It's easy to modify the code above to do more complex things, or to use
|
||||
different mlpack learners, or to interface with other machine learning toolkits.
|
||||
|
||||
@section go_quickstart_whatelse What else does mlpack implement?
|
||||
|
||||
The example above has only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of each of these commands and full documentation can be found on the following
|
||||
page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/go_documentation.html">Go documentation</a>
|
||||
|
||||
You can also use the GoDoc to explore the @c mlpack module and its
|
||||
functions; every function comes with comprehensive documentation.
|
||||
|
||||
For more information on what mlpack does, see https://www.mlpack.org/.
|
||||
Next, let's go through another example for providing movie recommendations with
|
||||
mlpack.
|
||||
|
||||
@section go_quickstart_movierecs Using mlpack for movie recommendations
|
||||
## Using mlpack for movie recommendations
|
||||
|
||||
In this example, we'll train a collaborative filtering model using mlpack's
|
||||
<tt><a href="https://www.mlpack.org/doc/mlpack-git/go_documentation.html#cf">Cf()</a></tt> method. We'll train this on the MovieLens dataset from
|
||||
https://grouplens.org/datasets/movielens/, and then we'll use the model that we
|
||||
train to give recommendations.
|
||||
[`cf()`](https://www.mlpack.org/doc/stable/go_documentation.html#cf) method.
|
||||
We'll train this on the
|
||||
[MovieLens dataset](https://grouplens.org/datasets/movielens/), and then we'll
|
||||
use the model that we train to give recommendations.
|
||||
|
||||
You can copy-paste this code directly into main.go to run it.
|
||||
|
||||
@code{.go}
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -185,12 +162,12 @@ func main() {
|
||||
fmt.Println(i, ":", movies[int(output.At(0 , i))])
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
```
|
||||
|
||||
Here is some example output, showing that user 1 seems to have good taste in
|
||||
movies:
|
||||
|
||||
@code{.unparsed}
|
||||
```
|
||||
Recommendations for user 1:
|
||||
0: Casablanca (1942)
|
||||
1: Pan's Labyrinth (Laberinto del fauno, El) (2006)
|
||||
@@ -202,29 +179,22 @@ Recommendations for user 1:
|
||||
7: Out for Justice (1991)
|
||||
8: Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
|
||||
9: Schindler's List (1993)
|
||||
@endcode
|
||||
```
|
||||
|
||||
@section go_quickstart_nextsteps Next steps with mlpack
|
||||
## Next steps with mlpack
|
||||
|
||||
Now that you have done some simple work with mlpack, you have seen how it can
|
||||
easily plug into a data science workflow in Go. A great thing to do next
|
||||
would be to look at more documentation for the Go mlpack bindings:
|
||||
easily plug into a data science workflow in Go. But the two examples above have
|
||||
only shown a little bit of the functionality of mlpack. Lots of other methods
|
||||
are available with different functionality. A full list of each of these
|
||||
methods and full documentation can be found on the following page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/go_documentation.html">Go mlpack
|
||||
binding documentation</a>
|
||||
- [mlpack Go binding documentation](https://www.mlpack.org/doc/stable/go_documentation.html)
|
||||
|
||||
You can also use GoDoc to explore the `mlpack` module and its functions; every
|
||||
function comes with comprehensive documentation.
|
||||
|
||||
Also, mlpack is much more flexible from C++ and allows much greater
|
||||
functionality. So, more complicated tasks are possible if you are willing to
|
||||
write C++. To get started learning about mlpack in C++, the following resources
|
||||
might be helpful:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html">mlpack
|
||||
C++ tutorials</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/build.html">mlpack
|
||||
build and installation guide</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/sample.html">Simple
|
||||
sample C++ mlpack programs</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/index.html">mlpack
|
||||
Doxygen documentation homepage</a>
|
||||
|
||||
*/
|
||||
write C++. To get started learning about mlpack in C++, the [C++ quickstart]( )
|
||||
is a good resource to visit next.
|
||||
@@ -1,37 +1,28 @@
|
||||
/**
|
||||
* @file julia_quickstart.hpp
|
||||
* @author Ryan Curtin
|
||||
|
||||
@page julia_quickstart mlpack in Julia quickstart guide
|
||||
|
||||
@section julia_quickstart_intro Introduction
|
||||
# mlpack in Julia quickstart guide
|
||||
|
||||
This page describes how you can quickly get started using mlpack from Julia and
|
||||
gives a few examples of usage, and pointers to deeper documentation.
|
||||
|
||||
This quickstart guide is also available for @ref python_quickstart "Python",
|
||||
@ref cli_quickstart "the command-line", @ref go_quickstart "Go" and
|
||||
@ref r_quickstart "R".
|
||||
This quickstart guide is also available for [Python]( ), [the command line]( ),
|
||||
[R]( ), and [Go]( ).
|
||||
|
||||
@section julia_quickstart_install Installing mlpack
|
||||
## Installing mlpack
|
||||
|
||||
Installing the mlpack bindings for Julia is straightforward; you can just use
|
||||
@c Pkg:
|
||||
`Pkg`:
|
||||
|
||||
@code{.julia}
|
||||
```julia
|
||||
using Pkg
|
||||
Pkg.add("mlpack")
|
||||
@endcode
|
||||
```
|
||||
|
||||
Building the Julia bindings from scratch is a little more in-depth, though. For
|
||||
information on that, follow the instructions on the @ref build page, and be sure
|
||||
to specify @c -DBUILD_JULIA_BINDINGS=ON to CMake; you may need to also set the
|
||||
location of the Julia program with @c -DJULIA_EXECUTABLE=/path/to/julia.
|
||||
information on that, follow the instructions in the [main README]( ).
|
||||
|
||||
@section julia_quickstart_example Simple mlpack quickstart example
|
||||
## Simple quickstart example
|
||||
|
||||
As a really simple example of how to use mlpack from Julia, let's do some
|
||||
simple classification on a subset of the standard machine learning @c covertype
|
||||
simple classification on a subset of the standard machine learning `covertype`
|
||||
dataset. We'll first split the dataset into a training set and a testing set,
|
||||
then we'll train an mlpack random forest on the training data, and finally we'll
|
||||
print the accuracy of the random forest on the test dataset.
|
||||
@@ -40,7 +31,7 @@ You can copy-paste this code directly into Julia to run it. You may need to add
|
||||
some extra packages with, e.g., `using Pkg; Pkg.add("CSV");
|
||||
Pkg.add("DataFrames"); Pkg.add("Libz")`.
|
||||
|
||||
@code{.julia}
|
||||
```julia
|
||||
using CSV
|
||||
using DataFrames
|
||||
using Libz
|
||||
@@ -77,41 +68,26 @@ _, predictions, _ = mlpack.random_forest(input_model=rf_model,
|
||||
correct = sum(predictions .== test_labels)
|
||||
print("$(correct) out of $(length(test_labels)) test points correct " *
|
||||
"($(correct / length(test_labels) * 100.0)%).\n")
|
||||
@endcode
|
||||
```
|
||||
|
||||
We can see that we achieve reasonably good accuracy on the test dataset (80%+);
|
||||
if we use the full @c covertype.csv.gz, the accuracy should increase
|
||||
if we use the full `covertype.csv.gz`, the accuracy should increase
|
||||
significantly (but training will take longer).
|
||||
|
||||
It's easy to modify the code above to do more complex things, or to use
|
||||
different mlpack learners, or to interface with other machine learning toolkits.
|
||||
|
||||
@section julia_quickstart_whatelse What else does mlpack implement?
|
||||
|
||||
The example above has only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of each of these commands and full documentation can be found on the following
|
||||
page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/julia_documentation.html">Julia documentation</a>
|
||||
|
||||
You can also use the Julia REPL to explore the @c mlpack module and its
|
||||
functions; every function comes with comprehensive documentation.
|
||||
|
||||
For more information on what mlpack does, see https://www.mlpack.org/.
|
||||
Next, let's go through another example for providing movie recommendations with
|
||||
mlpack.
|
||||
|
||||
@section julia_quickstart_movierecs Using mlpack for movie recommendations
|
||||
## Using mlpack for movie recommendations
|
||||
|
||||
In this example, we'll train a collaborative filtering model using mlpack's
|
||||
<tt><a href="https://www.mlpack.org/doc/mlpack-git/julia_documentation.html#cf">cf()</a></tt> method. We'll train this on the MovieLens dataset from
|
||||
https://grouplens.org/datasets/movielens/, and then we'll use the model that we
|
||||
train to give recommendations.
|
||||
[`cf()`](https://www.mlpack.org/doc/stable/julia_documentation.html#cf) method.
|
||||
We'll train this on the
|
||||
[MovieLens dataset](https://grouplens.org/datasets/movielens/), and then we'll
|
||||
use the model that we train to give recommendations.
|
||||
|
||||
You can copy-paste this code directly into Julia to run it.
|
||||
|
||||
@code{.julia}
|
||||
```julia
|
||||
using CSV
|
||||
using mlpack
|
||||
using Libz
|
||||
@@ -147,12 +123,12 @@ print("Recommendations for user 1:\n")
|
||||
for i in 1:10
|
||||
print(" $(i): $(movies[output[i], :][3])\n")
|
||||
end
|
||||
@endcode
|
||||
```
|
||||
|
||||
Here is some example output, showing that user 1 seems to have good taste in
|
||||
movies:
|
||||
|
||||
@code{.unparsed}
|
||||
```
|
||||
Recommendations for user 1:
|
||||
0: Casablanca (1942)
|
||||
1: Pan's Labyrinth (Laberinto del fauno, El) (2006)
|
||||
@@ -164,29 +140,22 @@ Recommendations for user 1:
|
||||
7: Out for Justice (1991)
|
||||
8: Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
|
||||
9: Schindler's List (1993)
|
||||
@endcode
|
||||
```
|
||||
|
||||
@section julia_quickstart_nextsteps Next steps with mlpack
|
||||
## Next steps with mlpack
|
||||
|
||||
Now that you have done some simple work with mlpack, you have seen how it can
|
||||
easily plug into a data science workflow in Julia. A great thing to do next
|
||||
would be to look at more documentation for the Julia mlpack bindings:
|
||||
easily plug into a data science workflow in Julia. But the two examples above
|
||||
have only shown a little bit of the functionality of mlpack. Lots of other
|
||||
functions are available with different functionality. A full list of each of
|
||||
these commands and full documentation can be found on the following page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/julia_documentation.html">Julia mlpack
|
||||
binding documentation</a>
|
||||
- [Julia documentation](https://www.mlpack.org/doc/stable/julia_documentation.html)
|
||||
|
||||
You can also use the Julia REPL to explore the `mlpack` module and its
|
||||
functions; every function comes with comprehensive documentation.
|
||||
|
||||
Also, mlpack is much more flexible from C++ and allows much greater
|
||||
functionality. So, more complicated tasks are possible if you are willing to
|
||||
write C++ (or perhaps CxxWrap.jl). To get started learning about mlpack in C++,
|
||||
the following resources might be helpful:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html">mlpack
|
||||
C++ tutorials</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/build.html">mlpack
|
||||
build and installation guide</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/sample.html">Simple
|
||||
sample C++ mlpack programs</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/index.html">mlpack
|
||||
Doxygen documentation homepage</a>
|
||||
|
||||
*/
|
||||
the [C++ quickstart]( ) would be a good place to start.
|
||||
@@ -1,69 +1,45 @@
|
||||
/**
|
||||
* @file python_quickstart.hpp
|
||||
* @author Ryan Curtin
|
||||
|
||||
@page python_quickstart mlpack in Python quickstart guide
|
||||
|
||||
@section python_quickstart_intro Introduction
|
||||
# mlpack in Python quickstart guide
|
||||
|
||||
This page describes how you can quickly get started using mlpack from Python and
|
||||
gives a few examples of usage, and pointers to deeper documentation.
|
||||
|
||||
This quickstart guide is also available for
|
||||
@ref cli_quickstart "the command-line" and @ref julia_quickstart "Julia".
|
||||
This quickstart guide is also available for [the command line]( ), [Julia]( ),
|
||||
[R]( ), and [Go]( ).
|
||||
|
||||
@section python_quickstart_install Installing mlpack
|
||||
## Installing mlpack
|
||||
|
||||
Installing the mlpack bindings for Python is straightforward. It's easy to use
|
||||
conda or pip to do this:
|
||||
`conda` or `pip` to do this:
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
pip install mlpack
|
||||
@endcode
|
||||
```
|
||||
|
||||
@code{.sh}
|
||||
```sh
|
||||
conda install -c conda-forge mlpack
|
||||
@endcode
|
||||
|
||||
Otherwise, we can build the Python bindings from scratch, as follows. First we
|
||||
have to install the dependencies (the code below is for Ubuntu), then we can
|
||||
build and install mlpack. You can copy-paste the commands into your shell.
|
||||
|
||||
@code{.sh}
|
||||
sudo apt-get install g++ cmake libarmadillo-dev python-pip wget
|
||||
sudo pip install cython setuptools distutils numpy pandas
|
||||
wget https://www.mlpack.org/files/mlpack-3.4.2.tar.gz
|
||||
tar -xvzpf mlpack-3.4.2.tar.gz
|
||||
mkdir -p mlpack-3.4.2/build/ && cd mlpack-3.4.2/build/
|
||||
cmake ../ && make -j4 && sudo make install
|
||||
@endcode
|
||||
|
||||
More information on the build process and details can be found on the @ref build
|
||||
page. You may also need to set the environment variable @c LD_LIBRARY_PATH to
|
||||
include @c /usr/local/lib/ on most Linux systems.
|
||||
|
||||
@code
|
||||
export LD_LIBRARY_PATH=/usr/local/lib/
|
||||
@endcode
|
||||
```
|
||||
|
||||
You can also use the mlpack Docker image on Dockerhub, which has all of the
|
||||
Python bindings pre-installed:
|
||||
|
||||
@code
|
||||
```sh
|
||||
docker run -it mlpack/mlpack /bin/bash
|
||||
@endcode
|
||||
```
|
||||
|
||||
@section python_quickstart_example Simple mlpack quickstart example
|
||||
Otherwise, you can build the Python bindings from scratch using the
|
||||
documentation in the [main README]( ).
|
||||
|
||||
## Simple mlpack quickstart example
|
||||
|
||||
As a really simple example of how to use mlpack from Python, let's do some
|
||||
simple classification on a subset of the standard machine learning @c covertype
|
||||
simple classification on a subset of the standard machine learning `covertype`
|
||||
dataset. We'll first split the dataset into a training set and a testing set,
|
||||
then we'll train an mlpack random forest on the training data, and finally we'll
|
||||
print the accuracy of the random forest on the test dataset.
|
||||
|
||||
You can copy-paste this code directly into Python to run it.
|
||||
|
||||
@code{.py}
|
||||
```py
|
||||
import mlpack
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
@@ -104,38 +80,26 @@ correct = np.sum(
|
||||
output['predictions'] == np.reshape(test_labels, (test_labels.shape[0],)))
|
||||
print(str(correct) + ' correct out of ' + str(len(test_labels)) + ' (' +
|
||||
str(100 * float(correct) / float(len(test_labels))) + '%).')
|
||||
@endcode
|
||||
```
|
||||
|
||||
We can see that we achieve reasonably good accuracy on the test dataset (80%+);
|
||||
if we use the full @c covertype.csv.gz, the accuracy should increase
|
||||
if we use the full `covertype.csv.gz`, the accuracy should increase
|
||||
significantly (but training will take longer).
|
||||
|
||||
It's easy to modify the code above to do more complex things, or to use
|
||||
different mlpack learners, or to interface with other machine learning toolkits.
|
||||
|
||||
@section python_quickstart_whatelse What else does mlpack implement?
|
||||
|
||||
The example above has only shown a little bit of the functionality of mlpack.
|
||||
Lots of other commands are available with different functionality. A full list
|
||||
of each of these commands and full documentation can be found on the following
|
||||
page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/python_documentation.html">Python documentation</a>
|
||||
|
||||
For more information on what mlpack does, see https://www.mlpack.org/.
|
||||
Next, let's go through another example for providing movie recommendations with
|
||||
mlpack.
|
||||
|
||||
@section python_quickstart_movierecs Using mlpack for movie recommendations
|
||||
## Using mlpack for movie recommendations
|
||||
|
||||
In this example, we'll train a collaborative filtering model using mlpack's
|
||||
<tt><a href="https://www.mlpack.org/doc/mlpack-git/python_documentation.html#cf">cf()</a></tt> method. We'll train this on the MovieLens dataset from
|
||||
https://grouplens.org/datasets/movielens/, and then we'll use the model that we
|
||||
train to give recommendations.
|
||||
[`cf()`](https://www.mlpack.org/doc/stable/python_documentation.html#cf) method.
|
||||
We'll train this on the
|
||||
[MovieLens dataset](https://grouplens.org/datasets/movielens/), and then we'll
|
||||
use the model that we train to give recommendations.
|
||||
|
||||
You can copy-paste this code directly into Python to run it.
|
||||
|
||||
@code{.py}
|
||||
```py
|
||||
import mlpack
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
@@ -170,12 +134,12 @@ print("Recommendations for user 1:")
|
||||
for i in range(10):
|
||||
print(" " + str(i) + ": " + str(movies.loc[movies['movieId'] ==
|
||||
output['output'][0, i]].iloc[0]['title']))
|
||||
@endcode
|
||||
```
|
||||
|
||||
Here is some example output, showing that user 1 seems to have good taste in
|
||||
movies:
|
||||
|
||||
@code{.unparsed}
|
||||
```
|
||||
Recommendations for user 1:
|
||||
0: Casablanca (1942)
|
||||
1: Pan's Labyrinth (Laberinto del fauno, El) (2006)
|
||||
@@ -187,29 +151,19 @@ Recommendations for user 1:
|
||||
7: Out for Justice (1991)
|
||||
8: Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
|
||||
9: Schindler's List (1993)
|
||||
@endcode
|
||||
```
|
||||
|
||||
@section python_quickstart_nextsteps Next steps with mlpack
|
||||
## Next steps with mlpack
|
||||
|
||||
Now that you have done some simple work with mlpack, you have seen how it can
|
||||
easily plug into a data science workflow in Python. A great thing to do next
|
||||
would be to look at more documentation for the Python mlpack bindings:
|
||||
easily plug into a data science workflow in Python. But the two examples above
|
||||
have only shown a little bit of the functionality of mlpack. Lots of other
|
||||
commands are available with different functionality. A full list of each of
|
||||
these commands and full documentation can be found on the following page:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/python_documentation.html">Python mlpack
|
||||
binding documentation</a>
|
||||
- [Python documentation](https://www.mlpack.org/doc/stable/python_documentation.html)
|
||||
|
||||
Also, mlpack is much more flexible from C++ and allows much greater
|
||||
functionality. So, more complicated tasks are possible if you are willing to
|
||||
write C++ (or perhaps Cython). To get started learning about mlpack in C++, the
|
||||
following resources might be helpful:
|
||||
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/tutorials.html">mlpack
|
||||
C++ tutorials</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/build.html">mlpack
|
||||
build and installation guide</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/sample.html">Simple
|
||||
sample C++ mlpack programs</a>
|
||||
- <a href="https://www.mlpack.org/doc/mlpack-git/doxygen/index.html">mlpack
|
||||
Doxygen documentation homepage</a>
|
||||
|
||||
*/
|
||||
[C++ quickstart]( ) would be a good place to go.
|
||||
Reference in New Issue
Block a user