\section{Introduction}\label{go_quickstart_go_quickstart_intro}
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 \doxyref{Python}{p.}{python_quickstart}, \doxyref{the command-\/line}{p.}{cli_quickstart}, \doxyref{Julia}{p.}{julia_quickstart} and \doxyref{R}{p.}{r_quickstart}.\section{Installing mlpack}\label{go_quickstart_go_quickstart_install}
Installing the mlpack bindings for Go is somewhat time-\/consuming as the library must be built; you can run the following code\+:


\begin{DoxyCode}
go get -u -d mlpack.org/v1/mlpack
cd $\{GOPATH\}/src/mlpack.org/v1/mlpack
make install
\end{DoxyCode}


Building the Go bindings from scratch is a little more in-\/depth, though. For information on that, follow the instructions on the \doxyref{Building mlpack From Source}{p.}{build} page, and be sure to specify {\ttfamily -\/\+D\+B\+U\+I\+L\+D\+\_\+\+G\+O\+\_\+\+B\+I\+N\+D\+I\+N\+GS=ON} to C\+Make;\section{Simple mlpack quickstart example}\label{go_quickstart_go_quickstart_example}
As a really simple example of how to use mlpack from Go, 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 main.\+go to run it. 
\begin{DoxyCode}
package main

import (
  "mlpack.org/v1/mlpack"
  "fmt"
)
func main() \{

  // Download dataset.
  mlpack.DownloadFile("https://www.mlpack.org/datasets/covertype-small.data.csv.gz",
                      "data.csv.gz")
  mlpack.DownloadFile("https://www.mlpack.org/datasets/covertype-small.labels.csv.gz",
                      "labels.csv.gz")

  // Extract/Unzip the dataset.
  mlpack.UnZip("data.csv.gz", "data.csv")
  dataset, \_ := mlpack.Load("data.csv")

  mlpack.UnZip("labels.csv.gz", "labels.csv")
  labels, \_ := mlpack.Load("labels.csv")

  // Split the dataset using mlpack.
  params := mlpack.PreprocessSplitOptions()
  params.InputLabels = labels
  params.TestRatio = 0.3
  params.Verbose = true
  test, test\_labels, train, train\_labels :=
      mlpack.PreprocessSplit(dataset, params)

  // Train a random forest.
  rf\_params := mlpack.RandomForestOptions()
  rf\_params.NumTrees = 10
  rf\_params.MinimumLeafSize = 3
  rf\_params.PrintTrainingAccuracy = true
  rf\_params.Training = train
  rf\_params.Labels = train\_labels
  rf\_params.Verbose = true
  rf\_model, \_, \_ := mlpack.RandomForest(rf\_params)

  // Predict the labels of the test points.
  rf\_params\_2 := mlpack.RandomForestOptions()
  rf\_params\_2.Test = test
  rf\_params\_2.InputModel = &rf\_model
  rf\_params\_2.Verbose = true
  \_, predictions, \_ := mlpack.RandomForest(rf\_params\_2)

  // Now print the accuracy.
  rows, \_ := predictions.Dims()
  var sum int = 0
  for i := 0; i < rows; i++ \{
    if (predictions.At(i, 0) == test\_labels.At(i, 0)) \{
      sum = sum + 1
    \}
  \}
  fmt.Print(sum, " correct out of ", rows, " (",
      (float64(sum) / float64(rows)) * 100, "%).\(\backslash\)n")
\}
\end{DoxyCode}


We can see that we achieve reasonably good accuracy on the test dataset (80\%+); if we use the full {\ttfamily covertype.\+csv.\+gz}, the accuracy should increase significantly (but training will take longer).

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{go_quickstart_go_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 each of these commands and full documentation can be found on the following page\+:


\begin{DoxyItemize}
\item {\tt Go documentation}
\end{DoxyItemize}

You can also use the Go\+Doc to explore the {\ttfamily mlpack} module and its functions; every function comes with comprehensive documentation.

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{go_quickstart_go_quickstart_movierecs}
In this example, we\textquotesingle{}ll train a collaborative filtering model using mlpack\textquotesingle{}s {\ttfamily {\tt Cf()}} method. 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 main.\+go to run it.


\begin{DoxyCode}
package main

import (
  "github.com/frictionlessdata/tableschema-go/csv"
  "mlpack.org/v1/mlpack"
  "gonum.org/v1/gonum/mat"
  "fmt"
)
func main() \{

  // Download dataset.
  mlpack.DownloadFile("https://www.mlpack.org/datasets/ml-20m/ratings-only.csv.gz",
                      "ratings-only.csv.gz")
  mlpack.DownloadFile("https://www.mlpack.org/datasets/ml-20m/movies.csv.gz",
                      "movies.csv.gz")

  // Extract dataset.
  mlpack.UnZip("ratings-only.csv.gz", "ratings-only.csv")
  ratings, \_ := mlpack.Load("ratings-only.csv")

  mlpack.UnZip("movies.csv.gz", "movies.csv")
  table, \_ := csv.NewTable(csv.FromFile("movies.csv"), csv.LoadHeaders())
  movies, \_ := table.ReadColumn("title")

  // Split the dataset using mlpack.
  params := mlpack.PreprocessSplitOptions()
  params.TestRatio = 0.1
  params.Verbose = true
  ratings\_test, \_, ratings\_train, \_ := mlpack.PreprocessSplit(ratings, params)

  // Train the model.  Change the rank to increase/decrease the complexity of the
  // model.
  cf\_params := mlpack.CfOptions()
  cf\_params.Training = ratings\_train
  cf\_params.Test = ratings\_test
  cf\_params.Rank = 10
  cf\_params.Verbose = true
  cf\_params.Algorithm = "RegSVD"
  \_, cf\_model := mlpack.Cf(cf\_params)

  // Now query the 5 top movies for user 1.
  cf\_params\_2 := mlpack.CfOptions()
  cf\_params\_2.InputModel = &cf\_model
  cf\_params\_2.Recommendations = 10
  cf\_params\_2.Query = mat.NewDense(1, 1, []float64\{1\})
  cf\_params\_2.Verbose = true
  cf\_params\_2.MaxIterations = 10
  output, \_ := mlpack.Cf(cf\_params\_2)

  // Get the names of the movies for user 1.
  fmt.Println("Recommendations for user 1")
  for i := 0; i < 10; i++ \{
    fmt.Println(i, ":", movies[int(output.At(0 , i))])
  \}
\}
\end{DoxyCode}


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


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


\begin{DoxyItemize}
\item {\tt Go mlpack binding 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}