Earlier this year the Big Data Beard team tackled Andrew Ng’s Machine Learning course on Coursera. In week two the course started to get hands on with Machine Learning labs. These labs were all done in Octave or Matlab. I had the misfortune of not having any experience using Octave or Matlab. So not only was I learning the Machine Learning content, I also had to level on on my Octave knowledge. Let’s jump through the top Octave Commands I learned in this course.

## What is Octave

Octave is an open source application that runs on Windows, Mac, & Linux systems used for computing large mathematical computations. Octave the open source version of Matlab which is used heavily by Data Scientist, Engineers, and Mathematicians for developing mathimatical models. Think the relationship between Octave and Matlab as CentOS is to Redhat.

## Why Use Octave vs. Python?

Throughout the Machine Learning course assignment are calculated and submitted using Octave. Why Octave over using Python or R? Andrew Ng built this course to revolve around the fundamentals of Machine Learning. This course is more a math and concepts fundamentals versus showing how to code. While Python is a fairly easy language to pick up, it still requires basic coding skills. Octave gives non-coding students the ability to easily jump into implementation the mathematical concepts in the course.

I would have rather used Python, but I have a background in software engineering so of course I would.

## Octave Commands

At first glance Octave reminded me of the TI-83 from my high school days (yes I’m that old). The syntax is very simple and the commands have roots in the UNIX filesystem. Let’s walk through the top Octave Commands.

Baseline Octave CLI Commands

**ls** – List files, sub-directories, and content in current location. Same thing as doing ls from the CLI in Linux.

1 2 3 4 |
$ ls file.txt tmp module-1.txt |

**cd** – Change directory. When you need to move to another directory cd allows you to move to that location.

1 2 |
$ cd /tmp move from current location to the tmp directory |

**mkdir** – Creates an empty directory in some location.

1 2 |
$ mkdir test creates test directory in current file path |

**help** – Documentation from the CLI. Use the help command then name of command you want documentation on.

1 2 3 |
$ help commandname defines command here with more support as well... |

### Declaring Variables in Octave

**Variable Name** – To declare variables in Octave it’s as simple is assigning the variable name then setting it equal to some value or other variable.

1 2 |
$ x = 3 x = 3 |

### Arithmetic Octave Commands

** Addition **-Simple addition

1 2 |
$ 2 + 2 ans = 4 |

**Subtract **-Simple subtraction

1 2 |
$ 3 - 2 ans = 1 |

**Multiplication **-Simple multiplication

1 2 |
$ 2 * 2 ans = 4 |

**Division **-Simple division

1 2 |
$ 2/2 ans = 1 |

**Exponential**** **-Simple Exponential

1 2 |
$ 2^2 asn = 4 |

**sqrt()** – Find square root of some value or variable.

1 2 |
sqrt(4) ans = 2 |

### Octave Complex Functions

**plot()** – Allows users to pass in variable to be plotted.

1 2 |
$ plot(x,y) plots out x and y variables in series |

**rand()** – Generate random numbers.

1 2 |
$ x = rand() x = .27088 |

**ones()** – Create matrix with n (whatever you pass in) dimensions.

1 2 3 4 5 6 |
$ ones(4,4) asn= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 |

**size()** – Describe the size of n dimensions in matrix.

1 2 3 4 5 |
$ z = ones(2,2) $ size(z) ans = 1 1 1 1 |

## Want More Big Data Beard?

Find out more tips about Octave Commands, Data Analytics Architecture, and other cool topics in Big Data by subscribing to the Big Data Beard Podcast.