Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility Function for DataFrames #1

Open
mtanco opened this issue Jan 24, 2021 · 0 comments
Open

Utility Function for DataFrames #1

mtanco opened this issue Jan 24, 2021 · 0 comments
Labels
type/feature Feature request

Comments

@mtanco
Copy link

mtanco commented Jan 24, 2021

Maybe not Real Applications, but a lot of demos will use data frames, so a scoring function that takes a data frame and returns one would be nice. This is a rough draft which needs to be cleaned up, but putting hear as a place holder for the ModelOps Utiliies

def get_predictions(rows: pd.DataFrame):
    # handle nulls
    rows = rows.where(pd.notnull(rows), "")

   # every value needs to be a string
    vals = rows.values.tolist()
    for i in range(len(vals)):
        vals[i] = [str(x) for x in vals[i]]

    # create a string that is in the expected dictionary format
    dictionary = '{"fields": ' + str(df.columns.tolist()) + ', "rows": ' + str(vals) + '}'
    dictionary = dictionary.replace("'", '"'). #mlops needs double quotes!

   # use the utility function
    dict_preds = mlops_get_score('https://model.wave.h2o.ai/f2659e88-cbad-4ae0-baf0-e25daef42461/model/score',
                                 dictionary)

   # turn the returned dict into a dataframe
    preds = pd.DataFrame(data=dict_preds['score'], columns=dict_preds['fields'])

    # join with original data, assumption is the row order never changes
    return pd.concat([rows, preds], axis=1)
@mtanco mtanco added the type/feature Feature request label Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Feature request
Projects
None yet
Development

No branches or pull requests

1 participant