手机参数与价格关联性分析
01 | 数据来源
链接:
https://pan.baidu.com/s/1QEYV6MpubaDgDUKHBy49Zw 提取码: 7p8bkaggle:
https://www.kaggle.com/iabhishekofficial/mobile-price-classification
这是一个来自kagle上面的数据集。数据集收集了不同型号手机的具体参数以及价格区间。通过对数据集的分析,我们可以找出什么要素对价格影响最大,并利用模型对不同参数的手机进行分类。
import pandas as pd
df_train = pd.read_csv(r'D:\pycharm\data\mobile\train.csv')
print(df_train.columns)
'''
Index(['battery_power', 'blue', 'clock_speed', 'dual_sim', 'fc', 'four_g',
'int_memory', 'm_dep', 'mobile_wt', 'n_cores', 'pc', 'px_height',
'px_width', 'ram', 'sc_h', 'sc_w', 'talk_time', 'three_g',
'touch_screen', 'wifi', 'price_range'],
dtype='object')
'''
02 | 分析思路
1.准备工作
①设置display最大化,matplotlib与seaborn显示中文
pd.set_option('display.max_columns',1000)
pd.set_option('display.width',1000)
pd.set_option('display.max_colwidth',1000)
plt.rcParams['font.sans-serif'] = ['SimHei']
sns.set_style('whitegrid',{
'font.sans-serif':['simhei','Arial']})
②导入需要的库
- 常用的pandas、matplotlib、seaborn
- 导入词云库stylecloud,查看具体参数
- sklearn库,用来做分类
2.数据预处理
①pd.read_csv,查看head,info,describe,isnull等信息
df_train = pd.read_csv(r'D:\pycharm\data\mobile\train.csv')
df_test = pd.read_csv(r'D:\pycharm\data\mobile\test.csv')
print(df_train.head())
print(df_test.head())
print(df_train.info())
print(df_train.isna().sum())
②stylecloud可视化参数,先将columns转为list
df_index = df_train.columns.tolist()
print(df_index)
stylecloud.gen_stylecloud(file_path = r'D:\pycharm\data\mobile\df_index.txt', collocations=False,
font_path = r'C:\Windows\Fonts\SimHei.ttf',
icon_name='fas fa-cloud',size = 800, # fas fa-xx是图片形状