You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoML-Classification.md 3.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # AutoML - Classification
  2. ### A basic classification example
  3. ```python
  4. from flaml import AutoML
  5. from sklearn.datasets import load_iris
  6. # Initialize an AutoML instance
  7. automl = AutoML()
  8. # Specify automl goal and constraint
  9. automl_settings = {
  10. "time_budget": 1, # in seconds
  11. "metric": 'accuracy',
  12. "task": 'classification',
  13. "log_file_name": "iris.log",
  14. }
  15. X_train, y_train = load_iris(return_X_y=True)
  16. # Train with labeled input data
  17. automl.fit(X_train=X_train, y_train=y_train,
  18. **automl_settings)
  19. # Predict
  20. print(automl.predict_proba(X_train))
  21. # Print the best model
  22. print(automl.model.estimator)
  23. ```
  24. #### Sample of output
  25. ```
  26. [flaml.automl: 11-12 18:21:44] {1485} INFO - Data split method: stratified
  27. [flaml.automl: 11-12 18:21:44] {1489} INFO - Evaluation method: cv
  28. [flaml.automl: 11-12 18:21:44] {1540} INFO - Minimizing error metric: 1-accuracy
  29. [flaml.automl: 11-12 18:21:44] {1577} INFO - List of ML learners in AutoML Run: ['lgbm', 'rf', 'catboost', 'xgboost', 'extra_tree', 'lrl1']
  30. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 0, current learner lgbm
  31. [flaml.automl: 11-12 18:21:44] {1944} INFO - Estimated sufficient time budget=1285s. Estimated necessary time budget=23s.
  32. [flaml.automl: 11-12 18:21:44] {2029} INFO - at 0.2s, estimator lgbm's best error=0.0733, best estimator lgbm's best error=0.0733
  33. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 1, current learner lgbm
  34. [flaml.automl: 11-12 18:21:44] {2029} INFO - at 0.3s, estimator lgbm's best error=0.0733, best estimator lgbm's best error=0.0733
  35. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 2, current learner lgbm
  36. [flaml.automl: 11-12 18:21:44] {2029} INFO - at 0.4s, estimator lgbm's best error=0.0533, best estimator lgbm's best error=0.0533
  37. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 3, current learner lgbm
  38. [flaml.automl: 11-12 18:21:44] {2029} INFO - at 0.6s, estimator lgbm's best error=0.0533, best estimator lgbm's best error=0.0533
  39. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 4, current learner lgbm
  40. [flaml.automl: 11-12 18:21:44] {2029} INFO - at 0.6s, estimator lgbm's best error=0.0533, best estimator lgbm's best error=0.0533
  41. [flaml.automl: 11-12 18:21:44] {1826} INFO - iteration 5, current learner xgboost
  42. [flaml.automl: 11-12 18:21:45] {2029} INFO - at 0.9s, estimator xgboost's best error=0.0600, best estimator lgbm's best error=0.0533
  43. [flaml.automl: 11-12 18:21:45] {1826} INFO - iteration 6, current learner lgbm
  44. [flaml.automl: 11-12 18:21:45] {2029} INFO - at 1.0s, estimator lgbm's best error=0.0533, best estimator lgbm's best error=0.0533
  45. [flaml.automl: 11-12 18:21:45] {1826} INFO - iteration 7, current learner extra_tree
  46. [flaml.automl: 11-12 18:21:45] {2029} INFO - at 1.1s, estimator extra_tree's best error=0.0667, best estimator lgbm's best error=0.0533
  47. [flaml.automl: 11-12 18:21:45] {2242} INFO - retrain lgbm for 0.0s
  48. [flaml.automl: 11-12 18:21:45] {2247} INFO - retrained model: LGBMClassifier(learning_rate=0.2677050123105203, max_bin=127,
  49. min_child_samples=12, n_estimators=4, num_leaves=4,
  50. reg_alpha=0.001348364934537134, reg_lambda=1.4442580148221913,
  51. verbose=-1)
  52. [flaml.automl: 11-12 18:21:45] {1608} INFO - fit succeeded
  53. [flaml.automl: 11-12 18:21:45] {1610} INFO - Time taken to find the best model: 0.3756711483001709
  54. ```
  55. ### A more advanced example including custom learner and metric
  56. [Link to notebook](https://github.com/microsoft/FLAML/blob/main/notebook/automl_classification.ipynb) | [Open in colab](https://colab.research.google.com/github/microsoft/FLAML/blob/main/notebook/automl_classification.ipynb)