\section{Introduction}\label{cli_quickstart_cli_quickstart_intro}
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 \doxyref{Python}{p.}{python_quickstart} and \doxyref{Julia}{p.}{julia_quickstart}.\section{Installing mlpack}\label{cli_quickstart_cli_quickstart_install}
Installing the mlpack is straightforward and can be done with your system\textquotesingle{}s package manager.

For instance, for Ubuntu or Debian the command is simply


\begin{DoxyCode}
sudo apt-get install mlpack-bin
\end{DoxyCode}


On Fedora or Red Hat\+:


\begin{DoxyCode}
sudo dnf install mlpack
\end{DoxyCode}


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\+:


\begin{DoxyCode}
docker run -it mlpack/mlpack /bin/bash
\end{DoxyCode}


This Docker image has mlpack already built and installed.

If you prefer to build mlpack from scratch, see \doxyref{Building mlpack From Source}{p.}{build}.\section{Simple mlpack quickstart example}\label{cli_quickstart_cli_quickstart_example}
As a really simple example of how to use mlpack from the command-\/line, let\textquotesingle{}s do some simple classification on a subset of the standard machine learning {\ttfamily covertype} dataset. We\textquotesingle{}ll first split the dataset into a training set and a testing set, then we\textquotesingle{}ll train an mlpack random forest on the training data, and finally we\textquotesingle{}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.


\begin{DoxyCode}
# 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
gunzip covertype-small.data.csv.gz covertype-small.labels.csv.gz

# Split the dataset; 70% into a training set and 30% into a test set.
# Each of these options has a shorthand single-character option but here we type
# it all out for clarity.
mlpack\_preprocess\_split                                       \(\backslash\)
    --input\_file covertype-small.data.csv                     \(\backslash\)
    --input\_labels\_file covertype-small.labels.csv            \(\backslash\)
    --training\_file covertype-small.train.csv                 \(\backslash\)
    --training\_labels\_file covertype-small.train.labels.csv   \(\backslash\)
    --test\_file covertype-small.test.csv                      \(\backslash\)
    --test\_labels\_file covertype-small.test.labels.csv        \(\backslash\)
    --test\_ratio 0.3                                          \(\backslash\)
    --verbose

# Train a random forest.
mlpack\_random\_forest                                  \(\backslash\)
    --training\_file covertype-small.train.csv         \(\backslash\)
    --labels\_file covertype-small.train.labels.csv    \(\backslash\)
    --num\_trees 10                                    \(\backslash\)
    --minimum\_leaf\_size 3                             \(\backslash\)
    --print\_training\_accuracy                         \(\backslash\)
    --output\_model\_file rf-model.bin                  \(\backslash\)
    --verbose

# Now predict the labels of the test points and print the accuracy.
# Also, save the test set predictions to the file 'predictions.csv'.
mlpack\_random\_forest                                    \(\backslash\)
    --input\_model\_file rf-model.bin                     \(\backslash\)
    --test\_file covertype-small.test.csv                \(\backslash\)
    --test\_labels\_file covertype-small.test.labels.csv  \(\backslash\)
    --predictions\_file predictions.csv                  \(\backslash\)
    --verbose
\end{DoxyCode}


We can see by looking at the output that we achieve reasonably good accuracy on the test dataset (80\%+). The file {\ttfamily predictions.\+csv} could also be used by other tools; for instance, we can easily calculate the number of points that were predicted incorrectly\+:


\begin{DoxyCode}
$ diff -U 0 predictions.csv covertype-small.test.labels.csv | grep '^@@' | wc -l
\end{DoxyCode}


It\textquotesingle{}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{What else does mlpack implement?}\label{cli_quickstart_cli_quickstart_whatelse}
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\+:


\begin{DoxyItemize}
\item {\tt C\+LI documentation}
\end{DoxyItemize}

For more information on what mlpack does, see {\tt https\+://www.\+mlpack.\+org/}. Next, let\textquotesingle{}s go through another example for providing movie recommendations with mlpack.\section{Using mlpack for movie recommendations}\label{cli_quickstart_cli_quickstart_movierecs}
In this example, we\textquotesingle{}ll train a collaborative filtering model using mlpack\textquotesingle{}s {\ttfamily mlpack\+\_\+cf} program. We\textquotesingle{}ll train this on the Movie\+Lens dataset from {\tt https\+://grouplens.\+org/datasets/movielens/,} and then we\textquotesingle{}ll use the model that we train to give recommendations.

You can copy-\/paste this code directly into the command line to run it.


\begin{DoxyCode}
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
gunzip movies.csv.gz

# Hold out 10% of the dataset into a test set so we can evaluate performance.
mlpack\_preprocess\_split                 \(\backslash\)
    --input\_file ratings-only.csv       \(\backslash\)
    --training\_file ratings-train.csv   \(\backslash\)
    --test\_file ratings-test.csv        \(\backslash\)
    --test\_ratio 0.1                    \(\backslash\)
    --verbose

# Train the model.  Change the rank to increase/decrease the complexity of the
# model.
mlpack\_cf                             \(\backslash\)
    --training\_file ratings-train.csv \(\backslash\)
    --test\_file ratings-test.csv      \(\backslash\)
    --rank 10                         \(\backslash\)
    --algorithm RegSVD                \(\backslash\)
    --output\_model\_file cf-model.bin  \(\backslash\)
    --verbose

# Now query the 5 top movies for user 1.
echo "1" > query.csv;
mlpack\_cf                             \(\backslash\)
    --input\_model\_file cf-model.bin   \(\backslash\)
    --query\_file query.csv            \(\backslash\)
    --recommendations 10              \(\backslash\)
    --output\_file recommendations.csv \(\backslash\)
    --verbose

# Get the names of the movies for user 1.
echo "Recommendations for user 1:"
for i in `seq 1 10`; do
    item=`cat recommendations.csv | awk -F',' '\{ print $'$i' \}'`;
    head -n $(($item + 2)) movies.csv | tail -1 | \(\backslash\)
        sed 's/^[^,]*,[^,]*,//' | \(\backslash\)
        sed 's/\(\backslash\)(.*\(\backslash\)),.*$/\(\backslash\)1/' | sed 's/"//g';
done
\end{DoxyCode}


Here is some example output, showing that user 1 seems to have good taste in movies\+:


\begin{DoxyCode}
Recommendations for user 1:
Casablanca (1942)
Pan's Labyrinth (Laberinto del fauno, El) (2006)
Godfather, The (1972)
Answer This! (2010)
Life Is Beautiful (La Vita è bella) (1997)
Adventures of Tintin, The (2011)
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)
\end{DoxyCode}
\section{Next steps with mlpack}\label{cli_quickstart_cli_quickstart_nextsteps}
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\+:


\begin{DoxyItemize}
\item {\tt mlpack command-\/line program documentation}
\end{DoxyItemize}

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\+:


\begin{DoxyItemize}
\item {\tt mlpack C++ tutorials}
\item {\tt mlpack build and installation guide}
\item {\tt Simple sample C++ mlpack programs}
\item {\tt mlpack Doxygen documentation homepage} 
\end{DoxyItemize}