ium_444421/preparation.py

105 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# coding: utf-8
# In[ ]:
# get_ipython().system('kaggle datasets download -d tejashvi14/travel-insurance-prediction-data')
# In[ ]:
get_ipython().system('unzip -o travel-insurance-prediction-data.zip')
# In[5]:
import pandas as pd
travel_insurance=pd.read_csv('TravelInsurancePrediction.csv', index_col=0)
travel_insurance
# In[ ]:
# usunięcie wierszy zawierających braki
travel_insurance.dropna(axis='index', how='any')
# In[6]:
# normalizacja danych
for column in travel_insurance.columns:
if travel_insurance[column].dtype == 'object':
travel_insurance[column] = travel_insurance[column].str.lower()
travel_insurance
# In[8]:
# podział na podzbiory train/dev/test
import sklearn
from sklearn.model_selection import train_test_split
travel_insurance_train, travel_insurance_rest = sklearn.model_selection.train_test_split(travel_insurance, test_size=0.4, random_state=1)
travel_insurance_test, travel_insurance_dev = sklearn.model_selection.train_test_split(travel_insurance_rest, test_size=0.5, random_state=1)
# In[27]:
travel_insurance.describe(include='all')
# In[23]:
# zwracanie informacji o danym zbiorze
import seaborn as sns
def printInformation(data):
print(f'Size (rows): {len(data)}\n')
mean_value = data.mean()
min_value = data.min(numeric_only=True)
max_value = data.max(numeric_only=True)
std_value = data.std()
median_value = data.median()
print(f'(mean)\n{mean_value}', f'(min)\n{min_value}', f'(max)\n{max_value}', f'(std)\n{std_value}', f'(median)\n{median_value}', sep="\n\n")
sns.pairplot(data=data, hue="TravelInsurance")
# In[24]:
printInformation(travel_insurance)
# In[11]:
printInformation(travel_insurance_train)
# In[12]:
printInformation(travel_insurance_test)
# In[13]:
printInformation(travel_insurance_dev)
# In[ ]: