forked from hxu/kaggle-loan-default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore.py
47 lines (38 loc) · 1.72 KB
/
explore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from __future__ import division
from sklearn.preprocessing import OneHotEncoder
import classes
from constants import *
import numpy as np
import pandas as pd
train_x, train_y = classes.get_train_data()
# Train x is of type
# <class 'pandas.core.frame.DataFrame'>
# Int64Index: 105471 entries, 1 to 105471
# Columns: 769 entries, f1 to f778
# dtypes: float64(652), int64(97), object(20)
# the int64s are probably good candidates for categorical variables
# The object data types turn out to be really long numbers. Maybe account numbers or something?
object_types_mask = train_x.dtypes == np.object
object_types = train_x.loc[:, object_types_mask]
object_types.iloc[0:5]
# Possible leakage via the object types numbers?
# Actually from the description we can see that some of these columns may be useful (the unique count is not very close to the total count)
desc = object_types.describe()
# IDEA - filter out columns where unique ~ count
# Find out how many unique ints there are in each int64 column
int_types_mask = train_x.dtypes == np.int64
int_types = train_x.loc[:, int_types_mask]
desc = int_types.describe()
uniques = [len(x.unique()) for n, x in int_types.iteritems()]
categorical = [x < 50 for x in uniques]
cat_columns = int_types.loc[:, categorical]
cat = cat_columns.iloc[:, 0:2]
one_hot = OneHotEncoder()
# Some columns have 0 standard deviation
# IDEA - filter out columns where SD ~ 0
# most
unique_ints = [len(x.unique()) for n, x in int_types.iteritems()]
# Looks like about half the rows have NAs in them. Can't drop rows, otherwise lose too many observations
# Are NAs possibly correlated with defaults?
# 431 columns have NANs, so can't drop columns either
# All the columns appear to be float columns -- can just interpolate maybe?