当前位置: 首页> 教育> 培训 > 商务网站建设软件_东莞市天气_网站推广软件免费观看_上海百度推广客服电话

商务网站建设软件_东莞市天气_网站推广软件免费观看_上海百度推广客服电话

时间:2025/9/12 2:51:06来源:https://blog.csdn.net/m0_64336780/article/details/139162902 浏览次数:0次
商务网站建设软件_东莞市天气_网站推广软件免费观看_上海百度推广客服电话

 9a634410cc6b7f35886b50945fab99c7.gif

🤵‍♂️ 个人主页:@艾派森的个人主页

✍🏻作者简介:Python学习者
🐋 希望大家多多支持,我们一起进步!😄
如果文章对你有帮助的话,
欢迎评论 💬点赞👍🏻 收藏 📂加关注+


目录

1.项目背景

2.数据集介绍

3.技术工具

4.导入数据

5.数据预处理 

6.数据可视化

源代码


 

1.项目背景

        随着科技的飞速发展,笔记本电脑已经成为现代社会不可或缺的重要工具,其广泛应用于教育、商务、娱乐等多个领域。然而,随着市场的不断扩张和竞争的日益激烈,笔记本电脑的价格也变得日益复杂多变,这给消费者和商家都带来了不小的挑战。

        在这样的背景下,数据可视化分析显得尤为重要。数据可视化,作为一种强大的数据处理和展示工具,能够将海量的、复杂的数据转化为直观、易懂的图形和图像,帮助人们快速洞察数据的内在规律和趋势。对于笔记本电脑价格而言,数据可视化分析不仅能够帮助消费者更好地理解市场价格动态,做出更明智的购买决策,还能够为商家提供有力的市场分析和预测工具,指导其制定更有效的市场策略。

        具体来说,通过数据可视化分析,我们可以将笔记本电脑的价格数据以时间序列图、柱状图、散点图等多种形式展示出来。这些图形能够清晰地反映出笔记本电脑价格在不同时间段、不同品牌、不同配置之间的变化趋势和差异。例如,时间序列图可以帮助我们观察价格随时间的波动情况,柱状图可以比较不同品牌或配置之间的价格差异,散点图则可以揭示价格与其他因素(如性能、评价等)之间的潜在关系。

        此外,数据可视化分析还可以结合其他分析方法(如回归分析、聚类分析等)对笔记本电脑价格进行更深入的研究。例如,通过回归分析,我们可以探索价格与性能、品牌知名度等因素之间的定量关系;通过聚类分析,我们可以将不同品牌、配置的笔记本电脑按照价格水平进行分类,进一步揭示市场结构和竞争格局。

        总之,笔记本电脑价格的数据可视化分析是一个复杂而重要的研究领域。它不仅能够为消费者提供直观、易懂的市场信息,还能够为商家提供有力的市场分析和预测工具。随着数据科学和可视化技术的不断发展,我们有理由相信这一领域将在未来发挥更加重要的作用。

2.数据集介绍

        本实验数据集来源于Kaggle,原始数据集共有1303条数据,13个变量,各变量含义如下:

0 laptop_ID-数字-产品ID

1 Company-字符串-笔记本电脑制造商

2 Product-字符串-品牌和型号

3 TypeName-字符串-类型(笔记本电脑、超极本、游戏机等)

4 Inches-数字-屏幕尺寸

5 ScreenResolution-字符串-屏幕分辨率

6 Cpu-字符串-中央处理器 (CPU)

7 Ram-字符串-笔记本电脑 RAM

8 Memory-字符串-硬盘/SSD 内存

9 GPU-字符串-图形处理单元 (GPU)

10 OpSys-字符串-操作系统

11 Weight-字符串-笔记本电脑重量

12 Price_euros-数字-价格(欧元)

3.技术工具

Python版本:3.9

代码编辑器:jupyter notebook

4.导入数据

导入数据分析第三方库

f51640a1506d5884ea5adde1fe1d797e.png

导入数据集

173233f84f05b94563fc1d5dc8ea4081.png

查看数据大小

1e92a40137f46b691291613653f43a66.png

查看数据基本信息

65a3f543d6eabbd1752e3ed0c0159b9d.png

查看数值型变量的描述性统计

74b58d71d361b188dd03241a813084ca.png

查看非数值型变量的描述性统计

c9633a30dbeba7ee7070ec91fa0ca89a.png

5.数据预处理 

统计缺失值情况

205b1fbf24646c9c8a5d07c206e6cee8.png

发现没有缺失值

统计重复值情况

200467743648d4082276c5af306ba3bc.png

发现没有重复值

复制数据集并删除无关的变量

791ff8a6276221827cd6787399355c94.png

变量处理

861d2c1078a9fcffc08e341c30aae859.png

0b74f1a3e706eecf58b88a74deb876f4.png

三星的CPU是一个不必要的异常值,所以我们将删除它。

60ecf81a7f7be1f26abdb1c0ed676705.png

06697f58320693d4c694eff37f56b089.png

这里我们有4种不同类型的内存:SSD, HDD, Flash Storage和Hybrid。我们可以提取存储类型和内存。

37e92dd6ea0c1999ce2caa9d64f8bcaa.png

088719e5cc016f907f28f1504f6e97f1.png

6.数据可视化

da6dcd4d0d2afe1ed89dcf61208c3185.png

7e417adb86cc1e80475956dc2478f753.png

ff73637f5c34e05ea20a2eec9a01e2d2.png

213cbf1acf73830b1d53beb4d1f81795.png

ef7c7ead4de32691b855ffec81022848.png

c38ab4b6bd2a1d6e484ecc811a4464d1.png

89089882925d3ab475b04d082ea4eba5.png

aea53a5a5ae365d7f5ffac64e53ca129.png

d04c582d556aed4a50e725cbfa26ddfd.png

55ba4c583c7c7e654b19977832d13c3a.png

69efc35e71a36d9b1d77f06314352c5f.png

6286e8f69f8f9cd6a99e6283cbffe852.png

60374dfb35135217d1fc81e681b398b0.png

961c1ec9938ab012053dadaf99691fdf.png

9a53a437d6063963539a376450f143ea.png

9601ce33f5b2af7f88a2f0ecbcbddcaa.png

bd6ed3d86a7b56ab8b1003267f323e9e.png

7c77bc9d9d85e40c56814ae97843bf54.png

2aaf9b36558c2774b6db9e7d15c556f1.png

ac83088f6081415d2bc2b338223aeaa3.png

ba0ed3804ad714e1bc091b1873714bdf.png

5e74217bdeee4e6826391dc1062056ae.png

e2d79fda1551562c50d6f44313b7a433.png

源代码

1 Company-字符串-笔记本电脑制造商
2 Product-字符串-品牌和型号
3 TypeName-字符串-类型(笔记本电脑、超极本、游戏机等)
4 Inches-数字-屏幕尺寸
5 ScreenResolution-字符串-屏幕分辨率
6 Cpu-字符串-中央处理器 (CPU)
7 Ram-字符串-笔记本电脑 RAM
8 Memory-字符串-硬盘/SSD 内存
9 GPU-字符串-图形处理单元 (GPU)
10 OpSys-字符串-操作系统
11 Weight-字符串-笔记本电脑重量
12 Price_euros-数字-价格(欧元)
import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import optuna
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
import xgboost as xgb
from xgboost import XGBRegressor
from xgboost import plot_importance
import warnings
warnings.filterwarnings('ignore')laptop_price = pd.read_csv('laptop_price.csv', encoding='latin-1')
laptop_price.head()
laptop_price.shape
laptop_price.info()
laptop_price.describe()
laptop_price.describe(include='O')
laptop_price.isnull().sum()
laptop_price.duplicated().sum()
df = laptop_price
df = df.drop(['laptop_ID', 'Product'], axis=1)
# 仅从ScreenResolution列中提取分辨率
df['PPI'] = df['ScreenResolution'].str.extract(r'(\d+x\d+)')
# 创建宽度和高度来计算PPI
df[['Width', 'Height']] = df['PPI'].str.split('x', expand=True).astype('int')
# 计算PPI
df['PPI'] = (((df['Width']**2 + df['Height']**2)**0.5)/df['Inches']).round(2)
# 创建基于术语“触摸屏”的触摸屏专栏
df['Touchscreen'] = df['ScreenResolution'].str.contains('Touchscreen', case=False, regex=True).astype(int)
# 我们可以删除不需要的列
df = df.drop(['Height', 'Width', 'ScreenResolution'], axis=1)
# 提取Ghz数
df['Cpu_Ghz'] = df['Cpu'].str.extract(r'(\d+(\.\d+)?)GHz')[0].astype(float)
# 提取制造商名称 
df['Cpu_Manufacturer'] = df['Cpu'].str.split(' ').str[0]
df['Cpu_Manufacturer'].value_counts()
三星的CPU是一个不必要的异常值,所以我们将放弃它。
# 去除异常值并删除Cpu变量
df = df[df['Cpu_Manufacturer'] != 'Samsung']
df = df.drop(['Cpu'], axis=1)
# 从“Ram”列中提取数值
df['Ram'] = df['Ram'].str[:-2].astype(int)
df['Memory'].unique()
这里我们有4种不同类型的内存:SSD, HDD, Flash Storage和Hybrid。我们可以提取存储类型和内存。
df['Memory'] = df['Memory'].str.replace('1TB', '1024GB')
df['Memory'] = df['Memory'].str.replace('1.0TB', '1024GB')
df['Memory'] = df['Memory'].str.replace('2TB', '2048GB')
df['Memory'] = df['Memory'].str.replace('GB', '')
df['Memory'] = df['Memory'].str.replace('  ', '')df['Storage_1_Type'] = ''
df['Storage_1_Memory'] = 0
df['Storage_2_Type'] = ''
df['Storage_2_Memory'] = 0storage_types = ['SSD', 'HDD', 'Flash', 'Hybrid']# Storage_1
for storage_type in storage_types:condition = df['Memory'].str.contains(storage_type, case=False, regex=True)df.loc[condition & (df['Storage_1_Type'] == ''), 'Storage_1_Type'] = storage_typedf.loc[condition & (df['Storage_1_Memory'] == 0), 'Storage_1_Memory'] = df['Memory'].str.extract(f'(\d+) {storage_type}', expand=False).astype(float)df['Second_Storage'] = df['Memory'].str.extract(r'(\+\s?\d+\s?\w+)', expand=False).fillna('')
df['Has_Second_Storage'] = df['Second_Storage'].apply(lambda x: False if x == '' else True)# Storage_2
for storage_type in storage_types:condition = df['Second_Storage'].str.contains(storage_type, case=False, regex=True)df.loc[condition & (df['Storage_2_Type'] == ''), 'Storage_2_Type'] = storage_typedf.loc[condition & (df['Storage_2_Memory'] == 0), 'Storage_2_Memory'] = df['Second_Storage'].str.extract(f'(\d+) {storage_type}', expand=False).astype(float)# 删除不必要的列
df.drop(['Memory', 'Second_Storage', 'Has_Second_Storage'], axis=1, inplace=True)
# 提取制造商名称
df['Gpu_Manufacturer'] = df['Gpu'].str.split(' ').str[0]
df = df.drop(['Gpu'], axis=1)
# 提取出重量数字
df['Weight'] = df['Weight'].str[:-2].astype(float)
df.head()
# 按公司划分的产品数量
plt.figure(figsize=(8, 5))
sns.countplot(x='Company', data=df, order=df['Company'].value_counts().index, palette='crest')
plt.xticks(rotation=45, ha='right')
plt.title('Number of Products by Company', fontsize=10)
plt.xlabel('Company', fontsize=8)
plt.ylabel('Number of Products', fontsize=8)
plt.xticks(fontsize=8)
plt.yticks(fontsize=8)
plt.show()
# 按TypeName, Ram, OpSys划分的产品数量
columns_to_plot = ['TypeName', 'Ram', 'OpSys']plt.figure(figsize=(10, 4))for i, feature in enumerate(columns_to_plot):plt.subplot(1, 3, i + 1)sns.countplot(x=feature, data=df, order=df[feature].value_counts().index, palette='crest')plt.title(f'Number of Products by {feature}', fontsize=10)plt.xlabel(feature, fontsize=8)plt.ylabel('Number of Products', fontsize=8)if i == 0 or i == 2:plt.tick_params(rotation=45, axis='both', labelsize=8)else:plt.tick_params(axis='both', labelsize=8)plt.tight_layout()
plt.show()
# 重量分布
plt.figure(figsize=(8, 3))
sns.histplot(df['Weight'], color='navy', bins=8, alpha=0.6)
plt.title('Distribution of Weight')
plt.xlabel('Weight')
plt.ylabel('Frequency')
plt.show()
# CPU和GPU厂商
features = ['Cpu_Manufacturer', 'Gpu_Manufacturer']
plt.figure(figsize=(8, 3))for i, feature in enumerate(features, 1):plt.subplot(1, 2, i)sns.countplot(x=feature, data=df, order=df[feature].value_counts().index, palette='crest')plt.title(f'Count of Products by {feature}', fontsize=10)plt.xlabel('Number of Products', fontsize=8)plt.ylabel(feature, fontsize=8)plt.xticks(fontsize=8)plt.yticks(fontsize=8)
plt.tight_layout()
plt.show()
# 按内存类型划分的产品数量
features = ['Storage_1_Type', 'Storage_2_Type']
plt.figure(figsize=(8, 3))for i, feature in enumerate(features, 1):plt.subplot(1, 2, i)sns.countplot(x=feature, data=df, order=df[feature].value_counts().index, palette='crest')plt.title(f'Count of Products by {feature}', fontsize=10)plt.xlabel('Number of Products', fontsize=8)plt.ylabel(feature, fontsize=8)plt.xticks(fontsize=8)plt.yticks(fontsize=8)
plt.tight_layout()
plt.show()
# 存储内存,重量,PPI,英寸和价格的分布
features = ['Storage_1_Memory', 'Storage_2_Memory', 'Weight', 'PPI', 'Inches', 'Price_euros']plt.figure(figsize=(15, 10))for i, feature in enumerate(features, 1):plt.subplot(2, 3, i)sns.histplot(df[feature].dropna(), kde=True, color='navy', bins='auto', alpha=0.6)plt.title(f'Histogram of {feature}')plt.xlabel(feature)plt.ylabel('Frequency')plt.tight_layout()
plt.show()
# 各公司平均价格
plt.figure(figsize=(12, 6))
order_by_mean_price = df.groupby('Company')['Price_euros'].mean().sort_values(ascending=False).index
sns.barplot(x='Company', y='Price_euros', data=df, palette='crest', order=order_by_mean_price)
plt.title('Mean Price by Company')
plt.xlabel('Company')
plt.ylabel('Mean Price (euros)')
plt.xticks(rotation=45, ha='right')
plt.show()
# 价格与PPI、Ram和Cpu_Ghz的关系
columns_to_plot = ['PPI', 'Ram', 'Cpu_Ghz']plt.figure(figsize=(8, 3))for i, feature in enumerate(columns_to_plot):plt.subplot(1, 3, i + 1)sns.scatterplot(x=feature, data=df, y='Price_euros', color='navy', alpha=0.6)plt.title(f'{feature}', fontsize=10)plt.xlabel(feature, fontsize=8)if i == 0:plt.ylabel('Price euros', fontsize=8)else: plt.ylabel('')plt.tick_params(axis='both', labelsize=8)plt.tight_layout()
plt.show()
# 箱线图:Cpu_Manufacturer和Gpu_Manufacturer与价格
plt.figure(figsize=(8, 4))for i, feature in enumerate(['Cpu_Manufacturer', 'Gpu_Manufacturer']):plt.subplot(1, 2, i + 1)sns.boxplot(x=feature, y='Price_euros', data=df, palette='crest')plt.title(f'{feature} vs. Price', fontsize=10)plt.xlabel(feature, fontsize=8)if i == 0:plt.ylabel('Price euros', fontsize=8)else: plt.ylabel('')plt.tick_params(axis='both', labelsize=8)plt.tight_layout()
plt.show()
# 相关矩阵
numerical_columns = df.select_dtypes(include=['int', 'float']).columns
corr_matrix = df[numerical_columns].corr()
plt.figure(figsize=(12, 10))
sns.heatmap(corr_matrix, annot=True, cmap='crest', fmt=".2f", linewidths=.5)
plt.title('Correlation Matrix', fontsize=10)
plt.xticks(rotation=45, fontsize=8)
plt.yticks(fontsize=8)
plt.show()
import plotly.express as px
fig = px.sunburst(df, path=['Company','Ram','TypeName'], values='Price_euros',color='Price_euros')
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()

资料获取,更多粉丝福利,关注下方公众号获取

fbede7fa95ce75bb78ad56ed8d5979ce.gif#pic_center

 

关键字:商务网站建设软件_东莞市天气_网站推广软件免费观看_上海百度推广客服电话

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: