Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Go Machine Learning Projects

You're reading from   Go Machine Learning Projects Eight projects demonstrating end-to-end machine learning and predictive analytics applications in Go

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781788993401
Length 348 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Xuanyi Chew Xuanyi Chew
Author Profile Icon Xuanyi Chew
Xuanyi Chew
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. How to Solve All Machine Learning Problems 2. Linear Regression - House Price Prediction FREE CHAPTER 3. Classification - Spam Email Detection 4. Decomposing CO2 Trends Using Time Series Analysis 5. Clean Up Your Personal Twitter Timeline by Clustering Tweets 6. Neural Networks - MNIST Handwriting Recognition 7. Convolutional Neural Networks - MNIST Handwriting Recognition 8. Basic Facial Detection 9. Hot Dog or Not Hot Dog - Using External Services 10. What's Next? 11. Other Books You May Enjoy

Functions

Functions are the main way that anything is computed in Go.

This is a function:

func addInt(a, b int) int { return a + b }

We call func addInt(a, b int) int, which is the function signature. The function signature is composed of the function name, parameters, and return type(s).

The name of the function is addInt. Note the formatting being used. The function name is in camelCase—this is the preferred casing of names in Go. The first letter of any name, when capitalized, like AddInt indicates that it should be exported. By and large in this book we shan't worry about exported or unexported names, as we will be mostly using functions. But if you are writing a package, then it matters. Exported names are available from outside a package.

Next, note that a and b are parameters, and both have the type int. We'll discuss types in a bit, but the same function can also be written as:

func addInt(a int, b int) int { return a + b }

Following that, this is what the function returns. This function addInt returns an int. This means when a function is called correctly, like so:

 z := addInt(1, 2) 

z will have a type int.

After the return type is defined, {...} denotes the body. When {...} is written in this book, it means the content of the function body is not as important for the discussion at hand. Some parts of the book may have snippets of function bodies, but without the signature func foo(...). Again those snippets are the snippets under discussion. It's expected that the reader will piece together the function from context in the book.

A Go function may return multiple results. The function signature looks something like this:

 func divUint(a, b uint) (uint, error) { ... }
func divUint(a, b uint) (retVal uint, err error) { ... }

Again, the difference is mainly in naming the return values. In the second example, the return values are named retVal and err respectively. retVal is of type uint and err is of type error.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime