官术网_书友最值得收藏!

Preparing a dataset for machine learning with scikit-learn

The first step to implementing any machine learning algorithm with scikit-learn is data preparation. Scikit-learn comes with a set of constraints to implementation that will be discussed later in this section. The dataset that we will be using is based on mobile payments and is found on the world's most popular competitive machine learning website – Kaggle.

You can download the dataset from: https://www.kaggle.com/ntnu-testimon/paysim1.

Once downloaded, open a new Jupyter Notebook by using the following code in Terminal (macOS/Linux) or Anaconda Prompt/PowerShell (Windows):

Jupyter Notebook

The fundamental goal of this dataset is to predict whether a mobile transaction is fraudulent. In order to do this, we need to first have a brief understanding of the contents of our data. In order to explore the dataset, we will use the pandas package in Python. You can install pandas by using the following code in Terminal (macOS/Linux) or PowerShell (Windows):

pip3 install pandas

Pandas can be installed on Windows machines in an Anaconda Prompt by using the following code:

conda install pandas

We can now read in the dataset into our Jupyter Notebook by using the following code: 

#Package Imports

import pandas as pd

#Reading in the dataset

df = pd.read_csv('PS_20174392719_1491204439457_log.csv')

#Viewing the first 5 rows of the dataset

df.head()

This produces an output as illustrated in the following screenshot: 

主站蜘蛛池模板: 葫芦岛市| 灵川县| 嘉善县| 渝中区| 宝丰县| 大理市| 施秉县| 安宁市| 三河市| 云霄县| 镇雄县| 巴东县| 武义县| 沧州市| 麦盖提县| 阜新| 长垣县| 柘荣县| 达拉特旗| 秀山| 金秀| 东平县| 灵武市| 将乐县| 尼木县| 通州市| 丽江市| 阜新| 长治市| 防城港市| 广德县| 宣城市| 名山县| 时尚| 内黄县| 蒲江县| 无锡市| 陵水| 宁乡县| 双峰县| 灵璧县|