2022-03-19 12:27:30 +01:00
|
|
|
import pandas as pd
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import sklearn.model_selection
|
|
|
|
import numpy as np
|
2022-04-02 14:02:35 +02:00
|
|
|
#from kaggle.api.kaggle_api_extended import KaggleApi
|
2022-03-21 11:33:15 +01:00
|
|
|
import os
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# funkcja usuwająca wiersze zawierające platformę "Stadia"
|
|
|
|
def delete_stadia(games):
|
|
|
|
index_list = []
|
|
|
|
for i in range(0, len(games["platform"])):
|
|
|
|
try:
|
|
|
|
if games["platform"][i] == " Stadia":
|
|
|
|
index_list.append(i)
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
games.drop(index_list, inplace=True)
|
|
|
|
|
|
|
|
# funkcja usuwająca wiersze zawierające "tbd" w kolumnie "user_review"
|
|
|
|
def delete_tbd(games):
|
|
|
|
index_list = []
|
|
|
|
for i in range(0, len(games["platform"])):
|
|
|
|
try:
|
|
|
|
if games["user_review"][i] == "tbd":
|
|
|
|
index_list.append(i)
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
games.drop(index_list, inplace=True)
|
|
|
|
|
|
|
|
# funkcja zmieniająca kolumnę "user_review" ze stringa na numeric
|
|
|
|
def user_review_to_numeric(games):
|
|
|
|
games["user_review"] = pd.to_numeric(games["user_review"])
|
|
|
|
|
|
|
|
# funkcja normalizująca wartości w kolumnie "meta_score" i "user_review"
|
|
|
|
def normalization(games):
|
|
|
|
games['meta_score'] = games['meta_score'] / 100.0
|
|
|
|
games['user_review'] = games['user_review'] / 10.0
|
|
|
|
|
|
|
|
# funkcja przygotowująca dane metacritic
|
|
|
|
def preparation_meta_plot(games):
|
|
|
|
keys = games["meta_score"].value_counts().keys().sort_values()
|
|
|
|
values = []
|
|
|
|
for k in keys:
|
|
|
|
values.append(games["meta_score"].value_counts()[k])
|
|
|
|
return values
|
|
|
|
|
|
|
|
# funkcja przygotowująca dane użytkowników
|
|
|
|
def preparation_users_plot(games):
|
|
|
|
keys = games["user_review"].value_counts().keys().sort_values()
|
|
|
|
values = []
|
|
|
|
for k in keys:
|
|
|
|
values.append(games["user_review"].value_counts()[k])
|
|
|
|
return values
|
|
|
|
|
|
|
|
# funkcja tworząca wykres
|
|
|
|
def create_plot(games):
|
|
|
|
keys_meta = games["meta_score"].value_counts().keys().sort_values()
|
|
|
|
values_meta = preparation_meta_plot(games)
|
|
|
|
keys_user = games["user_review"].value_counts().keys().sort_values()
|
|
|
|
values_user = preparation_users_plot(games)
|
|
|
|
fig = plt.figure(figsize=(10, 5))
|
|
|
|
plt.plot(keys_meta, values_meta, color="maroon", label = "metacritic")
|
|
|
|
plt.plot(keys_user, values_user, color='blue', label = "użytkownicy")
|
|
|
|
plt.xlabel("Ocena")
|
|
|
|
plt.ylabel("Liczba ocen")
|
|
|
|
plt.title("Oceny metacritic i użytkowników")
|
|
|
|
plt.legend()
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
# funkcja dokonująca podziału na podzbiory train i test
|
2022-03-21 08:52:14 +01:00
|
|
|
def create_train_dev_test(games):
|
|
|
|
games_train, games_test = sklearn.model_selection.train_test_split(games, test_size=6972, random_state=1)
|
|
|
|
games_test, games_dev = sklearn.model_selection.train_test_split(games_test, test_size=3486, random_state=1)
|
|
|
|
#games_train, games_test = sklearn.model_selection.train_test_split(games, test_size=5810, random_state=1)
|
|
|
|
return games_train, games_dev, games_test
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# funkcja pobierająca informacje z danej platformy o ocenach metacritic
|
|
|
|
def get_platform_score_metacritic(games, platform):
|
|
|
|
meta_list = []
|
|
|
|
for i in range(0, len(games["platform"])):
|
|
|
|
try:
|
|
|
|
if games["platform"][i] == platform:
|
|
|
|
meta_list.append(games["meta_score"][i])
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
return meta_list
|
|
|
|
|
|
|
|
# funkcja pobierająca informacje z danej platformy o ocenach użytkowników
|
|
|
|
def get_platform_score_users(games, platform):
|
|
|
|
users_list = []
|
|
|
|
for i in range(0, len(games["platform"])):
|
|
|
|
try:
|
|
|
|
if games["platform"][i] == platform:
|
|
|
|
users_list.append(games["user_review"][i])
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
return users_list
|
|
|
|
|
|
|
|
# funkcja wypisująca informacje o danych powiązanych z daną platformą (wielkość zbioru, średnia, minimum,
|
|
|
|
# maksimum, odchylenie standardowe, mediana)
|
|
|
|
def platform_information(games, platform):
|
|
|
|
list = get_platform_score_metacritic(games, platform)
|
|
|
|
list_users = get_platform_score_users(games, platform)
|
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-02 14:04:38 +02:00
|
|
|
print("Wielkosd zbioru dla%s: %.0f" % (platform, len(list)))
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-02 14:04:38 +02:00
|
|
|
print("Srednia ocen metacritic dla%s: %.2f" % (platform, np.mean(list)))
|
2022-03-19 12:27:30 +01:00
|
|
|
print("Minimalna ocena metacritic dla%s: %.2f" % (platform, min(list)))
|
|
|
|
print("Maksymalna ocena metacritic dla%s: %.2f" % (platform, max(list)))
|
|
|
|
print("Odchylenie standardowe w ocenach metacritic dla%s: %.2f" % (platform, np.std(list)))
|
|
|
|
print("Mediana ocen metacritic dla%s: %.2f" % (platform, np.median(list)))
|
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-02 14:05:51 +02:00
|
|
|
print("Srednia ocen uzytkownikow dla%s: %.2f" % (platform, np.mean(list_users)))
|
|
|
|
print("Minimalna ocena uzytkownikow dla%s: %.2f" % (platform, min(list_users)))
|
|
|
|
print("Maksymalna ocena uzytkownikow dla%s: %.2f" % (platform, max(list_users)))
|
|
|
|
print("Odchylenie standardowe w ocenach uzytkownikow dla%s: %.2f" % (platform, np.std(list_users)))
|
|
|
|
print("Mediana ocen uzytkownikow dla%s: %.2f" % (platform, np.median(list_users)))
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# funkcja wypisująca informacje o danych (wielkość zbioru, średnia, minimum,
|
|
|
|
# maksimum, odchylenie standardowe, mediana, rozkład częstości przykładów)
|
|
|
|
def dataset_information(games):
|
2022-04-02 14:04:38 +02:00
|
|
|
print("Wielkosc zbioru: %.0f" % games["meta_score"].describe().loc[['count']][0])
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-02 14:04:38 +02:00
|
|
|
print("Srednia ocen metacritic: %.2f" % games["meta_score"].mean())
|
2022-03-19 12:27:30 +01:00
|
|
|
print("Minimalna ocena metacritic: %.2f" % games["meta_score"].describe().loc[['min']][0])
|
|
|
|
print("Maksymalna ocena metacritic: %.2f" % games["meta_score"].describe().loc[['max']][0])
|
|
|
|
print("Odchylenie standardowe w ocenach metacritic: %.2f" % games["meta_score"].describe().loc[['std']][0])
|
|
|
|
print("Mediana ocen metacritic: %.2f" % games["meta_score"].median())
|
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
2022-04-02 14:05:51 +02:00
|
|
|
print("Srednia ocen uzytkownikow: %.2f" % games["user_review"].mean())
|
|
|
|
print("Minimalna ocena uzytkownikow: %.2f" % games["user_review"].describe().loc[['min']][0])
|
|
|
|
print("Maksymalna ocena uzytkownikow: %.2f" % games["user_review"].describe().loc[['max']][0])
|
|
|
|
print("Odchylenie standardowe w ocenach uzytkownikow: %.2f" % games["user_review"].describe().loc[['std']][0])
|
|
|
|
print("Mediana ocen uzytkownikow: %.2f" % games["user_review"].median())
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# wykres
|
|
|
|
create_plot(games)
|
|
|
|
|
|
|
|
|
2022-03-21 11:33:15 +01:00
|
|
|
# pobranie dataset z kaggle
|
2022-04-02 13:58:54 +02:00
|
|
|
# os.system("kaggle datasets download -d deepcontractor/top-video-games-19952021-metacritic")
|
|
|
|
# os.system("unzip top-video-games-19952021-metacritic.zip")
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# wczytanie danych
|
2022-04-02 14:17:30 +02:00
|
|
|
games=pd.read_csv('all_games1.csv')
|
2022-03-19 12:27:30 +01:00
|
|
|
|
|
|
|
# usunięcie 5 wyników "Stadia"
|
|
|
|
delete_stadia(games)
|
|
|
|
|
|
|
|
# usunięcie wyników zawierających "tbd" w kolumnie "user_review"
|
|
|
|
delete_tbd(games)
|
|
|
|
|
|
|
|
# zmiana kolumny "user_review" na numeric
|
|
|
|
user_review_to_numeric(games)
|
|
|
|
|
|
|
|
# normalizacja kolumn "meta_score" i "user_review"
|
|
|
|
normalization(games)
|
|
|
|
|
|
|
|
# wypisanie informacji o danych
|
|
|
|
dataset_information(games)
|
|
|
|
|
|
|
|
# wypisanie informacji o danej platformie
|
2022-03-25 19:13:05 +01:00
|
|
|
platform_information(games, " PlayStation 4")
|
2022-03-19 12:27:30 +01:00
|
|
|
|
2022-03-21 08:52:14 +01:00
|
|
|
# podział na podzbiory train, dev i test (6,2,2)
|
|
|
|
#games_train, games_test = create_train_test(games)
|
|
|
|
games_train, games_dev, games_test = create_train_dev_test(games)
|