Book Image

Machine Learning with R Quick Start Guide

By : Iván Pastor Sanz
Book Image

Machine Learning with R Quick Start Guide

By: Iván Pastor Sanz

Overview of this book

Machine Learning with R Quick Start Guide takes you on a data-driven journey that starts with the very basics of R and machine learning. It gradually builds upon core concepts so you can handle the varied complexities of data and understand each stage of the machine learning pipeline. From data collection to implementing Natural Language Processing (NLP), this book covers it all. You will implement key machine learning algorithms to understand how they are used to build smart models. You will cover tasks such as clustering, logistic regressions, random forests, support vector machines, and more. Furthermore, you will also look at more advanced aspects such as training neural networks and topic modeling. By the end of the book, you will be able to apply the concepts of machine learning, deal with data-related problems, and solve them using the powerful yet simple language that is R.
Table of Contents (9 chapters)

R and RStudio installation

Let's first start with installing R. It is totally free and can be downloaded from https://cloud.r-project.org/. Installing R is an easy task.

Let's look at the steps to install R on a Windows PC. For installing it on other operating systems, the steps are straightforward and are available at the same https://cloud.r-project.org/ link.

Let's start by installing R on a Windows system:

  1. Visit https://cloud.r-project.org/.
  2. Look for Download and Install R and select your operating system. We are installing for Windows, so select the Windows link.
  3. Go to Subdirectories and click on base.
  4. You will be redirected to a page that shows download R X.X.X for Windows. At the time of writing this book, Download R 3.5.2 for Windows is the version that you need to click on.
  5. Save and run the .exe file.
  6. You can now select the setup language to install R.
  7. A setup wizard will open and you can go on clicking Next until you reach Select Destination Location.
  8. Select your preferred location and click Next.
  9. Click the Next button several more times until R starts to install.
  10. After the installation is complete, R will notify you with the message Completing the R for Windows 3.5.2 Setup Wizard. You can now click on Finish.
  11. You can find the R shortcut on your desktop and double-click on it to start R.
  12. Like any other application, in case you can't find R on your desktop, you can go to the Start button, All Programs, and look for R and start it.
  13. You will get a screen similar to what's shown in the following screenshot:

This is the R Command Prompt, waiting for input.

Things to know about R

Before moving on to typing in commands, you must know that R is a case-sensitive and interpreted language.

You can choose between manually entering commands and running a set of commands from the source file as per your will. R provides a lot of built-in functions that give most functionalities to the user. As a user, you can even create user-created functions.

You can even create and manipulate objects. You might know that objects are anything that can have an assigned value. An interactive session will require all objects to be present in the memory while the execution process is running, whereas the functions can be placed in the packages that have a reference in the current program and can be accessed as and when needed.

Using RStudio

Alongside using R, it is recommended to use RStudio. RStudio is an integrated development environment (IDE) that, like any other IDE, enhances your interaction with R.

RStudio provides you with a very well-organized interface that can clearly represent graphs, data tables, R code, and output simultaneously.

Moreover, to import and export files in different formats into R without having to write code, R offers an import wizard like feature.

Having seen the standard R GUI interface, you will see the similarities with RStudio, but the difference is that RStudio is very intuitive and user-friendly compared to the R GUI. You will have many options to choose from the menu, and you can even customize the GUI according to your requirements. RStudio for desktop is available at https://www.rstudio.com/products/rstudio/download/#download.

RStudio installation

The installation steps are very similar to the installation of R, so it isn't necessary to describe the detailed steps.

The first time you open RStudio, you will see three different windows. You can enable a fourth window by going to File, New File, and selecting R Script:

On the upper-left side window, scripts can be written and then saved and executed. The window that follows, on the left, represents the Console, where codes in R can directly be executed.

The upper-right window allows for the visualization of variables and objects that have been defined in the workspace. Furthermore, it is possible to see the history of commands that were previously executed. Finally, the bottom-right window displays the working directory.