0

I have a function that handles any null values for my machine learning project. I would like to know of a way to save a function and reuse it same way I can save a trained machine learning algorithm using pickle and use it on my deployed app backend.

Function to save

def handle_nulls(df):
    df = df[df['account_status'].notna()]
    
    df = df[df['probability'].notna()]
    
    max = df['am_daysincelast_txn'].max()
    df['am_daysincelast_txn'].fillna(max, inplace=True)
    
    max = df['years_on_net'].max()
    df['years_on_net'].fillna(max, inplace=True)
    
    
    return df
    
df = handle_nulls(df)

My way pickel.dump(handle_null(), open('handle_null.pkl', 'wb')) doesn't work

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Shadow Walker
  • 979
  • 5
  • 27
  • 51
  • Maybe because it's `pickle` not `pickel`? – SiHa Dec 10 '20 at 12:53
  • Maybe because it's `handle_null()` not `handle_null`? – Konstantin Dec 10 '20 at 12:55
  • "X doesn't work" isn't really a description that allows us to see what's wrong. Do you get an error? If so please post a stacktrace. Is your output different from what you expected? Then please provide expected output vs. actual output. – Kraay89 Dec 10 '20 at 12:57
  • This answer might help https://stackoverflow.com/questions/4529815/saving-an-object-data-persistence – Salma Elshahawy Dec 10 '20 at 13:47

1 Answers1

0

You could try

pickel.dump(handle_null, open('handle_null.pkl', 'wb+'))
West
  • 2,350
  • 5
  • 31
  • 67