Skip to content
Project: Customer Analytics: Preparing Data for Modeling
  • AI Chat
  • Code
  • Report
  • Spinner

    A common problem when creating models to generate business value from data is that the datasets can be so large that it can take days for the model to generate predictions. Ensuring that your dataset is stored as efficiently as possible is crucial for allowing these models to run on a more reasonable timescale without having to reduce the size of the dataset.

    You've been hired by a major online data science training provider called Training Data Ltd. to clean up one of their largest customer datasets. This dataset will eventually be used to predict whether their students are looking for a new job or not, information that they will then use to direct them to prospective recruiters.

    You've been given access to customer_train.csv, which is a subset of their entire customer dataset, so you can create a proof-of-concept of a much more efficient storage solution. The dataset contains anonymized student information, and whether they were looking for a new job or not during training:

    ColumnDescription
    student_idA unique ID for each student.
    cityA code for the city the student lives in.
    city_development_indexA scaled development index for the city.
    genderThe student's gender.
    relevant_experienceAn indicator of the student's work relevant experience.
    enrolled_universityThe type of university course enrolled in (if any).
    education_levelThe student's education level.
    major_disciplineThe educational discipline of the student.
    experienceThe student's total work experience (in years).
    company_sizeThe number of employees at the student's current employer.
    last_new_jobThe number of years between the student's current and previous jobs.
    training_hoursThe number of hours of training completed.
    job_changeAn indicator of whether the student is looking for a new job (1) or not (0).
    # Start your code here!
    import pandas as pd
    import numpy as np
    
    ds_jobs_clean = pd.read_csv('customer_train.csv')
    ds_jobs = pd.read_csv('customer_train.csv')

    First of all, let's explore what is the current status or our database

    ds_jobs_clean.info()

    floats data type

    ds_jobs_clean['city_development_index'] = ds_jobs_clean['city_development_index'].astype(np.float16)
    ds_jobs_clean['gender'] = ds_jobs_clean['gender'].astype('category')

    integer data type

    list_integer = ['job_change', 'training_hours', 'student_id']
    for i in list_integer:
        ds_jobs_clean[i] = ds_jobs_clean[i].astype(np.int32)
    list_categories = ['city', 'gender', 'relevant_experience', 'enrolled_university', 'education_level', 'major_discipline', 'company_type']
    for category in list_categories:
        ds_jobs_clean[category] = ds_jobs_clean[category].astype('category')

    Categorical

    categories_order = {'experience': ['1<']+list(map(str, range(1,21)))+['>20'],
                       'company_size': ['10<', '10-49', '50-99', '100-499', '500-999', '1000-4999', '5000-9999', '10000+'],
                       'education_level': ['Primary School', 'High School', 'Graduate', 'Masters', 'Phd'], 
                        'relevant_experience': ['No relevant experience', 'Has relevant experience'], 
                        'enrolled_university':['no_enrollment', 'Part time course', 'Full time course'],
                        'last_new_job': ['never']+ list(map(str, range(1,5))) +['>4']
                       }
    for cat in categories_order.keys():
        category = pd.CategoricalDtype(categories_order[cat], ordered = True)
        ds_jobs_clean[cat] = ds_jobs_clean[cat].astype(category)
    ds_jobs_clean.info()