Building a Python environment for machine learning with Miniconda [Windows 10]

2018/11/11

Build Python environment with Miniconda

It is a method to build a python environment with Miniconda on a Windows 10 PC.

If you are not accustomed to it, you may stumble when building the environment, so I have summarized the steps that even I, a non-engineer, could do.I think that there are many new people who want to start machine learning and deep learning with python, so I would appreciate it if you could refer to it.

"Anaconda" is often recommended as a method of building a Python environment for beginners, but it is wasteful because you cannot use libraries that you do not know.

If you are trying programming for the first time, or if you want to experience machine learning on Windows for the time being, setting up with Miniconda is easy and just right.It is also useful to be able to use it properly if you can grasp the packages installed by yourself.

On the other hand, it is said that those who are accustomed to programming and those who are involved in development should build the environment purely using Python and pip / venv.This is because computers such as those used by developers use Mac OS or Linux as the OS, and they conflict with Python, which is included as standard in those OSs, and cause problems.

See also here for the differences between Anaconda and Miniconda.

reference:https://conda.io/docs/index.html

First, download the installer from the miniconda site.https://docs.conda.io/en/latest/miniconda.html

Miniconda install
Download the Windows version from one of the red frames.You can check whether your PC is 32bit or 64bit by right-clicking "PC" in "Explorer" and selecting "Properties".

Miniconda setup

After downloading, open the installer.Agree and select "Just Me".

Miniconda setup

Select the installation folder.The required capacity is about 260MB.

Anaconda prompt

After the installation is complete, open "Anaconda prompt" from the start menu.conda listIf you enter, you can see the list of installed items as shown below.

conda list

You can see that Python 3.7.0 (the target programming language) and conda (necessary to install various libraries) have been installed properly.Installation is complete.

Virtual environment settings

Depending on the library, the version of the other library on which it depends is strictly determined, and operation may not be guaranteed by upgrading one of the libraries.For example, scikit-learn doesn't work unless it's numpy 1.8.2 or higher, but there are things I want to do with earlier versions of numpy.

In preparation for such cases, you can create an environment (library installation destination) for each purpose and use it separately.

  1. Check the current environment:conda info -e(* Is added to the current environment. First, directly under the installation destination)
  2. Creating a virtual environment:conda create -n 仮想環境名
  3. Virtual environment selection:activate 仮想環境名

You can now install the library with conda or pip in the virtual environment of your choice.

Library installation

Basically, just enter the following conda prompt.

A list is displayed in a row including packages that need to be installed together, and "Proceed ([y] / n)?" Is confirmed, so enter y.

conda install Library name to install Proceed ([y] / n)? y

This is a typical library for machine learning.conda installIf you enter after, you can install all at once.

conda install numpy pandas scikit-learn matplotlib

numpy: for numerical calculation
pandas: for data preprocessing
scikit-learn: for machine learning
matplotlib: For graph drawing

The accessory packages required to run these (for example, numpy, scipy for scikit-learn) are also installed.

As a caveat, you shouldn't install non-conda libraries with pip (The Anaconda environment was corrupted when I thought the Jupyter Notebook wouldn't start).

It has happened, but the conda environment is broken and I have to reinstall it.