Learn dynamic programming with Julia to build apps for data analysis, visualization, machine learning, and the web
Key Features
Leverage Julia's high speed and efficiency to build fast, efficient applications
Perform supervised and unsupervised machine learning and time series analysis
Tackle problems concurrently and in a distributed environment
Book Description
Julia offers the high productivity and ease of use of Python and R with the lightning-fast speed of C++. There's never been a better time to learn this language, thanks to its large-scale adoption across a wide range of domains, including fintech, biotech and artificial intelligence (AI).
You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. This Learning Path walks you through two important collection types: arrays and matrices. You'll be taken through how type conversions and promotions work, and in further chapters you'll study how Julia interacts with operating systems and other languages. You'll also learn about the use of macros, what makes Julia suitable for numerical and scientific computing, and how to run external programs.
Once you have grasped the basics, this Learning Path goes on to how to analyze the Iris dataset using DataFrames. While building a web scraper and a web app, you'll explore the use of functions, methods, and multiple dispatches. In the final chapters, you'll delve into machine learning, where you'll build a book recommender system.
By the end of this Learning Path, you'll be well versed with Julia and have the skills you need to leverage its high speed and efficiency for your applications.
This Learning Path includes content from the following Packt products:
Julia 1.0 Programming - Second Edition by Ivo Balbaert
Julia Programming Projects by Adrian Salceanu
What you will learn
Create your own types to extend the built-in type system
Visualize your data in Julia with plotting packages
Explore the use of built-in macros for testing and debugging
Integrate Julia with other languages such as C, Python, and MATLAB
Analyze and manipulate datasets using Julia and DataFrames
Develop and run a web app using Julia and the HTTP package
Build a recommendation system using supervised machine learning
Who this book is for
If you are a statistician or data scientist who wants a quick course in the Julia programming language while building big data applications, this Learning Path is for you. Basic knowledge of mathematics and programming is a must.
Now that you have a working Julia installation and your IDE of choice is ready to run, it's time to put them to some good use. In this chapter, you'll learn how to apply Julia for data analysisāa domain that is central to the language, so expect to be impressed!
We will learn to perform exploratory data analysis with Julia. In the process, we'll take a look at RDatasets, a package that provides access to over 700 learning datasets. We'll load one of them, the Iris flowers dataset, and we'll manipulate it using standard data analysis functions. Then we'll look more closely at the data by employing common visualization techniques. And finally, we'll see how to persist and (re)load our data.
But, in order to do that, first we need to revisit and take a look at some of the language's most important building blocks.
We will cover the following topics in this chapter:
Declaring variables (and constants)
Working with Strings of characters and regular expressions
Numbers and numeric types
Our first Julia data structuresāTuple, Range, and Array
* Exploratory data analysis using the Iris flower datasetāRDatasets and core Statistics
Quick data visualization with Gadfly
* Saving and loading tabular data with CSV and Feather
Interacting with MongoDB databases
Technical requirements
The Julia package ecosystem is under continuous development and new package versions are released on a daily basis. Most of the times this is great news, as new releases bring new features and bug fixes. However, since many of the packages are still in beta (version 0.x), any new release can introduce breaking changes. As a result, the code presented in the book can stop working. In order to ensure that your code will produce the same results as described in the book, it is recommended to use the same package versions. Here are the external packages used in this chapter and their specific versions:
Alternatively you can install all the used packages by downloading the Project.toml file provided with the chapter and using pkg> instantiate as follows:
We have seen in the previous chapter how to use the REPL in order to execute computations and have the result displayed back to us. Julia even lends a helping hand by setting up the ans variable, which automatically holds the last computed value.
But, if we want to write anything but the most trivial programs, we need to learn how to define variables ourselves. In Julia, a variable is simply a name associated to a value. There are very few restrictions for naming variables, and the names themselves have no semantic meaning (the language will not treat variables differently based on their names, unlike say Ruby, where a name that is all caps is treated as a constant).
Let's see some examples:
julia> book = "Julia v1.0 By Example" julia> pi = 3.14 julia> ANSWER = 42 julia> my_first_name = "Adrian"
You can follow along through the examples in the chapter by loading the accompanying Jupyter/IJulia notebook provided with this chapter's support files.
The variables, names are case-sensitive, meaning that ANSWER and answer (and Answer and aNsWeR) are completely different things:
julia> answer ERROR: UndefVarError: answer not defined
Unicode names (UTF-8-encoded) are also accepted as variables names:
julia> Ī“ = 130
Remember that you can type many Unicode math symbols by typing backslash (\) then the name of the symbol and then the Tab key. For example, \pi[Tab] will output Ļ.
Emojis also work, if your terminal supports them:
julia>
= "apollo 11"
The only explicitly disallowed names for variables are the names of built-in Julia statements (do, end, try, catch, if, and else, plus a few more):
julia> do = 3 ERROR: syntax: invalid "do" syntax julia> end = "Paris" ERROR: syntax: unexpected end
Attempting to access a variable that hasn't been defined will result in an error:
julia> MysteryVar ERROR: UndefVarError: MysteryVar not defined
It's true that the language does not impose many restrictions, but a set of code style conventions is always usefulāand even more so for an open source language. The Julia community has distilled a set of best practices for writing code. In regard to naming variables, the names should be lowercase and in just one word; word separation can be done with underscores (_), but only if the name would be difficult to read without them. For example, myvar versus total_length_horizontal.
Given that the degree of difficulty in reading a name is a subjective thing, I'm a bit split about this naming style. I normally prefer the crystal-clear clarity of separating at word boundaries. But nevertheless, it is better to follow the recommendation, given that function names in the Julia API adhere to it. By adhering to the same conventions, your code will be consistent throughout.
Constants
Constants are variables that, once declared, can't be changed. They are declared by prefixing them with the const keyword:
julia> const firstmonth = "January"
Very importantly in Julia, constants are not concerned with their value, but rather with their type. It is a bit too early to discuss types in Julia, so for now it suffices to say that a type represents what kind of a value we're dealing with. For instance, "abc" (within double quotes) is of type String, 'a' (within single quotes) is of type Char , and 1000 is of type Int (because it's an integer). Thus, in Julia, unlike most other languages, we can change the value assigned to a constant as long as the type remains the same. For instance, we can at first decide that eggs and milk are acceptable meal choices and go vegetarian:
julia> const mealoption = "vegetarian"
And we can change our mind later on, if we decide to go vegan. Julia will let it slide with just a warning:
However, attempting to say that mealoption = 2 will result in an error:
julia> mealoption = 2 ERROR: invalid redefinition of constant mealoption
This makes sense, right? W...
Table of contents
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Installing the Julia Platform
Variables, Types, and Operations
Functions
Control Flow
Collection Types
More on Types, Methods, and Modules
Metaprogramming in Julia
I/O, Networking, and Parallel Computing
Running External Programs
The Standard Library and Packages
Creating Our First Julia App
Setting Up the Wiki Game
Building the Wiki Game Web Crawler
Adding a Web UI for the Wiki Game
Implementing Recommender Systems with Julia
Machine Learning for Recommender Systems
Other Books You May Enjoy
Frequently asked questions
Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, weāve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere ā even offline. Perfect for commutes or when youāre on the go. Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Julia 1.0 Programming Complete Reference Guide by Ivo Balbaert, Adrian Salceanu in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.