一、选题背景

随着科技的飞速发展,电子游戏产业已经成为全球范围内最具影响力和盈利能力的娱乐产业之一。在过去的几十年里,电子游戏市场规模不断扩大,游戏类型和玩法日益丰富多样,吸引了越来越多的玩家参与其中。而电子游戏销量数据反映了市场需求的变化趋势。通过对历史销量数据的挖掘和分析,可以发现不同类型、题材和风格的游戏在不同时间段的受欢迎程度,从而为游戏开发商提供有针对性的市场策略建议。此外,还可以预测未来一段时间内的游戏市场走势,为投资者提供有价值的参考信息。因此,对电子游戏销量数据的分析具有重要的现实意义和理论价值。

二、大数据分析设计方案

1.数据集来源:

  • 本次课程设计采用的数据集:电子游戏销量数据集
  • 数据集来源:爱数科,http://idatascience.cn/dataset-detail?table_id=431

2.数据集的数据内容:

3.实现思路:

  1. 导入数据集;
  2. 数据清洗;
  3. 数据可视化分析;

4.技术难点:

  1. 数据可视化分析:实现散点关系图、核密度图、Hexbin图等图,利用数据图进行数据可视化和信息分析;
  2. 构建预测模型。

数据分析步骤

1、数据清洗

导入数据集:

复制代码
1 import matplotlib.pyplot as plt
2 
3 import numpy as np
4 
5 import pandas as pd
6 
7 df=pd.read_csv('G:电子游戏销量数据集.csv')
8 
9 df.head()
复制代码

 

结果:

查找缺失值:

1 # 数据集信息
2 
3 df.info()

 

 

将处理后的数据集保存为新文件,方便使用:

1 df.to_csv('G:电子游戏销量数据集(数据已处理).csv', index=False)

导入处理后的数据集并查看:

1 # 导入已处理完的数据集
2 
3 df = pd.read_csv('G:电子游戏销量数据集(数据已处理).csv')
4 
5 print(df.shape) # 输出数据集的维度
6 
7 df.head()

统计数据的各个特征信息,包括样本数量、均值、最大值、最小值、四分位数:

1 data_summary = df.describe()
2 
3 display(data_summary)

2.数据可视化分析

1 # 各个字段的数据分布情况
2 
3 import matplotlib.pyplot as plt
4 
5 df.hist(bins = 20, figsize = (40, 30))
6 
7 plt.show()

结果:

热力图显示各字段的相关性:

1 plt.figure(figsize = (20,15))
2 
3 sns.heatmap(df.corr(), annot =True)
4 
5 plt.show()

结果:

1.

复制代码
 1 #全球销量同时间变化
 2 
 3 import pandas as pd
 4 
 5 import matplotlib.pyplot as plt
 6 
 7 import seaborn as sns
 8 
 9 # 数据准备
10 
11 df=pd.read_csv('G:电子游戏销量数据集.csv')
12 
13 x = df['Year']
14 
15 y = df['Global_Sales']
16 
17 # 使用Seaborn画折线图
18 
19 df = pd.DataFrame({'x': x, 'y': y})
20 
21 sns.lineplot(x="x", y="y", data=df)
22 
23 plt.show()
复制代码

结果:

结论:由全球销量折线图看出,数据是起伏不定的,在1995年后,逐渐趋于平缓,稳定在2以下

2.

复制代码
 1 #各游戏发行商占比
 2 
 3 from pylab import *
 4 
 5 mpl.rcParams['font.sans-serif'] = ['SimHei']
 6 
 7 mpl.rcParams['axes.unicode_minus'] = False
 8 
 9 df=pd.read_csv('G:电子游戏销量数据集.csv')
10 
11 df = (df['Publisher'].value_counts())[:16].to_frame()
12 
13 plt.figure(figsize=(15,15))
14 
15 plt.pie(df['Publisher'], labels=df.index.values, autopct='%.1f%%')
16 
17 plt.title('发行商占比',fontsize=20)
复制代码

结果:

结论:饼状图能更快在看出各发行商的占比,通过上图可得,在所有发行商中,占比最大的是Electronic Arts,达到了13.6%,占比最小的是Di sney Interactive Stud ios,仅仅只有2.2%。而lbisoft,Namco Bandai Games,Activision三者所占比相近。

3.

复制代码
 1 #游戏平台占比
 2 
 3 from pylab import *
 4 
 5 mpl.rcParams['font.sans-serif'] = ['SimHei']
 6 
 7 mpl.rcParams['axes.unicode_minus'] = False
 8 
 9 df=pd.read_csv('G:电子游戏销量数据集.csv')
10 
11 df = (df['Platform'].value_counts())[:16].to_frame()
12 
13 plt.figure(figsize=(15,15))
14 
15 plt.pie(df['Platform'], labels=df.index.values, autopct='%.1f%%')
16 
17 plt.title('游戏平台占比',fontsize=20)
复制代码

结果:

结论:通过游戏平台占比饼状图,我们可以看出占比最大的游戏平台是ps2和DS,占比都是13.8%,而最不受人欢迎的平台是snes,占比仅有1.5%

4.

复制代码
 1 #各游戏类型占比
 2 
 3 from pylab import *
 4 
 5 mpl.rcParams['font.sans-serif'] = ['SimHei']
 6 
 7 mpl.rcParams['axes.unicode_minus'] = False
 8 
 9 df=pd.read_csv('G:电子游戏销量数据集.csv')
10 
11 df = (df['Genre'].value_counts())[:16].to_frame()
12 
13 plt.figure(figsize=(15,15))
14 
15 plt.pie(df['Genre'], labels=df.index.values, autopct='%.1f%%')
16 
17 plt.title('游戏类型占比',fontsize=20)
复制代码

结果:

结论:由游戏类型占比饼状图可以看出,最受人欢迎的游戏类型是Action,达到了20%。比较受欢迎的是Sports类和Mi sc类游戏,最不受欢迎的是puzzle类游戏,只占了3.5%。

5.

复制代码
 1 # 绘制年份和销量的散点关系图
 2 
 3 lx = df['Year'].apply(lambda x:float(x))
 4 
 5 # print(home_area.head())
 6 
 7 xl = df['Global_Sales']
 8 
 9 # print(total_price.head())
10 
11 plt.scatter(lx,xl,s=3)
12 
13 plt.title('年份和销量关系',fontsize=15)
14 
15 plt.xlabel('年份',fontsize=15)
16 
17 plt.ylabel('全球销量',fontsize=15)
18 
19 plt.grid(linestyle=":", color="g")
20 
21 plt.show()
复制代码

结果:

结论:由年份与销量的散点关系图可以看出,从1980到2015年的销量呈现上下波动的现象 其中2010年的销量最多,2017年的销量最少

6.

复制代码
 1 #查看年份和销量的二元变量分布
 2 
 3 import matplotlib.pyplot as plt
 4 
 5 import seaborn as sns
 6 
 7 # 数据准备
 8 
 9 # tips = sns.load_dataset("tips")
10 
11 tips = pd.read_csv('G:电子游戏销量数据集.csv')
12 
13 print(tips.head(10))
14 
15 # 用Seaborn画二元变量分布图(散点图,核密度图,Hexbin图)
16 
17 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='scatter')
18 
19 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='kde')
20 
21 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='hex')
22 
23 plt.show()
复制代码

结果:

7.

复制代码
 1 #查看平台与销量之间的关系
 2 
 3 import pandas as pd
 4 
 5 import numpy as np
 6 
 7 import matplotlib.pyplot as plt
 8 
 9 import seaborn as sns
10 
11 df=pd.read_csv('G:电子游戏销量数据集.csv')
12 
13 fig,ax = plt.subplots()
14 
15 fig.set_size_inches(19,7)
16 
17 sns.boxplot(x=df['Platform'],y=df['Global_Sales'],data=df)
18 
19 plt.show()
复制代码

结果:

结论:由图可以看出,在wii平台和nes平台和ds平台上,游戏的销量是最好的,在ng,tg16和gg和pcfx平台上,游戏的销量最少

8.

复制代码
 1 #查看各平台下游戏数量
 2 
 3 fig,ax = plt.subplots()
 4 
 5 fig.set_size_inches(10,10)
 6 
 7 xq = df['Platform'].value_counts().sort_values()
 8 
 9 index = list(xq.index)
10 
11 value = list(xq.values)
12 
13 qx = pd.DataFrame({'Platform':index,'数量':value})
14 
15 qx.plot.barh(x='Platform',y='数量',ax=ax,color='blue',fontsize=12)
16 
17 plt.legend(loc='right')
18 
19 for a,b in zip(value,np.arange(0,14,1)):
20 
21 plt.text(a+0.5,b,a,fontsize=12)
22 
23 plt.show()
复制代码

结果:

结论:由图可以看出,ds,ps平台上游戏的下载量是最多,二者持平。pcfx,gg,tg16平台上游戏的下载数是最少的。

9.

复制代码
 1 #对各地区近年销量可视化处理
 2 
 3 #导入库
 4 
 5 import matplotlib.pyplot as plt
 6 
 7 plt.figure(figsize=(8,7))
 8 
 9 
10 
11 date = df.set_index('Year') #把日期列设为索引
12 
13 date.index = pd.to_datetime(date.index) #把索引转为时间格式
14 
15 plt.title('北美地区销量',fontsize=15)
16 
17 plt.xlabel('年份',fontsize=15)
18 
19 plt.ylabel('销量',fontsize=15)
20 
21 plt.bar(df.index, df['NA_Sales'])
复制代码

结果:

由图可以看出,随着时间的增长,北美地区的销量逐渐减少,最后逐渐趋于平缓

10.

复制代码
 1 date = df.set_index('Year')
 2 
 3 date.index = pd.to_datetime(date.index)
 4 
 5 plt.title('欧洲地区销量',fontsize=15)
 6 
 7 plt.xlabel('年份',fontsize=15)
 8 
 9 plt.ylabel('销量',fontsize=15)
10 
11 plt.bar(df.index, df['EU_Sales'])
复制代码

结果:

由图可以看出,随着时间的增长,欧洲地区的销量逐渐减少,最后逐渐趋于平缓

11.

复制代码
 1 date = df.set_index('Year')
 2 
 3 date.index = pd.to_datetime(date.index)
 4 
 5 plt.title('日本地区销量',fontsize=15)
 6 
 7 plt.xlabel('年份',fontsize=15)
 8 
 9 plt.ylabel('销量',fontsize=15)
10 
11 plt.bar(df.index, df['JP_Sales'])
复制代码

结果:

从图可以看出,日本地区最初的销量是最高的,但是随着时间的增长,销量逐渐减少。

12.

复制代码
 1 date = df.set_index('Year')
 2 
 3 date.index = pd.to_datetime(date.index)
 4 
 5 plt.title('其他地区销量',fontsize=15)
 6 
 7 plt.xlabel('年份',fontsize=15)
 8 
 9 plt.ylabel('销量',fontsize=15)
10 
11 plt.bar(df.index, df['Other_Sales'])
复制代码

结果:

由图可以看出,随着时间增加,销量逐渐减少,但是在1990年时候,达到最高值。

13.

复制代码
 1 date = df.set_index('Year')
 2 
 3 date.index = pd.to_datetime(date.index)
 4 
 5 plt.title('全球销量',fontsize=15)
 6 
 7 plt.xlabel('年份',fontsize=15)
 8 
 9 plt.ylabel('销量',fontsize=15)
10 
11 plt.bar(df.index, df['Global_Sales'])
复制代码

结果:

由图可以看出,全球地区的销量随着时间的增加而逐渐减少。

14.

复制代码
 1 #各地区销量之间关系
 2 
 3 import numpy as np
 4 
 5 import matplotlib.pyplot as plt
 6 
 7 from mpl_toolkits. mplot3d import Axes3D
 8 
 9 fig = plt.figure()
10 
11 ax = Axes3D(fig,auto_add_to_figure=False)
12 
13 fig.add_axes(ax)
14 
15 x = df['NA_Sales']
16 
17 y = df['EU_Sales']
18 
19 z = df['JP_Sales']
20 
21 ax. scatter(x, y, z)
22 
23 ax.set_xlabel('北美地区销量')
24 
25 ax.set_ylabel( '欧洲地区销量')
26 
27 ax.set_zlabel('日本地区销量')
28 
29 plt.show()
复制代码

结果:

15.

复制代码
 1 #探索电子游戏销量数据集中的多个成对双变量的分布
 2 
 3 import matplotlib.pyplot as plt
 4 
 5 import seaborn as sns
 6 
 7 # 数据准备
 8 
 9 # iris = sns.load_dataset('iris')
10 
11 iris =pd.read_csv('G:电子游戏销量数据集.csv')
12 
13 # 用Seaborn画成对关系
14 
15 sns.pairplot(iris)
16 
17 plt.show()
复制代码

结果:

16.预测模型

(1)划分训练集和测试集

1 # 划分训练集和测试集
2 
3 x_train, x_test, y_train, y_test = train_test_split(features, target, test_size=0.3, random_state=42)

(2)决策树:

复制代码
 1 from sklearn.model_selection import train_test_split
 2 
 3 from sklearn.tree import DecisionTreeClassifier
 4 
 5 from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
 6 
 7 # 特征选择
 8 
 9 features = df[['Name', 'Platform', 'Year', 'Genre', 'NA_Sales', 'EU_Sales', 'Publisher', 'JP_Sales', 'Other_Sales', 'Global_Sales']]
10 
11 # 目标变量
12 
13 target = df['Global_Sales']
14 
15 # 构建决策树模型
16 
17 model = DecisionTreeClassifier(random_state=42)
18 
19 model.fit(x_train, y_train)
20 
21 # 在测试集上进行预测
22 
23 y_pred = model.predict(x_test)
24 
25 # 评估模型性能
26 
27 accuracy = accuracy_score(y_test, y_pred)
28 
29 conf_matrix = confusion_matrix(y_test, y_pred)
30 
31 classification_rep = classification_report(y_test, y_pred)
32 
33 # 打印模型性能指标
34 
35 print(f'Accuracy: {accuracy:.2f}')
36 
37 print(f'Classification Report:\n{classification_rep}')
复制代码

结果:

(3)随机森林:

复制代码
 1 from sklearn.ensemble import RandomForestClassifier
 2 
 3 from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
 4 
 5 import matplotlib.pyplot as plt
 6 
 7 from sklearn import tree
 8 
 9 # 构建随机森林模型
10 
11 model_rf = RandomForestClassifier(n_estimators=100, random_state=42)
12 
13 model_rf.fit(x_train, y_train)
14 
15 # 在测试集上进行预测
16 
17 y_pred_rf = model_rf.predict(x_test)
18 
19 # 评估模型性能
20 
21 accuracy_rf = accuracy_score(y_test, y_pred_rf)
22 
23 conf_matrix_rf = confusion_matrix(y_test, y_pred_rf)
24 
25 classification_rep_rf = classification_report(y_test, y_pred_rf)
26 
27 # 打印模型性能指标
28 
29 print(f'Random Forest Accuracy: {accuracy_rf:.2f}')
30 
31 print(f'Random Forest Classification Report:\n{classification_rep_rf}')
复制代码

结果:

四.完整代码

 

复制代码
  1 import matplotlib.pyplot as plt
  2 
  3 import numpy as np
  4 
  5 import pandas as pd
  6 
  7 df=pd.read_csv('G:电子游戏销量数据集.csv')
  8 
  9 df.head()
 10 
 11 # 数据集信息
 12 
 13 df.info()
 14 
 15 df.to_csv('G:电子游戏销量数据集(数据已处理).csv', index=False)
 16 
 17 # 导入已处理完的数据集
 18 
 19 df = pd.read_csv('G:电子游戏销量数据集(数据已处理).csv')
 20 
 21 print(df.shape) # 输出数据集的维度
 22 
 23 df.head()
 24 
 25 data_summary = df.describe()
 26 
 27 display(data_summary)
 28 
 29 # 各个字段的数据分布情况
 30 
 31 import matplotlib.pyplot as plt
 32 
 33 df.hist(bins = 20, figsize = (40, 30))
 34 
 35 plt.show()
 36 
 37 plt.figure(figsize = (20,15))
 38 
 39 sns.heatmap(df.corr(), annot =True)
 40 
 41 plt.show()
 42 
 43 import pandas as pd
 44 
 45 import matplotlib.pyplot as plt
 46 
 47 import seaborn as sns
 48 
 49 # 数据准备
 50 
 51 df=pd.read_csv('G:电子游戏销量数据集.csv')
 52 
 53 x = df['Year']
 54 
 55 y = df['Global_Sales']
 56 
 57 # 使用Seaborn画折线图
 58 
 59 df = pd.DataFrame({'x': x, 'y': y})
 60 
 61 sns.lineplot(x="x", y="y", data=df)
 62 
 63 plt.show()
 64 
 65 from pylab import *
 66 
 67 mpl.rcParams['font.sans-serif'] = ['SimHei']
 68 
 69 mpl.rcParams['axes.unicode_minus'] = False
 70 
 71 df=pd.read_csv('G:电子游戏销量数据集.csv')
 72 
 73 df = (df['Publisher'].value_counts())[:16].to_frame()
 74 
 75 plt.figure(figsize=(15,15))
 76 
 77 plt.pie(df['Publisher'], labels=df.index.values, autopct='%.1f%%')
 78 
 79 plt.title('发行商占比',fontsize=20)
 80 
 81 from pylab import *
 82 
 83 mpl.rcParams['font.sans-serif'] = ['SimHei']
 84 
 85 mpl.rcParams['axes.unicode_minus'] = False
 86 
 87 df=pd.read_csv('G:电子游戏销量数据集.csv')
 88 
 89 df = (df['Platform'].value_counts())[:16].to_frame()
 90 
 91 plt.figure(figsize=(15,15))
 92 
 93 plt.pie(df['Platform'], labels=df.index.values, autopct='%.1f%%')
 94 
 95 plt.title('游戏平台占比',fontsize=20)
 96 
 97 from pylab import *
 98 
 99 mpl.rcParams['font.sans-serif'] = ['SimHei']
100 
101 mpl.rcParams['axes.unicode_minus'] = False
102 
103 df=pd.read_csv('G:电子游戏销量数据集.csv')
104 
105 df = (df['Genre'].value_counts())[:16].to_frame()
106 
107 plt.figure(figsize=(15,15))
108 
109 plt.pie(df['Genre'], labels=df.index.values, autopct='%.1f%%')
110 
111 plt.title('游戏类型占比',fontsize=20)
112 
113 # 绘制年份和销量的散点关系图
114 
115 lx = df['Year'].apply(lambda x:float(x))
116 
117 # print(home_area.head())
118 
119 xl = df['Global_Sales']
120 
121 # print(total_price.head())
122 
123 plt.scatter(lx,xl,s=3)
124 
125 plt.title('年份和销量关系',fontsize=15)
126 
127 plt.xlabel('年份',fontsize=15)
128 
129 plt.ylabel('全球销量',fontsize=15)
130 
131 plt.grid(linestyle=":", color="g")
132 
133 plt.show()
134 
135 #查看年份和销量的二元变量分布
136 
137 import matplotlib.pyplot as plt
138 
139 import seaborn as sns
140 
141 # 数据准备
142 
143 # tips = sns.load_dataset("tips")
144 
145 tips = pd.read_csv('G:电子游戏销量数据集.csv')
146 
147 print(tips.head(10))
148 
149 # 用Seaborn画二元变量分布图(散点图,核密度图,Hexbin图)
150 
151 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='scatter')
152 
153 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='kde')
154 
155 sns.jointplot(x="Year", y="Global_Sales", data=tips, kind='hex')
156 
157 plt.show()
158 
159 import pandas as pd
160 
161 import numpy as np
162 
163 import matplotlib.pyplot as plt
164 
165 import seaborn as sns
166 
167 df=pd.read_csv('G:电子游戏销量数据集.csv')
168 
169 fig,ax = plt.subplots()
170 
171 fig.set_size_inches(19,7)
172 
173 sns.boxplot(x=df['Platform'],y=df['Global_Sales'],data=df)
174 
175 plt.show()
176 
177 #查看各平台下游戏数量
178 
179 fig,ax = plt.subplots()
180 
181 fig.set_size_inches(10,10)
182 
183 xq = df['Platform'].value_counts().sort_values()
184 
185 index = list(xq.index)
186 
187 value = list(xq.values)
188 
189 qx = pd.DataFrame({'Platform':index,'数量':value})
190 
191 qx.plot.barh(x='Platform',y='数量',ax=ax,color='blue',fontsize=12)
192 
193 plt.legend(loc='right')
194 
195 for a,b in zip(value,np.arange(0,14,1)):
196 
197 plt.text(a+0.5,b,a,fontsize=12)
198 
199 plt.show()
200 
201 #对各地区近年销量可视化处理
202 
203 #导入库
204 
205 import matplotlib.pyplot as plt
206 
207 plt.figure(figsize=(8,7))
208 
209 
210 
211 date = df.set_index('Year') #把日期列设为索引
212 
213 date.index = pd.to_datetime(date.index) #把索引转为时间格式
214 
215 plt.title('北美地区销量',fontsize=15)
216 
217 plt.xlabel('年份',fontsize=15)
218 
219 plt.ylabel('销量',fontsize=15)
220 
221 plt.bar(df.index, df['NA_Sales'])
222 
223 date = df.set_index('Year')
224 
225 date.index = pd.to_datetime(date.index)
226 
227 plt.title('欧洲地区销量',fontsize=15)
228 
229 plt.xlabel('年份',fontsize=15)
230 
231 plt.ylabel('销量',fontsize=15)
232 
233 plt.bar(df.index, df['EU_Sales'])
234 
235 date = df.set_index('Year')
236 
237 date.index = pd.to_datetime(date.index)
238 
239 plt.title('日本地区销量',fontsize=15)
240 
241 plt.xlabel('年份',fontsize=15)
242 
243 plt.ylabel('销量',fontsize=15)
244 
245 plt.bar(df.index, df['JP_Sales'])
246 
247 date = df.set_index('Year')
248 
249 date.index = pd.to_datetime(date.index)
250 
251 plt.title('其他地区销量',fontsize=15)
252 
253 plt.xlabel('年份',fontsize=15)
254 
255 plt.ylabel('销量',fontsize=15)
256 
257 plt.bar(df.index, df['Other_Sales'])
258 
259 date = df.set_index('Year')
260 
261 date.index = pd.to_datetime(date.index)
262 
263 plt.title('全球销量',fontsize=15)
264 
265 plt.xlabel('年份',fontsize=15)
266 
267 plt.ylabel('销量',fontsize=15)
268 
269 plt.bar(df.index, df['Global_Sales'])
270 
271 #各地区销量之间关系
272 
273 import numpy as np
274 
275 import matplotlib.pyplot as plt
276 
277 from mpl_toolkits. mplot3d import Axes3D
278 
279 fig = plt.figure()
280 
281 ax = Axes3D(fig,auto_add_to_figure=False)
282 
283 fig.add_axes(ax)
284 
285 x = df['NA_Sales']
286 
287 y = df['EU_Sales']
288 
289 z = df['JP_Sales']
290 
291 ax. scatter(x, y, z)
292 
293 ax.set_xlabel('北美地区销量')
294 
295 ax.set_ylabel( '欧洲地区销量')
296 
297 ax.set_zlabel('日本地区销量')
298 
299 plt.show()
300 
301 import matplotlib.pyplot as plt
302 
303 import seaborn as sns
304 
305 # 数据准备
306 
307 # iris = sns.load_dataset('iris')
308 
309 iris =pd.read_csv('G:电子游戏销量数据集.csv')
310 
311 # 用Seaborn画成对关系
312 
313 sns.pairplot(iris)
314 
315 plt.show()
316 
317 from sklearn.model_selection import train_test_split
318 
319 from sklearn.tree import DecisionTreeClassifier
320 
321 from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
322 
323 # 划分训练集和测试集
324 
325 x_train, x_test, y_train, y_test = train_test_split(features, target, test_size=0.3, random_state=42)
326 
327 # 特征选择
328 
329 features = df[['Name', 'Platform', 'Year', 'Genre', 'NA_Sales', 'EU_Sales', 'Publisher', 'JP_Sales', 'Other_Sales', 'Global_Sales']]
330 
331 # 目标变量
332 
333 target = df['Global_Sales']
334 
335 # 构建决策树模型
336 
337 model = DecisionTreeClassifier(random_state=42)
338 
339 model.fit(x_train, y_train)
340 
341 # 在测试集上进行预测
342 
343 y_pred = model.predict(x_test)
344 
345 # 评估模型性能
346 
347 accuracy = accuracy_score(y_test, y_pred)
348 
349 conf_matrix = confusion_matrix(y_test, y_pred)
350 
351 classification_rep = classification_report(y_test, y_pred)
352 
353 # 打印模型性能指标
354 
355 print(f'Accuracy: {accuracy:.2f}')
356 
357 print(f'Classification Report:\n{classification_rep}')
358 
359 from sklearn.ensemble import RandomForestClassifier
360 
361 from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
362 
363 import matplotlib.pyplot as plt
364 
365 from sklearn import tree
366 
367 # 构建随机森林模型
368 
369 model_rf = RandomForestClassifier(n_estimators=100, random_state=42)
370 
371 model_rf.fit(x_train, y_train)
372 
373 # 在测试集上进行预测
374 
375 y_pred_rf = model_rf.predict(x_test)
376 
377 # 评估模型性能
378 
379 accuracy_rf = accuracy_score(y_test, y_pred_rf)
380 
381 conf_matrix_rf = confusion_matrix(y_test, y_pred_rf)
382 
383 classification_rep_rf = classification_report(y_test, y_pred_rf)
384 
385 # 打印模型性能指标
386 
387 print(f'Random Forest Accuracy: {accuracy_rf:.2f}')
388 
389 print(f'Random Forest Classification Report:\n{classification_rep_rf}')
复制代码

五.总结

通过对数据集的相关性统计分析,我发现游戏销量在不同游戏类型、发行年份、开发商和平台上存在显著差异。例如,动作类游戏的销量普遍高于角色扮演类游戏;近几年发行的游戏销量普遍高于早期发行的游戏;知名开发商的游戏销量普遍高于小型开发商;主机平台的游戏销量普遍高于PC平台。

为了找出影响游戏销量的关键因素,我们对数据集进行了相关性分析。结果显示,游戏类型、发行年份、开发商和平台之间存在一定的相关性。其中,游戏类型与销量的相关性最高,说明游戏类型对销量的影响最大;发行年份与销量的相关性次之,说明游戏的发行时间对销量也有一定的影响;开发商与销量的相关性较低,说明开发商的品牌效应对销量的影响有限;平台与销量的相关性最低,说明平台对销量的影响相对较小。

通过对电子游戏销量数据集的分析与挖掘,我得出了以下有益的结论:

1. 游戏类型对游戏销量的影响最大,因此在开发新游戏时,应充分考虑市场需求和玩家喜好,选择合适的游戏类型。

2. 游戏的发行时间对销量也有一定的影响,近年来发行的游戏销量普遍较高。因此,在制定市场策略时,应关注市场趋势和竞争态势,选择合适的发行时间。

3. 开发商的品牌效应对销量的影响有限,因此在提高游戏销量方面,应注重产品质量和创新,而非过分依赖品牌效应。

本次参加课程会让我学到了新的关于大数据分析的理论知识、实践技能,提高了我的能力和素质。同时,也让我收获了更多的自信和动力,激发了我进一步学习和成长的热情。