Build a Python environment for beginners to learn AI/ML

    It disappeared for a long time without knowing it, and the official account has not been updated for a long time. Because I ran to learn the MPP course in Microsoft's AI direction. MPP is currently Microsoft's first training course on AI. I will write a brief introduction to the MPP learning system later.

     MPP contains a lot of content. The speed of learning is quite fast at the beginning, and it becomes more and more difficult later. This is also one of the reasons why there is no energy to update the content for a long time. In the process of learning, I gradually came into contact with the Python environment required by AI or ML. Remember our introduction earlier? Use Python to call many APIs of AI to quickly implement some functions of AI.

    When I was learning the eDoc of the Azure AI API, I found that some sample codes were reflected in Jupyter Notebook. At that time, I thought, wouldn't it be good for me to have Python? Learn to code as it is. After the "mandatory" use of notebooks in the MPP course, I found that this method is really convenient to learn. Let me explain, I will try to read the code and add my own comments before I copy the sample code and run it. Notebook can write comments or notes as blocks in md format. The code is split into separate blocks of code. This makes it very easy to read background information and notes, while at the same time it's easy to run debugging code.

    In addition, many AI or ML courses will also provide notebooks in notebook file format to help learning, so it is necessary to have a notebook environment. Let's try to use the most complex construction method to build a notebook environment.

    I still remember that when I used VS Code to write Python for the first time, the code format was scored, and normalization was also part of learning the code, so pylint is still needed:
astroid-1.6.3 / isort-4.3.4 / lazy-object-proxy- 1.3.1/mccabe-0.6.1/pylint-1.8.4/wrapt-1.10.11

    So many AI APIs are provided in the form of web services, and quick API calls are inseparable from requests:

certifi-2018.4.16 / chardet-3.0.4 / idna-2.6 / requests-2.18.4 / urllib3-1.22

    How can data processing be done without numpy? What code seems to have to be array ~
numpy-1.14.2

    Similarly, pandas is also indispensable for ML processing data~

pandas-0.22.0 / pytz-2018.4

    All kinds of drawings are displayed in various ways, what if there is no matplotlib?

cycler-0.10.0 / kiwisolver-1.0.1 / matplotlib-2.2.2 / pyparsing-2.2.0

    Installing notebooks is a bit more complicated, and there are a lot of dependent libraries~

MarkupSafe-1.0 / Send2Trash-1.5.0 / backcall-0.1.0 / bleach-2.1.3 / decorator-4.3.0 / entrypoints-0.2.3 / html5lib-1.0.1 / ipykernel-4.8.2 / ipython-6.3.1 / ipython-genutils-0.2.0 / ipywidgets-7.2.1 / jedi-0.12.0 / jinja2-2.10 / jsonschema-2.6.0 / jupyter-1.0.0 / jupyter-client-5.2.3 / jupyter-console-5.2.0 / jupyter-core-4.4.0 / mistune-0.8.3 / nbconvert-5.3.1 / nbformat-4.4.0 / notebook-5.4.1 / pandocfilters-1.4.2 / parso-0.2.0 / pickleshare-0.7.4 / prompt-toolkit-1.0.15 / pygments-2.2.0 / python-dateutil-2.7.2 / pywinpty-0.5.1 / pyzmq-17.0.0 / qtconsole-4.3.1 / simplegeneric-0.8.1 / terminado-0.8.1 / testpath-0.3.1 / tornado-5.0.2 / traitlets-4.3.2 / wcwidth-0.1.7 / webencodings-0.5.1 / widgetsnbextension-3.2.1

    Then to do the MPP experiment, it is natural to need Microsoft's artificial intelligence tool library CNTK~ The course is quite strange, requiring version 2.0, and the later courses require an updated version, first install the 2.0 version

scipy-1.0.1 / cntk-2.0

    In fact, the above list of so many libraries does not make much sense. When using pip to install, it will automatically install the required libraries according to the dependencies. So why do I list all these libraries? There are two reasons, first, if we need to install offline; second, for all known reasons, when accessing the default library distribution, it often interferes with HTTPS traffic and causes the download to fail. At this time, you can follow the above list and go to the pypi website to prescribe the medicine.

    After the installation is complete, you can use the notebook to run locally.

image

    Having said all that, isn't there a more convenient way? have!

image

    In fact, Anaconda is used in the MPP course to build an environment for learning AI/ML. Use Anaconda to easily manage your environment graphically. However, when I look at the installation files, there are already hundreds of M. Thinking about the poor 200G space of the deformed book, it is not installed.

     So, is there a more convenient way? have!

     Visit https://notebooks.azure.com   without installing anything, just open it and use it.

image

     After finishing the ML course, I still feel confused~ It will take time to digest and digest, but the environment needs to be updated. Updating CNTK is simple:

PS C:\WINDOWS\system32> pip install cntk --upgrade
Collecting cntk
   Downloading https://files.pythonhosted.org/packages/e0/66/bd529934288094c4a4a7110fa6797669d95ffa7fc3687275a5541b80a281/cntk-2.5.1-cp36-cp36m-win_amd64.whl (63.7MB)
     100% |████████████████████████████████| 63.7MB 181kB/s
Requirement not upgraded as not directly required: scipy>=0.17 in c:\program files\python36\lib\site-packages (from cntk) (1.0.1)
Requirement not upgraded as not directly required: numpy>=1.11 in c:\program files\python36\lib\site-packages (from cntk) (1.14.2)
Installing collected packages: cntk
   Found existing installation: cntk 2.0
     Uninstalling cntk-2.0:
       Successfully uninstalled cntk-2.0
Successfully installed cntk-2.5.1

    Because when CNTK 2.0 was installed, the dependent scipy and numpy libraries were already the latest at that time, so there was no automatic update. But I still manually flash to the latest version.

    Then, you need to add OpenCV. Go to the official website and have a look, the default support is Python 2.7... What's wrong with this? Looking through the web page, it seems that there are unofficial libraries provided. Since everyone uses it, don't hesitate to install it:

PS C:\WINDOWS\system32> pip install opencv_python
Collecting opencv_python
   Downloading https://files.pythonhosted.org/packages/4c/25/151aeb11e80f99b97d3eb93a2c98bcacd857f28c4fb8865eb0201d800e97/opencv_python-3.4.0.12-cp36-cp36m-win_amd64.whl (33.3MB)
     100% |████████████████████████████████| 33.4MB 581kB/s
Requirement already satisfied: numpy>=1.11.3 in c:\program files\python36\lib\site-packages (from opencv_python) (1.14.3)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.0.12

     验证一下安装:
PS C:\WINDOWS\system32> python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
3.4.0

     It seems that there is an updated version here, but it is no longer downloaded and installed manually.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv

    By the way, when upgrading Python itself, I encountered an interesting error:

C:\Personal\Hao.Hu\My Codes>jupyter
Fatal error in launcher: Unable to create process using '""c:\program files\python36\python.exe"  "C:\Program Files\Python36\Scripts\jupyter.exe" '

    I checked it, and it is related to the path setting of the exe generated at compile time. After some tossing, changing the path and reinstalling the library, the exe compiled again is no problem.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325947436&siteId=291194637