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
  • 52,940
  • 19
  • 125
  • 157
Shadow Walker
  • 750
  • 1
  • 15
  • 34

1 Answers1

0

You could try

pickel.dump(handle_null, open('handle_null.pkl', 'wb+'))
West
  • 1,882
  • 2
  • 17
  • 51