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

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