<jupyter_start><jupyter_text>KaggleUtils Examples<jupyter_code>%reload_ext autoreload
%autoreload 2
%matplotlib inline

import pandas as pd
from KaggleUtils import *
from scipy import stats
import numpy as np

train = pd.read_csv('data/train.csv')
test = pd.read_csv('data/test.csv')
print(train.shape)
train.head()
print(test.shape)
test.head()<jupyter_output>(418, 11)<jupyter_text>Basic Information When we want to get information about unique and missing values we can call `getStatsForDataFrame()`<jupyter_code>getStatsForDataframe(train)
getStatsForDataframe(test)<jupyter_output><empty_output><jupyter_text>Outliers We usually want to handle outliers manually but it can be a pain to look for them through a large dataset. `findPossibleOutliers()` goes through our numeric columns and looks for possible outliers based on `z_score`.<jupyter_code>findPossibleOutliers(train)
findPossibleOutliers(test)
df['SibSp'].hist()<jupyter_output><empty_output><jupyter_text>Plotting Categorical Data There are usually two things we need to know from our categories:1. Do they provide any signal? 2. Are the classes balanced?`plot_category_percent_of_target()` can show us whether or not our categories provide signal and how many of each is present in our training set.<jupyter_code>plot_category_percent_of_target(train, 'Embarked', 'Survived')<jupyter_output><empty_output><jupyter_text>Problematic Columns We consider a column problematic when it cannot help us improve our score on the test set. Some reasons for this: - All values in a column are the same - All values in a column as different<jupyter_code>findProblematicColumns(train)
train['Sex'] = train['Sex'].astype('category')
train['Cabin'] = train['Cabin'].astype('category')
train['Embarked'] = train['Embarked'].astype('category')
test['Sex'] = test['Sex'].astype('category')
test['Cabin'] = test['Cabin'].astype('category')
test['Embarked'] = test['Embarked'].astype('category')<jupyter_output><empty_output><jupyter_text>We also want to find columns that have categories that only exist in train or only exist in test.<jupyter_code>findProblematicCategories(train, test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10258780036968576, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 8.05857740585774, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '635956', 'license': 'MIT', 'n_tokens_mistral': 695, 'n_tokens_neox': 655, 'n_words': 201, 'path': 'Examples.ipynb', 'repo_name': 'JoshVarty/KaggleUtils', 'size': '2164'}