赛题介绍:
https://tianchi.aliyun.com/competition/entrance/231784/information
评价标准为 MAE(Mean Absolute Error)。
MAE 越小,说明模型预测得越准确。
打卡汇总:
导包:
import pandas as pd
import numpy as np
import torch
# #numpy设置行列不限制数量
# np.set_printoptions(threshold=np.inf)
# #tensor设置行列不限制数量
# torch.set_printoptions(threshold=np.inf)
# # 设置行不限制数量
# pd.set_option('display.max_rows',None)
# # 设置列不限制数量
# pd.set_option('display.max_columns',None)
使用Pandas对比赛数据集进行分析:
train_df = pd.read_csv(r'used_car_train_20200313\used_car_train_20200313.csv',sep=' ')
test_df = pd.read_csv(r'used_car_testB_20200421\used_car_testB_20200421.csv',sep=' ')
In[3] : train_df.shape,test_df.shape
Out[3]: ((150000, 31), (50000, 30))
train_df
分析每个字段的取值、范围(unique)和类型(dtypes):
train_df['brand'].value_counts()
# brand 本质是类别型的
# lablel encoder之后的
train_df['brand'].unique()
train_df['brand'].nunique()
train_df.info()
train_df.dtypes
train_df.corr()
# 相关性有正负
train_df.corr()['price']
train_df.corr()['price'].abs().sort_values(ascending=False)
train_df['v_3'].describe()
import seaborn as sns
# 箱线图
sns.boxplot(train_df['v_3'])
# 整体的密度分布
sns.distplot(train_df['v_3'])
# v_3与price的变化,离散变量和离散变量之间的关系建议用散点图来看
sns.scatterplot(train_df['v_3'],train_df['price'])
# v_12与price的变化
sns.scatterplot(train_df['v_12'],train_df['price'])
# v_8与price的变化
sns.scatterplot(train_df['v_8'],train_df['price'])
train_df['regDate']
pd.to_datetime(train_df['regDate'].head(),format='%Y%m%d')
train_df['regDate1'] = train_df['regDate'].apply(lambda x: str(x)[:4])
train_df
# 看看年份和价格有无关系
train_df.groupby(['regDate1'])['price'].mean().plot()
# 看看price是什么分布
# 小经验:price一般都是非正态分布
sns.distplot(train_df['price'])
# 取对数转换成正态分布
import numpy as np
sns.distplot(np.log(train_df['price']))