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 Python, the command-line, Go and R.
Installing the mlpack bindings for Julia is straightforward; you can just use Pkg:
Building the Julia bindings from scratch is a little more in-depth, though. For information on that, follow the instructions on the Building mlpack From Source page, and be sure to specify -DBUILD_JULIA_BINDINGS=ON
to CMake; you may need to also set the location of the Julia program with -DJULIA_EXECUTABLE=/path/to/julia
.
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 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 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")
.
We can see that we achieve reasonably good accuracy on the test dataset (80%+); 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.
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:
You can also use the Julia REPL to explore the 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.
In this example, we'll train a collaborative filtering model using mlpack's cf()
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.
You can copy-paste this code directly into Julia to run it.
Here is some example output, showing that user 1 seems to have good taste in movies:
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:
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: