二手车交易价格预测 -Task1 赛题理解

二手车交易价格预测 -Task1 赛题理解

一、 赛题理解

赛题:零基础入门数据挖掘 - 二手车交易价格预测

地址:https://tianchi.aliyun.com/competition/entrance/231784/introduction?spm=5176.12281957.1004.1.38b02448ausjSX

 

赛题概况

比赛要求参赛选手根据给定的数据集,建立模型,二手汽车的交易价格。

赛题以预测二手车的交易价格为任务,数据集报名后可见并可下载,该数据来自某交易平台的二手车交易记录,总数据量超过40w,包含31列变量信息,其中15列为匿名变量。为了保证比赛的公平性,将会从中抽取15万条作为训练集,5万条作为测试集A,5万条作为测试集B,同时会对name、model、brand和regionCode等信息进行脱敏。

通过这道赛题来引导大家走进 AI 数据竞赛的世界,主要针对于于竞赛新人进行自我练习、自我提高。

问题说明

明确定义需要解决的问题。已制定解决问题的策略,并讨论了预期解决方案。

在这个源自阿里云天池的比赛:预测二手车的交易价格中,希望参赛者能通过给出的数据来预测二手车的交易价格,交易价格是数值型因而我们需要解决的是“回归问题”,基于有标签的数据集预测结果,这里我们用“监督学习算法”来实现此项目;再根据评价指标,所得的预测值与实际值的差值越小,准确性就越好。

本项⽬采⽤的模型是 XGBoost、GBDT 和 RandomForest 通过最后模型效果选择最优模型来做最终模型。

数据概况

天池比赛提供的数据文件:

  • used_car_train_20200313.zip(22MB) 训练数据集,

  • used_car_testB_20200421p.zip(7MB) 测试数据集,跟“train”机构一样,缺少“price”字段,用于最终的测试

  • used_car_sample_submit.csv(439KB) 提交数据集的参考样本

该数据来自某交易平台的二手车交易记录,总数据量超过40w,包含31列变量信息,其中15列为匿名变量。为了保证比赛的公平性,将会从中抽取15万条作为训练集,5万条作为测试集A,5万条作为测试集B,同时会对name、model、brand和regionCode等信息进行脱敏。

预测指标


本赛题的评价标准为MAE(Mean Absolute Error):

其中y{i}代表第i个样本的真实值,其中\hat{y}{i}代表第i个样本的预测值。


基本流程

  1. 初始化开发环境,加载所需库。

  2. 加载数据,数据完整性探索。

  3. 数据预处理。

  4. 数据探索。

  5. 特征工程。

  6. 模型构建、训练、调参、优化。

  7. 生成天池比赛的提交文件。

  8. 记录天池比赛得分情况。

初始化开发环境

 

# coding: utf-8
 
#开发环境:windows10, Anacoda3.7 , jupyter notebook ,python3.7
#库: numpy,pandas,matplotlib,seaborn,xgboost,time,warnings
#运行时间:CPU: i5-6700HQ
 
#项目名称: 二手车交易价格预测
​
#导入所需要的库
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
​
from sklearn.model_selection import GridSearchCV,cross_val_score,KFold,train_test_split
from sklearn.metrics import mean_squared_error, mean_absolute_error
import xgboost as xgb
from time import time
import warnings
warnings.filterwarnings("ignore")

准备数据

所需数据都存放于当前目录的/data/中

部分字段解释:

  • name - 汽车编码

  • regDate - 汽车注册时间

  • model - 车型编码

  • brand - 品牌

  • bodyType - 车身类型

  • fuelType - 燃油类型

  • gearbox - 变速箱

  • power - 汽车功率

  • kilometer - 汽车行驶公里

  • notRepairedDamage - 汽车有尚未修复的损坏

  • regionCode - 看车地区编码

  • seller - 销售方

  • offerType - 报价类型

  • creatDate - 广告发布时间

  • price - 汽车价格

  • v_0', 'v_1', 'v_2', 'v_3', 'v_4', 'v_5', 'v_6', 'v_7', 'v_8', 'v_9', 'v_10', 'v_11', 'v_12', 'v_13','v_14'(根据汽车的评论、标签等大量信息得到的embedding向量)【人工构造 匿名特征】

数字全都脱敏处理,都为label encoding形式,即数字形式

加载数据

## 通过Pandas对于数据进行读取 

train = pd.read_csv('data/used_car_train_20200313.csv', sep=' ')
testB  = pd.read_csv('data/used_car_testA_20200313.csv', sep=' ')
​
## 输出数据的大小信息
print('Train data shape:',train.shape)
print('TestB data shape:',testB.shape)
Train data shape: (150000, 31)
TestB data shape: (50000, 30)
train.head(5).append(train.tail())

 

 SaleIDnameregDatemodelbrandbodyTypefuelTypegearboxpowerkilometer...v_5v_6v_7v_8v_9v_10v_11v_12v_13v_14
007362004040230.061.00.00.06012.5...0.2356760.1019880.1295490.0228160.097462-2.8818032.804097-2.4208210.7952920.914762
1122622003030140.012.00.00.0015.0...0.2647770.1210040.1357310.0265970.020582-4.9004822.096338-1.030483-1.7226740.245522
221487420040403115.0151.00.00.016312.5...0.2514100.1149120.1651470.0621730.027075-4.8467491.8035591.565330-0.832687-0.229963
337186519960908109.0100.00.01.019315.0...0.2742930.1103000.1219640.0333950.000000-4.5095991.285940-0.501868-2.438353-0.478699
4411108020120103110.051.00.00.0685.0...0.2280360.0732050.0918800.0788190.121534-1.8962400.9107830.9311102.8345181.923482
14999514999516397820000607121.0104.00.01.016315.0...0.2802640.0003100.0484410.0711580.0191741.988114-2.9839730.589167-1.304370-0.302592
14999614999618453520091102116.0110.00.00.012510.0...0.2532170.0007770.0840790.0996810.0793711.839166-2.7746152.5539940.924196-0.272160
1499971499971475872010100360.0111.01.00.0906.0...0.2333530.0007050.1188720.1001180.0979142.439812-1.6306772.2901971.8919220.414931
149998149998459072006031234.0103.01.00.015615.0...0.2563690.0002520.0814790.0835580.0814982.075380-2.6337191.4149370.431981-1.659014
1499991499991776721999020419.0286.00.01.019312.5...0.2844750.0000000.0400720.0625430.0258191.978453-3.1799130.031724-1.483350-0.342674

10 rows × 31 columns

​train.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150000 entries, 0 to 149999
Data columns (total 31 columns):
SaleID               150000 non-null int64
name                 150000 non-null int64
regDate              150000 non-null int64
model                149999 non-null float64
brand                150000 non-null int64
bodyType             145494 non-null float64
fuelType             141320 non-null float64
gearbox              144019 non-null float64
power                150000 non-null int64
kilometer            150000 non-null float64
notRepairedDamage    150000 non-null object
regionCode           150000 non-null int64
seller               150000 non-null int64
offerType            150000 non-null int64
creatDate            150000 non-null int64
price                150000 non-null int64
v_0                  150000 non-null float64
v_1                  150000 non-null float64
v_2                  150000 non-null float64
v_3                  150000 non-null float64
v_4                  150000 non-null float64
v_5                  150000 non-null float64
v_6                  150000 non-null float64
v_7                  150000 non-null float64
v_8                  150000 non-null float64
v_9                  150000 non-null float64
v_10                 150000 non-null float64
v_11                 150000 non-null float64
v_12                 150000 non-null float64
v_13                 150000 non-null float64
v_14                 150000 non-null float64
dtypes: float64(20), int64(10), object(1)
memory usage: 35.5+ MB

总共数据 15万 条数据,数据完整,无null字段

#查看测试集
testB.head(5).append(testB.tail())

 SaleIDnameregDatemodelbrandbodyTypefuelTypegearboxpowerkilometer...v_5v_6v_7v_8v_9v_10v_11v_12v_13v_14
01500006693220111212222.045.01.01.031315.0...0.2644050.1218000.0708990.1065580.078867-7.050969-0.8546264.8001510.620011-3.664654
11500011749601999021119.0210.00.00.07512.5...0.2617450.0000000.0967330.0137050.0523833.679418-0.729039-3.796107-1.541230-0.757055
215000253562009030482.0210.00.00.01097.0...0.2602160.1120810.0780820.0620780.050540-4.9266901.0011060.8265620.1382260.754033
315000350688201004050.000.00.01.01607.0...0.2604660.1067270.0811460.0759710.048268-4.8646370.5054931.8703790.3660381.312775
41500041614281997070326.0142.00.00.07515.0...0.2509990.0000000.0778060.0286000.0817093.616475-0.673236-3.197685-0.025678-0.101290
4999519999520903199605034.044.00.00.011615.0...0.2846640.1300440.0498330.0288070.004616-5.9785111.303174-1.207191-1.981240-0.357695
49996199996708199910110.000.00.00.07515.0...0.2681010.1080950.0660390.0254680.025971-3.9138251.759524-2.075658-1.1548470.169073
4999719999766932004041249.010.01.01.022415.0...0.2694320.1057240.1176520.0574790.015669-4.6390650.6547131.137756-1.3905310.254420
49998199998969002002000827.010.00.01.033415.0...0.2611520.0004900.1373660.0862160.0513831.833504-2.8286872.465630-0.911682-2.057353
4999919999919338420041109166.061.0NaN1.0689.0...0.2287300.0003000.1035340.0806250.1242642.914571-1.1352700.5476282.094057-1.552150

10 rows × 30 columns

 

testB.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 50000 entries, 0 to 49999
Data columns (total 30 columns):
SaleID               50000 non-null int64
name                 50000 non-null int64
regDate              50000 non-null int64
model                50000 non-null float64
brand                50000 non-null int64
bodyType             48587 non-null float64
fuelType             47107 non-null float64
gearbox              48090 non-null float64
power                50000 non-null int64
kilometer            50000 non-null float64
notRepairedDamage    50000 non-null object
regionCode           50000 non-null int64
seller               50000 non-null int64
offerType            50000 non-null int64
creatDate            50000 non-null int64
v_0                  50000 non-null float64
v_1                  50000 non-null float64
v_2                  50000 non-null float64
v_3                  50000 non-null float64
v_4                  50000 non-null float64
v_5                  50000 non-null float64
v_6                  50000 non-null float64
v_7                  50000 non-null float64
v_8                  50000 non-null float64
v_9                  50000 non-null float64
v_10                 50000 non-null float64
v_11                 50000 non-null float64
v_12                 50000 non-null float64
v_13                 50000 non-null float64
v_14                 50000 non-null float64
dtypes: float64(20), int64(9), object(1)
memory usage: 11.4+ MB

总共数据 5万 条数据,数据完整,无null字段

基准模型

基准模型采用恒定猜测为mean值的方式。

先将训练集中price的mean值计算出来。

#拆分特征与标签,并将标签取对数处理
ho_xtrain = train.drop(['price'],axis=1 )
ho_ytrain = np.log1p(train.price)
 
pred_base = np.expm1(ho_ytrain).mean()
print ('基准模型预测值:'+str(pred_base))
基准模型预测值:5923.327333333334

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值