Logistic Regression In Python 简明教程
Setting Up a Project
在本章中,我们将详细了解在 Python 中设置一个用于执行逻辑回归的项目的过程中涉及的步骤。
In this chapter, we will understand the process involved in setting up a project to perform logistic regression in Python, in detail.
Installing Jupyter
我们将使用 Jupyter——机器学习中最广泛使用的平台之一。如果你还没有在你的机器上安装 Jupyter,请从 here 下载。你可以按照它们网站上的说明来安装这个平台。正如该网站所建议的,你可能更愿意使用 Anaconda Distribution ,它与 Python 以及许多常用的用于科学计算和数据科学的 Python 软件包一起提供。这将避免了单独安装这些软件包的需要。
We will be using Jupyter - one of the most widely used platforms for machine learning. If you do not have Jupyter installed on your machine, download it from here. For installation, you can follow the instructions on their site to install the platform. As the site suggests, you may prefer to use Anaconda Distribution which comes along with Python and many commonly used Python packages for scientific computing and data science. This will alleviate the need for installing these packages individually.
在成功安装 Jupyter 之后,创建一个新项目,你现在屏幕上的样子应该像下面这样,准备接受你的代码。
After the successful installation of Jupyter, start a new project, your screen at this stage would look like the following ready to accept your code.
现在,通过点击标题名称并编辑,将项目的名称从 Untitled1 to “Logistic Regression” 更改。
Now, change the name of the project from Untitled1 to “Logistic Regression” by clicking the title name and editing it.
首先,我们将导入我们在代码中需要的几个 Python 软件包。
First, we will be importing several Python packages that we will need in our code.
Importing Python Packages
为此,在代码编辑器中键入或粘贴以下代码 −
For this purpose, type or cut-and-paste the following code in the code editor −
In [1]: # import statements
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
此时,你的 Notebook 应该像下面这样 −
Your Notebook should look like the following at this stage −
通过点击 Run 按钮来运行代码。如果没有生成任何错误,说明你已成功安装 Jupyter,现在准备好进行其余的开发工作。
Run the code by clicking on the Run button. If no errors are generated, you have successfully installed Jupyter and are now ready for the rest of the development.
前三个 import 语句在我们的项目中导入了 pandas、numpy 和 matplotlib.pyplot 软件包。接下来的三个语句从 sklearn 导入了指定的模块。
The first three import statements import pandas, numpy and matplotlib.pyplot packages in our project. The next three statements import the specified modules from sklearn.
我们的下一个任务是下载项目所需的数据。我们将在下一章学习它。
Our next task is to download the data required for our project. We will learn this in the next chapter.