SHARE
TWEET

AutoML Sample Code

a guest Dec 7th, 2019 81 in 134 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from auto_ml import Predictor
  2. from auto_ml.utils import get_boston_dataset
  3. from auto_ml.utils_models import load_ml_model
  4.  
  5. # Load data
  6. df_train, df_test = get_boston_dataset()
  7.  
  8. # Tell auto_ml which column is 'output'
  9. # Also note columns that aren't purely numerical
  10. # Examples include ['nlp', 'date', 'categorical', 'ignore']
  11. column_descriptions = {
  12.   'MEDV': 'output'
  13.   , 'CHAS': 'categorical'
  14. }
  15.  
  16. ml_predictor = Predictor(type_of_estimator='regressor', column_descriptions=column_descriptions)
  17.  
  18. ml_predictor.train(df_train)
  19.  
  20. # Score the model on test data
  21. test_score = ml_predictor.score(df_test, df_test.MEDV)
  22.  
  23. # auto_ml is specifically tuned for running in production
  24. # It can get predictions on an individual row (passed in as a dictionary)
  25. # A single prediction like this takes ~1 millisecond
  26. # Here we will demonstrate saving the trained model, and loading it again
  27. file_name = ml_predictor.save()
  28.  
  29. trained_model = load_ml_model(file_name)
  30.  
  31. # .predict and .predict_proba take in either:
  32. # A pandas DataFrame
  33. # A list of dictionaries
  34. # A single dictionary (optimized for speed in production evironments)
  35. predictions = trained_model.predict(df_test)
  36. print(predictions)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top