application_vnd.jupyter.stderr_output_2.png text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pylab

import seaborn as sns

dataset = pd.read_csv('../input/census-data-set/Census Income Dataset.csv', na_values=[' ?'])

test_dataset = pd.read_csv('../input/census-test-dataset/Census Income Testset.csv', na_values=[' ?'])

def Income_bracket_binarization(feat_val):
    if feat_val == '<=50K':
        return 0
    else:
        return 1
dataset['Income_bracket'] = dataset['Income_bracket'].apply(Income_bracket_binarization)
test_dataset['Income_bracket'] = test_dataset['Income_bracket'].apply(Income_bracket_binarization)

def Plot():
    #Find Indices where Income is >50K and <=50K
    fig = plt.figure(figsize=(15,15))
    fig.subplots_adjust(hspace=0.7, wspace=0.7)
    pylab.suptitle("Analyzing the dataset", fontsize="xx-large")
    plt.subplot(3,2,1)
    ax = sns.countplot(x='Age', hue='Income_bracket', data=dataset)
    plt.subplot(3,2,2)
    ax =sns.countplot(x='workclass', hue='Income_bracket', data=dataset)
    ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
    plt.subplot(3,2,3)
    ax =sns.countplot(x='Education', hue='Income_bracket', data=dataset)
    ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
    plt.subplot(3,2,4)
    ax = sns.countplot(x='Occupation', hue='Income_bracket', data=dataset)
    ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
    plt.subplot(3,2,5)
    ax = sns.countplot(x='Gender', hue='Income_bracket', data=dataset)
    ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
    plt.subplot(3,2,6)
    ax = sns.countplot(x='hours_per_week', hue='Income_bracket', data=dataset)
    
    return None

dataset.hist(column=['Age', 'Education', 'hours_per_week'], figsize=(6, 5))
pylab.suptitle('Analyzing distribution for the dataset', fontsize='xx-large')
Plot()
X = dataset.drop('Income_bracket', axis=1)
y = dataset['Income_bracket']