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.

Default-Flamlized.md 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Default - Flamlized Estimator
  2. Flamlized estimators automatically use data-dependent default hyperparameter configurations for each estimator, offering a unique zero-shot AutoML capability, or "no tuning" AutoML.
  3. This example requires openml==0.10.2.
  4. ## Flamlized LGBMRegressor
  5. ### Zero-shot AutoML
  6. ```python
  7. from flaml.data import load_openml_dataset
  8. from flaml.default import LGBMRegressor
  9. from flaml.ml import sklearn_metric_loss_score
  10. X_train, X_test, y_train, y_test = load_openml_dataset(dataset_id=537, data_dir="./")
  11. lgbm = LGBMRegressor()
  12. lgbm.fit(X_train, y_train)
  13. y_pred = lgbm.predict(X_test)
  14. print("flamlized lgbm r2", "=", 1 - sklearn_metric_loss_score("r2", y_pred, y_test))
  15. print(lgbm)
  16. ```
  17. #### Sample output
  18. ```
  19. load dataset from ./openml_ds537.pkl
  20. Dataset name: houses
  21. X_train.shape: (15480, 8), y_train.shape: (15480,);
  22. X_test.shape: (5160, 8), y_test.shape: (5160,)
  23. flamlized lgbm r2 = 0.8537444671194614
  24. LGBMRegressor(colsample_bytree=0.7019911744574896,
  25. learning_rate=0.022635758411078528, max_bin=511,
  26. min_child_samples=2, n_estimators=4797, num_leaves=122,
  27. reg_alpha=0.004252223402511765, reg_lambda=0.11288241427227624,
  28. verbose=-1)
  29. ```
  30. ### Suggest hyperparameters without training
  31. ```
  32. from flaml.data import load_openml_dataset
  33. from flaml.default import LGBMRegressor
  34. from flaml.ml import sklearn_metric_loss_score
  35. X_train, X_test, y_train, y_test = load_openml_dataset(dataset_id=537, data_dir="./")
  36. lgbm = LGBMRegressor()
  37. hyperparams, estimator_name, X_transformed, y_transformed = lgbm.suggest_hyperparams(X_train, y_train)
  38. print(hyperparams)
  39. ```
  40. #### Sample output
  41. ```
  42. load dataset from ./openml_ds537.pkl
  43. Dataset name: houses
  44. X_train.shape: (15480, 8), y_train.shape: (15480,);
  45. X_test.shape: (5160, 8), y_test.shape: (5160,)
  46. {'n_estimators': 4797, 'num_leaves': 122, 'min_child_samples': 2, 'learning_rate': 0.022635758411078528, 'colsample_bytree': 0.7019911744574896, 'reg_alpha': 0.004252223402511765, 'reg_lambda': 0.11288241427227624, 'max_bin': 511, 'verbose': -1}
  47. ```
  48. [Link to notebook](https://github.com/microsoft/FLAML/blob/main/notebook/zeroshot_lightgbm.ipynb) | [Open in colab](https://colab.research.google.com/github/microsoft/FLAML/blob/main/notebook/zeroshot_lightgbm.ipynb)
  49. ## Flamlized XGBClassifier
  50. ### Zero-shot AutoML
  51. ```python
  52. from flaml.data import load_openml_dataset
  53. from flaml.default import XGBClassifier
  54. from flaml.ml import sklearn_metric_loss_score
  55. X_train, X_test, y_train, y_test = load_openml_dataset(dataset_id=1169, data_dir="./")
  56. xgb = XGBClassifier()
  57. xgb.fit(X_train, y_train)
  58. y_pred = xgb.predict(X_test)
  59. print("flamlized xgb accuracy", "=", 1 - sklearn_metric_loss_score("accuracy", y_pred, y_test))
  60. print(xgb)
  61. ```
  62. #### Sample output
  63. ```
  64. load dataset from ./openml_ds1169.pkl
  65. Dataset name: airlines
  66. X_train.shape: (404537, 7), y_train.shape: (404537,);
  67. X_test.shape: (134846, 7), y_test.shape: (134846,)
  68. flamlized xgb accuracy = 0.6729009388487608
  69. XGBClassifier(base_score=0.5, booster='gbtree',
  70. colsample_bylevel=0.4601573737792679, colsample_bynode=1,
  71. colsample_bytree=1.0, gamma=0, gpu_id=-1, grow_policy='lossguide',
  72. importance_type='gain', interaction_constraints='',
  73. learning_rate=0.04039771837785377, max_delta_step=0, max_depth=0,
  74. max_leaves=159, min_child_weight=0.3396294979905001, missing=nan,
  75. monotone_constraints='()', n_estimators=540, n_jobs=4,
  76. num_parallel_tree=1, random_state=0,
  77. reg_alpha=0.0012362430984376035, reg_lambda=3.093428791531145,
  78. scale_pos_weight=1, subsample=1.0, tree_method='hist',
  79. use_label_encoder=False, validate_parameters=1, verbosity=0)
  80. ```