[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac

Introduction

logo_horizontal.png

Many people said, "I want to study machine learning and artificial intelligence, but I'm stumbling on the environment construction before learning programming **", and I wrote an article ** to never fail in the environment construction. It was decided to do. There is more than one way to build a machine learning environment with Python, and you can try installing it with Homebrew, Anaconda, or any other method. It's nice to have multiple methods because even if you make a mistake, you can try other methods, but ** it can be a cause for beginners to wonder which method to build the environment **.

Therefore, in this article, we are targeting the following people.

Please refer to this article to build an environment that will not fail.

Thank you for your cooperation!

If you find this article helpful, I would be grateful if you could like this article.

About the author

02.jpg

I am ** Kikagaku Co., Ltd. ** Representative Director ** Ryosuke Yoshizaki ** My name is. Currently, "** Machine Learning / Artificial Intelligence De-Black Box Seminar **" and "** Machine Learning Online Tutor ** ”is operated.

Biography

Affiliation Department / Department research content Punishment
Maizuru National College of Technology Department of Electronic Control Engineering Study image processing (AR)
Maizuru National College of Technology Department of Electrical and Control Systems Engineering Research on robotics, system control, and optimization
Kyoto University Graduate School Graduate School of Informatics (Kano Lab Appliedresearchonmachinelearningforthemanufacturingindustry ADCHEM2016BestPaperAward,ChemicalEngineeringSocietyTechnologyAward
SHIFT Inc. President's office Research on software test automation by artificial intelligence CEDEC 2016 stage
Carat Co., Ltd. Director and COO Optimal itinerary proposal app (natural language processing / optimization)
Kikagaku Co., Ltd. PresidentandCEO Machinelearning/artificialintelligenceseminarOrOnlinetutor

Kikagaku Co., Ltd.

logo_horizontal.png

Providing educational services for machine learning and artificial intelligence

We look forward to your follow-up

We provide information on machine learning and artificial intelligence from a business perspective and recommended reference books.

President and CEO Ryosuke Yoshizaki Twitter:@yoshizaki_kkgk Facebook:@ryosuke.yoshizaki Blog: Blog of Kikagaku representative

Now that the introduction is long, let's start building the environment!

Local environment (Mac)

Depending on the environment, the settings may be successful. Currently, my PC has the latest Mac OS.

· MacOS Sierra 10.12.3

If it doesn't work, please try this.

スクリーンショット 2017-02-10 10.31.51.png

Homebrew installation

Introduce a package manager called ** Homebrew . Those who do not program on a daily basis may not be familiar with it, but in the world of programming, the work that humans were doing as " Search on the Web → Download files for installation → Perform installation at hand " is automatically performed. There is a mechanism that can be done with one command. That is " Package Manager **".

With this, 100 people. It will download and install the ** software you need in the programming world with just one command.

On Mac, a package manager called "** Homebrew **" is famous, and there is also "MacPorts", but recent Web information is mostly written in Homebrew, so ** Homebrew is recommended. **is.

Visit Homebrew site

First, access the ** Homebrew ** site.

スクリーンショット 2017-02-09 20.05.56.png

Copy this ** top script **.

Open terminal

We use "** Terminal ", which is commonplace for programmers. That is the " black screen **".

If you are using ** spotlight , search for " terminal **" and the following screen will appear. Press Enter to bring up the terminal.

スクリーンショット 2017-02-09 20.12.35.png

If you are not sure, open "** Application " from " Move **" on the upper left of the mac Finder.

スクリーンショット 2017-02-09 20.13.57.png スクリーンショット 2017-02-09 20.15.26.png スクリーンショット 2017-02-09 20.15.33.png

I think there is "** Terminal " in " Utility **".

When opened, ** Terminal ** started up like this.

スクリーンショット 2017-02-09 20.17.12.png

Install Homebrew from the terminal

Now, let's install Homebrew. To install, just paste the script you copied with Homebrew into the terminal and press Enter **.

スクリーンショット 2017-02-09 20.17.23.png

What do you think. Isn't it very easy?

On the way, you will see a screen like this.

スクリーンショット 2017-02-09 20.17.33.png

If you want to continue the process, it says "Return", so press Enter (Return).

スクリーンショット 2017-02-09 20.17.42.png

Next, you will be asked to enter the password. Enter the ** password set on your Mac . At this time, if you are new to the terminal, it is often mistaken for an error as " Characters are not reflected **", but since the characters have been entered properly, I thought that I was deceived and the characters Try typing and pressing Enter. If there is no problem, I think that I will proceed to the next process.

スクリーンショット 2017-02-09 20.22.56.png

After waiting for about 5 minutes, the installation will be completed like this.

Check if HomeBrew is installed correctly

The commands used in the terminal are basically the same as ** Linux **.

And commands using Homebrew use brew.

For example, if you want to install something, type the following in the terminal:

Software installation using Homebrew


$brew install software name

What do you think. Isn't it very intuitive?

As long as Homebrew is installed correctly, you can manage the software with commands like the one above. Now, let's check if Homebrew, which is the main subject, is installed correctly.

Check if Homebrew is installed correctly


$ which brew

Only this. This command which is a command to find out where the program that is the source of the command to be used is stored, but this will cause blank characters because nothing is saved if it is not installed. It will return, and if it is installed properly, it will return the location where it was saved.

スクリーンショット 2017-02-09 20.29.58.png

As you can see, it returns that it is saved in the location / usr / local / bin / brew, so you can see that the installation was successful. If you don't get anything back, you haven't installed correctly, so repeat the above steps again.

Install Python3

For Mac, Python is installed from the beginning, but ** Python installed from the beginning is a version that is a little troublesome to handle Japanese, which is 2 series **, so this time I will use Python 3 series. I will install it (if you don't know, you don't have to worry about it).

Make sure Python 3 is not installed

If you already have Python 3 installed, you do not need to follow the steps in this chapter. So let's first check if Python 3 is installed.

Use the which command you used earlier to verify that Homebrew installed it correctly.

Check if Python 3 is installed


$ which python3
スクリーンショット 2017-02-09 20.35.25.png

Nothing is returned, so you can confirm that it has not been installed. Now let's install Python3.

Install Python 3 with Homebrew

If you use Homebrew, the installation is completed with one command below.

Install Python3


$ brew install python3

Now when you press Enter, the installation commands will be executed one after another as shown in the image below.

スクリーンショット 2017-02-09 20.38.47.png

And finally, the installation is completed when the following screen is displayed.

スクリーンショット 2017-02-09 20.39.37.png

Let's check if it is installed.

Check if it is installed


$ which python3
スクリーンショット 2017-02-09 20.40.38.png

As you can see, the location where python3 is saved is returned, so the installation is complete.

Also, when you install python3 via Homebrew, you should also have the command pip3 installed.

Check if pip3 is installed


$ which pip3
スクリーンショット 2017-02-09 20.45.34.png

This pip3 is a tool for managing a convenient tool called ** library ** used in python.

Frequently Asked Questions: What's the difference between Homebrew and pip?

Both brew and pip3 are used to install something, but how do you use them properly?

The answer is "** Install software in Mac is HomeBrew " and " Install libraries in Python is pip **".

Homebrew manages software such as python3 and pip3 used on the Mac, and pip3 manages libraries for use with that python3.

Homebrew
 |- python3
 |- pip3
     |-Library used by python3...
 |- etc...

Check Python version

I installed Python3, but the installed version changes from time to time (basically to install the latest version).

Now let's check the version I installed.

Checking the version of python3


$ python3 --version
スクリーンショット 2017-02-09 20.42.55.png

My version was 3.6.0. If the first number starts with 3, it's basically okay.

Install frequently used libraries in python3

Install numpy (linear algebra), scipy (computer algebra), matplotlib (plot), and pandas (database), which are basically essential libraries for everything. Let's do it.

Install numpy and matplotlib


$ pip3 install numpy  #linear algebra
$ pip3 install scipy  #Computer algebra
$ pip3 install matplotlib   #drawing
$ pip3 install pandas  #Data manipulation

Installation will be completed in a few minutes.

Installation of libraries used in machine learning

scikit-learn

A machine learning package packed with models for classification and prediction. In data analysis with Python, it has a position that can be said to be almost de facto.

scikit-install learn


$ pip3 install scikit-learn

Chainer

It is a domestic library famous for implementing deep learning (neural network). There are plenty of Japanese references, and it is as popular as Google's Tensorflow.

Install Chainer


$ pip3 install chainer

Jupyter notebook

It is an environment where you can easily execute Python. We recommend that beginners use this Jupyter notebook to check the operation of the program.

Install Jupyter Notebook


$ pip3 install jupyter

This completes the environment construction for learning "machine learning".

(Bonus) Installation of Atom

The necessary software installation is complete, but for a little smoother programming, install the "** Editor " called " Atom ". " Editor **" is basically the same as the familiar Notepad, and is for writing and saving characters. However, editors in recent years have evolved so much that they can be colored to make programming easier to read, or have a terminal built into the editor to run programs smoothly.

Among the editors, the one that the author Yoshizaki recently recommends is "** Atom **". It's made by GitHub, so it's very easy to handle and stable.

To install Atom, download the installation file from the Official Page.

スクリーンショット 2017-02-09 21.05.41.png

Extract the downloaded file (double-click it to extract it), and if you can extract it, you're done. Make a copy of this file to the application folder described in the terminal first.

スクリーンショット 2017-02-09 21.07.39.png

This completes the installation of Atom itself.

When you open the Atom application, you will see a screen like this.

スクリーンショット 2017-02-09 21.09.52.png

Recommended settings for Atom

Let's simplify the settings inside Atom.

Select "Install a Package" on the right screen immediately after opening.

If you have closed the Welcome Guide, please use the toolbar at the top. "Atom"-> "Preferences"-> "Install" at the bottom left But you can get to the same screen.

スクリーンショット 2017-02-09 21.12.17.png

Search for "terminal" on this search screen.

Please install "platformio-ide-terminal" from the search results.

スクリーンショット 2017-02-09 21.13.21.png

Once this is installed, you can launch a terminal within Atom's editor, where you can write and run the program together, which makes development a lot easier. This setting is highly recommended for those who love the word "** productivity **".

スクリーンショット 2017-03-14 13.47.22.png スクリーンショット 2017-03-14 13.47.27.png

in conclusion

Thank you for building the environment on Mac. Were you able to build the environment smoothly?

I used Homebrew to install it in a very clean state, so if you need other libraries in the future, you can use the pip3 command and it will work, so don't worry.

We are very much looking forward to learning machine learning and revolutionizing various industries, and we hope that this article has helped you. If you found this article useful, we would appreciate it if you could like the article.

We look forward to your follow-up

We provide information on machine learning and artificial intelligence from a business perspective and recommended reference books.

President and CEO Ryosuke Yoshizaki Twitter:@yoshizaki_kkgk Facebook:@ryosuke.yoshizaki Blog: Blog of Kikagaku representative

Until the end Thank you for reading.

Recommended Posts

[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Build an environment for machine learning using Python on MacOSX
Memo for building a machine learning environment using Python
Building an environment for executing Python scripts (for mac)
Building an environment for matplotlib + cartopy on Mac
Install Python3 on Mac and build environment [Definitive Edition]
Build an interactive environment for machine learning in Python
Building an environment for "Tello_Video" on Mac OS X
Build a machine learning Python environment on Mac OS
How to build an environment for using multiple versions of Python on Mac
Building a Python environment on Mac
Building a Python environment on a Mac and using Jupyter lab
Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Building an auto-sklearn environment that semi-automates machine learning (Mac & Docker)
I tried to build an environment for machine learning with Python (Mac OS X)
[Python] Building an environment with Anaconda [Mac]
[Mac] Building a virtual environment for Python
An introduction to Python for machine learning
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
Building an HPC learning environment using Docker Compose (C, Python, Fortran)
Building an Anaconda environment for Python with pyenv
Building an environment for natural language processing with Python
Build a Python environment on your Mac using pyenv
Procedure for building a CDK environment on Windows (Python)
Building an environment for displaying organic compounds using RDKit
Building a Python environment for programming beginners (Mac OS)
Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)
Python environment construction For Mac
Rebuilding an environment for machine learning with Miniconda (Windows version)
Build a python machine learning study environment on macOS sierra
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Let's get started with Python ~ Building an environment on Windows 10 ~
Building an environment to execute python programs on AWS EC2
Create a virtual environment for python on mac [Very easy]
Until building a Python development environment using pyenv on Ubuntu 20.04
Error when building mac python environment
Create a Python environment on Mac (2017/4)
Python environment construction memo on Mac
<For beginners> python library <For machine learning>
Environment construction of python3.8 on mac
Python3 TensorFlow for Mac environment construction
[Python machine learning] Recommendation of using Spyder for beginners (as of August 2020)
Ansible playbook for setting up Python preferences using pyenv on Mac
Anyone can understand how to build an initial environment for Python on Mac September 2016 (pyenv + virutalenv)
Notes for using OpenCV on Windows10 Python 3.8.3.
Build an environment for Blender built-in Python
Python development environment for macOS using venv 2016
Notes on PyQ machine learning python grammar
Amplify images for machine learning with python
Create a python environment on your Mac
Creating amateur python environment settings (for MAC)
An introduction to OpenCV for machine learning
Why Python is chosen for machine learning
Notes on building Python and pyenv on Mac
[Shakyo] Encounter with Python for machine learning
Build Python environment with Anaconda on Mac