初步 EDA

用 Python 赢下 Kaggle 竞赛

Yauhen Babakhin

Kaggle Grandmaster

EDA 目标

 

  • 数据规模
  • 目标变量特性
  • 特征特性
  • 产生特征工程思路
用 Python 赢下 Kaggle 竞赛

Two Sigma Connect:租房咨询

 

问题描述
预测公寓租房信息的受欢迎度

目标变量
interest_level

问题类型
三分类:'high'、'medium'、'low'

评估指标
多分类对数损失

用 Python 赢下 Kaggle 竞赛

EDA:第 I 部分

# 数据规模
twosigma_train = pd.read_csv('twosigma_train.csv')
print('Train shape:', twosigma_train.shape)

twosigma_test = pd.read_csv('twosigma_test.csv')
print('Test shape:', twosigma_test.shape)
Train shape: (49352, 11)
Test shape: (74659, 10)
用 Python 赢下 Kaggle 竞赛

EDA:第 I 部分

print(twosigma_train.columns.tolist())
['id', 'bathrooms', 'bedrooms', 'building_id', 'latitude', 'longitude',
'manager_id', 'price', 'interest_level']
twosigma_train.interest_level.value_counts()
low       34284
medium    11229
high       3839
用 Python 赢下 Kaggle 竞赛

EDA:第 I 部分

# 描述训练数据
twosigma_train.describe()
         bathrooms      bedrooms      latitude     longitude         price
count  49352.00000  49352.000000  49352.000000  49352.000000  4.935200e+04
mean       1.21218      1.541640     40.741545    -73.955716  3.830174e+03
std        0.50142      1.115018      0.638535      1.177912  2.206687e+04
min        0.00000      0.000000      0.000000   -118.271000  4.300000e+01
25%        1.00000      1.000000     40.728300    -73.991700  2.500000e+03
50%        1.00000      1.000000     40.751800    -73.977900  3.150000e+03
75%        1.00000      2.000000     40.774300    -73.954800  4.100000e+03
max       10.00000      8.000000     44.883500      0.000000  4.490000e+06
用 Python 赢下 Kaggle 竞赛

EDA:第 II 部分

 

import matplotlib.pyplot as plt
plt.style.use('ggplot')
# 按兴趣等级计算价格中位数
prices = twosigma_train.groupby('interest_level', as_index=False)['price'].median()
用 Python 赢下 Kaggle 竞赛

EDA:第 II 部分

# 绘制柱状图
fig = plt.figure(figsize=(7, 5))
plt.bar(prices.interest_level, prices.price, width=0.5, alpha=0.8)

# 设置标题和标签 plt.xlabel('Interest level') plt.ylabel('Median price') plt.title('Median listing price across interest level')
# 显示图形 plt.show()
用 Python 赢下 Kaggle 竞赛

不同兴趣等级的挂牌价中位数

用 Python 赢下 Kaggle 竞赛

Passons à la pratique !

用 Python 赢下 Kaggle 竞赛

Preparing Video For Download...