src/features/build_features.py
def main(train_path, test_path,
         output_dir):
    """Build features
    TODO- Currently a placeholder script that saves existing files until feature engineering is implemented"""

    output_dir = Path(output_dir).resolve()
    assert (os.path.isdir(output_dir)), NotADirectoryError

    # load train and test data because feature engineering process should be identical
    train_df, test_df = load_data([train_path, test_path],
                                  sep=",", header=0,
                                  index_col="PassengerId")

    params = load_params()
    target_class = params["train_test_split"]["target_class"]

    # pop the target class
    train_labels = train_df.pop(target_class)

    # concatenate df
    df = pd.concat([train_df, test_df], sort=False)

    # load params
    params = load_params()
    params_featurize = params["feature_eng"]
    params_featurize["random_seed"] = params["random_seed"]

    # optionally normalize data
    if params_featurize["featurize"]:
        # create poly features
        df = create_poly_features(df, degree=2,
                                  interaction_only=True)

        # hand-crafted features
        df = hand_crafted_features(df)

        # bin continuous features
        df['Age'] = pd.qcut(df['Age'], 10,
                            duplicates="drop").astype('category').cat.codes
        df['Fare'] = pd.qcut(df['Fare'], 13).astype('category').cat.codes
        df['family_size'] = pd.qcut(df['family_size'], 3,
                                    duplicates="drop").astype('category').cat.codes

    # return datasets to train and test
    train_df = df.loc[train_df.index, df.columns]
    train_df.insert(loc=0, column=target_class,
                    value=train_labels)
    test_df = df.loc[test_df.index, df.columns]

    # save data
    save_as_csv([train_df, test_df],
                [train_path, test_path],
                output_dir,
                replace_text="_nan_imputed.csv",
                suffix="_featurized.csv",
                na_rep="nan")
Build features
    TODO- Currently a placeholder script that saves existing files until feature engineering is implemented
Build features
TODO- Currently a placeholder script that saves existing files until feature engineering is implemented
Build features TODO - Currently a placeholder script that saves existing files until feature engineering is implemented
def main(train_path, test_path,
         output_dir):
    output_dir = Path(output_dir).resolve()
    assert (os.path.isdir(output_dir)), NotADirectoryError
    train_df, test_df = load_data([train_path, test_path],
                                  sep=",", header=0,
                                  index_col="PassengerId")
    params = load_params()
    target_class = params["train_test_split"]["target_class"]
    train_labels = train_df.pop(target_class)
    df = pd.concat([train_df, test_df], sort=False)
    params = load_params()
    params_featurize = params["feature_eng"]
    params_featurize["random_seed"] = params["random_seed"]
    if params_featurize["featurize"]:
        df = create_poly_features(df, degree=2,
                                  interaction_only=True)
        df = hand_crafted_features(df)
        df['Age'] = pd.qcut(df['Age'], 10,
                            duplicates="drop").astype('category').cat.codes
        df['Fare'] = pd.qcut(df['Fare'], 13).astype('category').cat.codes
        df['family_size'] = pd.qcut(df['family_size'], 3,
                                    duplicates="drop").astype('category').cat.codes
    train_df = df.loc[train_df.index, df.columns]
    train_df.insert(loc=0, column=target_class,
                    value=train_labels)
    test_df = df.loc[test_df.index, df.columns]
    save_as_csv([train_df, test_df],
                [train_path, test_path],
                output_dir,
                replace_text="_nan_imputed.csv",
                suffix="_featurized.csv",
                na_rep="nan")
def main ( train_path , test_path , output_dir ) : output_dir = Path ( output_dir ) . resolve ( ) assert ( os . path . isdir ( output_dir ) ) , NotADirectoryError train_df , test_df = load_data ( [ train_path , test_path ] , sep = "," , header = 0 , index_col = "PassengerId" ) params = load_params ( ) target_class = params [ "train_test_split" ] [ "target_class" ] train_labels = train_df . pop ( target_class ) df = pd . concat ( [ train_df , test_df ] , sort = False ) params = load_params ( ) params_featurize = params [ "feature_eng" ] params_featurize [ "random_seed" ] = params [ "random_seed" ] if params_featurize [ "featurize" ] : df = create_poly_features ( df , degree = 2 , interaction_only = True ) df = hand_crafted_features ( df ) df [ 'Age' ] = pd . qcut ( df [ 'Age' ] , 10 , duplicates = "drop" ) . astype ( 'category' ) . cat . codes df [ 'Fare' ] = pd . qcut ( df [ 'Fare' ] , 13 ) . astype ( 'category' ) . cat . codes df [ 'family_size' ] = pd . qcut ( df [ 'family_size' ] , 3 , duplicates = "drop" ) . astype ( 'category' ) . cat . codes train_df = df . loc [ train_df . index , df . columns ] train_df . insert ( loc = 0 , column = target_class , value = train_labels ) test_df = df . loc [ test_df . index , df . columns ] save_as_csv ( [ train_df , test_df ] , [ train_path , test_path ] , output_dir , replace_text = "_nan_imputed.csv" , suffix = "_featurized.csv" , na_rep = "nan" )
Build features
TODO- Currently a placeholder script that saves existing files until feature engineering is implemented
Build features TODO - Currently a placeholder script that saves existing files until feature engineering is implemented
"""Build features
    TODO- Currently a placeholder script that saves existing files until feature engineering is implemented""" # load train and test data because feature engineering process should be identical # pop the target class # concatenate df # load params # optionally normalize data # create poly features # hand-crafted features # bin continuous features # return datasets to train and test # save data
train_path
test_path
output_dir