create python scripts for stats and downloading dataset

This commit is contained in:
Sheaza 2024-04-02 18:31:57 +02:00
parent bec0f944b2
commit 76154a9157
2 changed files with 52 additions and 0 deletions

18
get_dataset.py Normal file
View File

@ -0,0 +1,18 @@
import opendatasets as od
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
od.download("https://www.kaggle.com/datasets/nikhil7280/student-performance-multiple-linear-regression/code")
data = pd.read_csv("student-performance-multiple-linear-regression/Student_Performance.csv")
print(data.head())
data.drop_duplicates(inplace=True)
data["Extracurricular Activities"] = data["Extracurricular Activities"].replace({'Yes': 1, 'No': 0})
data[data.columns[:-1]] = preprocessing.StandardScaler().fit_transform(data[data.columns[:-1]])
print(data.head())
df_train, df_test = train_test_split(data, test_size=0.2, random_state=21, shuffle=True)
data.to_csv("dataset.csv", index=False)
df_train.to_csv("df_train.csv", index=False)
df_test.to_csv("df_test.csv", index=False)

34
stats/get_stats.py Normal file
View File

@ -0,0 +1,34 @@
import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
df = pd.read_csv('./dataset.csv')
df_train = pd.read_csv('./df_train.csv')
df_test = pd.read_csv('./df_test.csv')
with open('stats.txt', 'w') as f:
f.write(f"Wielkość całego zbioru:\n {df.shape}\n")
f.write(f"Wielkość treningowego zbioru:\n {df_train.shape}\n")
f.write(f"Wielkość testowego zbioru:\n {df_test.shape}\n")
f.write(f"\nStatystyki dla całego zbioru:\n")
f.write(f"{df.describe()}\n")
f.write(f"\nStatystyki dla treningowego zbioru:\n")
f.write(f"{df_train.describe()}\n")
f.write(f"\nStatystyki dla testowego zbioru:\n")
f.write(f"{df_test.describe()}\n")
f.write(f"\nRozkład zmiennej wyjściowej dla całości:\n")
f.write(f"{df['Performance Index'].value_counts()}\n")
f.write(f"\nRozkład zmiennej wyjściowej dla zbioru treningowego:\n")
f.write(f"{df_train['Performance Index'].value_counts()}\n")
f.write(f"\nRozkład zmiennej wyjściowej dla zbioru testowego:\n")
f.write(f"{df_test['Performance Index'].value_counts()}\n")