为何生成特征?

Python 中的机器学习特征工程

Robert O'Callaghan

Director of Data Science, Ordergroove

特征工程

Python 中的机器学习特征工程

数据类型

  • 连续型:整数(或自然数)或浮点数(小数)
  • 分类型:取自有限集合,例如性别、出生国家
  • 序数型:有顺序,间距未定
  • 布尔型:True/False 值
  • 日期时间:日期与时间
Python 中的机器学习特征工程

课程结构

  • 第 1 章:特征创建与提取

  • 第 2 章:处理脏数据

  • 第 3 章:特征归一化

  • 第 4 章:文本特征处理

Python 中的机器学习特征工程

Pandas

import pandas as pd  
df = pd.read_csv(path_to_csv_file)
print(df.head())
Python 中的机器学习特征工程

数据集

              SurveyDate  \
0    2018-02-28 20:20:00     
1    2018-06-28 13:26:00     
2    2018-06-06 03:37:00     
3    2018-05-09 01:06:00     
4    2018-04-12 22:41:00    

                              FormalEducation
0    Bachelor's degree (BA. BS. B.Eng.. etc.)
1    Bachelor's degree (BA. BS. B.Eng.. etc.)
2    Bachelor's degree (BA. BS. B.Eng.. etc.)
3    Some college/university study  ...
4    Bachelor's degree (BA. BS. B.Eng.. etc.)
Python 中的机器学习特征工程

列名

print(df.columns)
Index(['SurveyDate', 'FormalEducation',
       'ConvertedSalary', 'Hobby', 'Country',
       'StackOverflowJobsRecommend', 'VersionControl', 
       'Age', 'Years Experience', 'Gender', 
       'RawSalary'], dtype='object')
Python 中的机器学习特征工程

列类型

print(df.dtypes)
SurveyDate                            object
FormalEducation                       object
ConvertedSalary                      float64
...
Years Experience                       int64
Gender                                object
RawSalary                             object
dtype: object
Python 中的机器学习特征工程

选择特定数据类型

only_ints = df.select_dtypes(include=['int'])
print(only_ints.columns)
Index(['Age', 'Years Experience'], dtype='object')
Python 中的机器学习特征工程

开始吧!

Python 中的机器学习特征工程

Preparing Video For Download...