Beispiel #1
0
def save_model(model):
    try:
        if sys.argv[1] == 'save':
            save_data(model, MODEL_FILE_NAME)
        else:
            pass
    except IndexError:
        pass
Beispiel #2
0
def save_model(model, model_name):
    try:
        if sys.argv[1] == 'save':
            save_data(model, model_file_dict[model_name])
        else:
            pass
    except IndexError:
        pass
    except KeyError:
        print('Save error! Specified model name is invalid')
def save_model(model, model_name=None, file_path=None):
    if model_name is None and file_path is None:
        print('Please specify either model_name or file_path')
        print('file_path argument should have .pkl extension')
        print('Valid model_name arguments: ')
        print(list(model_file_dict.keys()))
        return

    try:
        if file_path is not None:  # if file_path specified, save to file_path if valid
            if file_path[-4:] != '.pkl':
                print('file_path argument should have .pkl extension')
            else:
                save_data(model, file_path)
                return
        save_data(model, model_file_dict[model_name])
    except KeyError:  # model_name alias specified not supported as per in model_file_dict
        print(
            'Error! Saving this model to file not supported by ai_cloud_model module'
        )
        print('Model aliases supported:')
        print(model_list)
def main():
    # Data Extraction
    df = data_extract_e('e_20190609_15.pkl')

    # Data Transformation and Engineering
    df = feature_eng(df)
    df = extract_queues(df)
    dept_encoder, queue_encoder = load_labels('dept_encoder.pkl',
                                              'queue_encoder.pkl',
                                              df=df)
    df = feature_transform(df,
                           dept_encoder=dept_encoder,
                           queue_encoder=queue_encoder)

    # Training/Test Split
    x, y = data_filter(df)
    x_train, x_test, y_train, y_test = train_test_split(
        x, y, test_size=0.2,
        random_state=1357)  # 2468 to use same shuffle as individual models

    # Load models from persistent files
    models = load_models()
    print(models)

    # Stacking
    # Produces a new set of features based on the predictions of base models
    x_train_s, x_test_s = stacking(models,
                                   x_train,
                                   y_train,
                                   x_test,
                                   n_folds=10,
                                   shuffle=True,
                                   verbose=0,
                                   regression=True)

    save_data(x_train_s, 'x_train_s.pkl')
    save_data(y_train, 'y_train.pkl')
    save_data(x_test_s, 'x_test_s.pkl')
    save_data(y_test, 'y_test.pkl')