如何开始使用Python进行深度学习和数据科学

by Joseph Lee Wei En

通过李维恩

如何开始使用Python进行深度学习和数据科学 (How to get started with Python for Deep Learning and Data Science)

为初学者设置Python的分步指南 (A step-by-step guide to setting up Python for a complete beginner)

You can code your own Data Science or Deep Learning project in just a couple of lines of code these days. This is not an exaggeration; many programmers out there have done the hard work of writing tons of code for us to use, so that all we need to do is plug-and-play rather than write code from scratch.

如今,您仅需执行几行代码即可编写自己的数据科学或深度学习项目。 这并不夸张。 许多程序员在那里辛苦地编写了供我们使用的大量代码,因此我们所需要做的就是即插即用,而不是从头开始编写代码。

You may have seen some of this code on Data Science / Deep Learning blog posts. Perhaps you might have thought: “Well, if it’s really that easy, then why don’t I try it out myself?”

您可能已经在数据科学/深度学习博客文章中看到了其中一些代码。 也许您可能会想过:“好吧,如果真的那么简单,那我为什么不自己尝试一下呢?”

If you’re a beginner to Python and you want to embark on this journey, then this post will guide you through your first steps. A common complaint I hear from complete beginners is that it’s pretty difficult to set up Python. How do we get everything started in the first place so that we can plug-and-play Data Science or Deep Learning code?

如果您是Python的初学者,并且想开始这一旅程,那么这篇文章将指导您完成第一步。 我从初学者那里听到的一个普遍抱怨是,设置Python非常困难。 我们如何首先开始一切,以便我们可以即插即用的数据科学或深度学习代码?

This post will guide you through in a step-by-step manner how to set up Python for your Data Science and Deep Learning projects. We will:

这篇文章将逐步指导您如何为数据科学和深度学习项目设置Python。 我们会:

  • Set up Anaconda and Jupyter Notebook

    设置Anaconda和Jupyter Notebook
  • Create Anaconda environments and install packages (code that others have written to make our lives tremendously easy) like tensorflow, keras, pandas, scikit-learn and matplotlib.

    创建Anaconda环境并安装tensorflow,keras,pandas,scikit-learn和matplotlib等软件包(其他人编写的代码使我们的生活变得异常轻松)。

Once you’ve set up the above, you can build your first neural network to predict house prices in this tutorial here:

完成上述设置后,您可以在本教程中构建第一个神经网络来预测房价:

Build your first Neural Network to predict house prices with Keras

使用Keras建立您的第一个神经网络来预测房价

设置Anaconda和Jupyter Notebook (Setting up Anaconda and Jupyter Notebook)

The main programming language we are going to use is called Python, which is the most common programming language used by Deep Learning practitioners.

我们将使用的主要编程语言称为Python,这是深度学习从业人员最常用的编程语言。

The first step is to download Anaconda, which you can think of as a platform for you to use Python “out of the box”.

第一步是下载Anaconda,您可以将其视为可以立即使用Python的平台。

Visit this page: https://www.anaconda.com/distribution/ and scroll down to see this:

访问此页面: https : //www.anaconda.com/distribution/并向下滚动以查看此内容:

This tutorial is written specifically for Windows users, but the instructions for users of other Operating Systems are not all that different. Be sure to click on “Windows” as your Operating System (or whatever OS that you are on) to make sure that you are downloading the correct version.

本教程是专门为Windows用户编写的,但是对其他操作系统用户的说明并没有什么不同。 确保单击“ Windows”作为您的操作系统(或您所使用的任何操作系统),以确保下载正确的版本。

This tutorial will be using Python 3, so click the green Download button under “Python 3.7 version”. A pop up should appear for you to click “Save” into whatever directory you wish.

本教程将使用Python 3,因此请单击“ Python 3.7版本”下的绿色“下载”按钮。 应该出现一个弹出窗口,供您单击“保存”到所需的任何目录。

Once it has finished downloading, just go through the setup step by step as follows:

下载完成后,只需按以下步骤逐步进行设置:

Once the installation is done, go to your Start Menu and you should see some newly installed software:

安装完成后,转到“开始”菜单,您应该会看到一些新安装的软件:

Click on Anaconda Navigator, which is a one-stop hub to navigate the apps we need. You should see a front page like this:

单击Anaconda Navigator,这是一个一站式集线器,可导航我们所需的应用程序。 您应该看到这样的首页:

Click on ‘Launch’ under Jupyter Notebook, which is the second panel on my screen above. Jupyter Notebook allows us to run Python code interactively on the web browser, and it’s where we will be writing most of our code.

单击Jupyter Notebook下的“启动”,这是我在屏幕上方的第二个面板。 Jupyter Notebook允许我们在Web浏览器上交互式运行Python代码,这是我们将编写大多数代码的地方。

A browser window should open up with your directory listing. I’m going to create a folder on my Desktop called “Intuitive Deep Learning Tutorial”. If you navigate to the folder, your browser should look something like this:

将打开一个浏览器窗口,其中包含您的目录列表。 我将在桌面上创建一个名为“ Intuitive Deep Learning Tutorial”的文件夹。 如果导航到该文件夹​​,则浏览器应如下所示:

On the top right, click on New and select “Python 3”:

在右上角,单击“新建”,然后选择“ Python 3”:

A new browser window should pop up like this.

这样会弹出一个新的浏览器窗口。

Congratulations — you’ve created your first Jupyter notebook! Now it’s time to write some code. Jupyter notebooks allow us to write snippets of code and then run those snippets without running the full program. This helps us perhaps look at any intermediate output from our program.

恭喜,您已经创建了第一本Jupyter笔记本! 现在是时候编写一些代码了。 Jupyter笔记本允许我们编写代码段,然后在不运行完整程序的情况下运行这些代码段。 这也许可以帮助我们查看程序中的任何中间输出。

To begin, let’s write code that will display some words when we run it. This function is called print. Copy and paste the code below into the grey box on your Jupyter notebook:

首先,让我们编写运行时将显示一些单词的代码。 此功能称为print 。 将以下代码复制并粘贴到Jupyter笔记本的灰色框中:

print("Hello World!")

Your notebook should look like this:

您的笔记本应如下所示:

Now, press Alt-Enter on your keyboard to run that snippet of code:

现在,按键盘上的Alt-Enter键运行该代码段:

You can see that Jupyter notebook has displayed the words “Hello World!” on the display panel below the code snippet! The number 1 has also filled in the square brackets, meaning that this is the first code snippet that we’ve run thus far. This will help us to track the order in which we have run our code snippets.

您会看到Jupyter笔记本显示了“ Hello World!”字样。 在代码段下方的显示面板上! 数字1也已填充在方括号中,这意味着这是到目前为止我们运行的第一个代码段。 这将有助于我们跟踪代码段的运行顺序。

Instead of Alt-Enter, note that you can also click Run when the code snippet is highlighted:

请注意,当代码段突出显示时,也可以单击“运行”来代替Alt-Enter:

If you wish to create new grey blocks to write more snippets of code, you can do so under Insert.

如果您希望创建新的灰色块来编写更多代码段,则可以在“插入”下执行此操作。

Jupyter Notebook also allows you to write normal text instead of code. Click on the drop-down menu that currently says “Code” and select “Markdown”:

Jupyter Notebook还允许您编写普通文本而不是代码。 单击当前显示“代码”的下拉菜单,然后选择“降价”:

Now, our grey box that is tagged as markdown will not have square brackets beside it. If you write some text in this grey box now and press Alt-Enter, the text will render it as plain text like this:

现在,标记为markdown的灰色框旁边将没有方括号。 如果您现在在此灰色框中写一些文本,然后按Alt-Enter,则文本会将其呈现为纯文本,如下所示:

There are some other features that you can explore. But now we’ve got Jupyter notebook set up for us to start writing some code!

您还可以探索其他一些功能。 但是,现在我们已经为Jupyter笔记本设置好了,可以开始编写一些代码!

设置Anaconda环境并安装软件包 (Setting up Anaconda environment and installing packages)

Now we’ve got our coding platform set up. But are we going to write Deep Learning code from scratch? That seems like an extremely difficult thing to do!

现在我们已经建立了编码平台。 但是我们要从头开始编写深度学习代码吗? 这似乎是一件非常困难的事情!

The good news is that many others have written code and made it available to us! With the contribution of others’ code, we can play around with Deep Learning models at a very high level without having to worry about implementing all of it from scratch. This makes it extremely easy for us to get started with coding Deep Learning models.

好消息是,许多其他人已经编写了代码并将其提供给我们! 借助其他人的代码,我们可以在很高的层次上使用深度学习模型,而不必担心从头开始实现所有这些。 这使我们非常轻松地开始编写深度学习模型的代码。

For this tutorial, we will be downloading five packages that Deep Learning practitioners commonly use:

对于本教程,我们将下载深度学习从业人员常用的五个软件包:

  • Tensorflow

    张量流
  • Keras

    凯拉斯
  • Pandas

    大熊猫
  • Scikit-learn

    Scikit学习
  • Matplotlib

    Matplotlib

The first thing we will do is to create a Python environment. An environment is like an isolated working copy of Python, so that whatever you do in your environment (such as installing new packages) will not affect other environments. It’s good practice to create an environment for your projects.

我们要做的第一件事是创建一个Python环境。 环境就像一个孤立的Python工作副本,因此您在环境中所做的任何事情(例如安装新软件包)都不会影响其他环境。 为您的项目创建环境是一个好习惯。

Click on Environments on the left panel and you should see a screen like this:

单击左侧面板上的“环境”,您将看到如下屏幕:

Click on the button “Create” at the bottom of the list. A pop-up like this should appear:

单击列表底部的“创建”按钮。 这样的弹出窗口应该出现:

Name your environment and select Python 3.7 and then click Create. This might take a few moments.

命名您的环境,然后选择Python 3.7,然后单击“创建”。 这可能需要一些时间。

Once that is done, your screen should look something like this:

完成后,您的屏幕应如下所示:

Notice that we have created an environment ‘intuitive-deep-learning’. We can see what packages we have installed in this environment and their respective versions.

请注意,我们已经创建了一个“直观-深度学习”环境。 我们可以看到在此环境中安装了哪些软件包以及它们各自的版本。

Now let’s install some packages we need into our environment!

现在,让我们在环境中安装一些我们需要的软件包!

The first two packages we will install are called Tensorflow and Keras, which help us plug-and-play code for Deep Learning.

我们将安装的前两个软件包分别称为Tensorflow和Keras,它们可以帮助我们实现即插即用的深度学习代码。

On Anaconda Navigator, click on the drop down menu where it currently says “Installed” and select “Not Installed”:

在Anaconda Navigator上,单击当前显示“已安装”的下拉菜单,然后选择“未安装”:

A whole list of packages that you have not installed will appear like this:

尚未安装的软件包的完整列表将显示如下:

Search for “tensorflow”, and click the checkbox for both “keras” and “tensorflow”. Then, click “Apply” on the bottom right of your screen:

搜索“ tensorflow”,然后单击“ keras”和“ tensorflow”的复选框。 然后,点击屏幕右下方的“应用”:

A pop up should appear like this:

弹出窗口应如下所示:

Click Apply and wait for a few moments. Once that’s done, we will have Keras and Tensorflow installed in our environment!

单击“应用”,等待片刻。 完成后,我们将在环境中安装Keras和Tensorflow!

Using the same method, let’s install the packages ‘pandas’, ‘scikit-learn’ and ‘matplotlib’. These are common packages that data scientists use to process the data as well as to visualize nice graphs in Jupyter notebook.

使用相同的方法,让我们安装软件包“ pandas”,“ scikit-learn”和“ matplotlib”。 这些是数据科学家用来处理数据以及在Jupyter笔记本中可视化漂亮图形的常用软件包。

This is what you should see on your Anaconda Navigator for each of the packages.

这是您应该在Anaconda Navigator上看到的每个软件包的内容。

Pandas:

熊猫:

Scikit-learn:

Scikit学习:

Matplotlib:

Matplotlib:

Once it’s done, go back to “Home” on the left panel of Anaconda Navigator. You should see a screen like this, where it says “Applications on intuitive-deep-learning” at the top:

完成后,返回到Anaconda Navigator左侧面板上的“主页”。 您应该看到这样的屏幕,它的顶部显示“直观-深度学习的应用程序”:

Now, we have to install Jupyter notebook in this environment. So click the green button “Install” under the Jupyter notebook logo. It will take a few moments (again). Once it’s done installing, the Jupyter notebook panel should look like this:

现在,我们必须在此环境中安装Jupyter Notebook。 因此,请单击Jupyter笔记本徽标下的绿色按钮“安装”。 (再次)需要一些时间。 安装完成后,Jupyter笔记本面板应如下所示:

Click on Launch, and the Jupyter notebook app should open.

单击启动,Jupyter笔记本应用程序应打开。

Create a notebook and type in these five snippets of code and click Alt-Enter. This code tells the notebook that we will be using the five packages that you installed with Anaconda Navigator earlier in the tutorial.

创建一个笔记本,然后输入这五个代码段,然后单击Alt-Enter。 此代码告诉笔记本,我们将使用在教程前面的Anaconda Navigator中安装的五个软件包。

import tensorflow as tf
import keras
import pandas
import sklearn
import matplotlib

If there are no errors, then congratulations — you’ve got everything installed correctly:

如果没有错误,那么恭喜您-您已正确安装了所有程序:

Now that we’ve got everything set up, we’ll start building our first neural network here:

现在我们已经完成了所有设置,我们将在这里开始构建第一个神经网络:

Build your first Neural Network to predict house prices with KerasA step-by-step complete beginner’s guide to building your first Neural Network in a couple lines of code like a Deep…medium.com

使用Keras构建您的第一个神经网络以预测房价 一步一步的完整的初学者指南,以 Deep。medium.com 等几行代码构建第一个神经网络。

If you have had any trouble with any of the steps above, please feel free to comment below and I’ll help you out!

如果您在执行上述任何步骤时遇到任何问题,请在下面发表评论,我们将为您提供帮助!

About the author:

关于作者:

Hi there, I’m Joseph! I recently graduated from Stanford University, where I worked with Andrew Ng in the Stanford Machine Learning Group. I want to make Deep Learning concepts as intuitive and as easily understandable as possible by everyone, which has motivated my publication: Intuitive Deep Learning.

嗨,我是约瑟夫 ! 我最近从斯坦福大学毕业,在那里我与斯坦福机器学习小组的 Andrew Ng合作。 我想使深度学习的概念对每个人都尽可能直观和易于理解,这激发了我的著作:《 直观的深度学习》 。

翻译自: https://www.freecodecamp.org/news/how-to-get-started-with-python-for-deep-learning-and-data-science-3bed07f91a08/

你可能感兴趣的:(神经网络,python,机器学习,深度学习,java)