|
26 | 26 | from autoPyTorch.api.tabular_classification import TabularClassificationTask |
27 | 27 | from autoPyTorch.datasets.resampling_strategy import CrossValTypes, HoldoutValTypes |
28 | 28 |
|
| 29 | +############################################################################ |
| 30 | +# Default Resampling Strategy |
| 31 | +# ============================ |
29 | 32 |
|
30 | 33 | ############################################################################ |
31 | 34 | # Data Loading |
32 | | -# ============ |
| 35 | +# ------------ |
33 | 36 | X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True) |
34 | 37 | X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split( |
35 | 38 | X, |
|
39 | 42 |
|
40 | 43 | ############################################################################ |
41 | 44 | # Build and fit a classifier with default resampling strategy |
42 | | -# =========================================================== |
| 45 | +# ----------------------------------------------------------- |
43 | 46 | api = TabularClassificationTask( |
44 | 47 | # 'HoldoutValTypes.holdout_validation' with 'val_share': 0.33 |
45 | 48 | # is the default argument setting for TabularClassificationTask. |
|
51 | 54 |
|
52 | 55 | ############################################################################ |
53 | 56 | # Search for an ensemble of machine learning algorithms |
54 | | -# ===================================================== |
| 57 | +# ----------------------------------------------------- |
55 | 58 | api.search( |
56 | 59 | X_train=X_train, |
57 | 60 | y_train=y_train, |
|
64 | 67 |
|
65 | 68 | ############################################################################ |
66 | 69 | # Print the final ensemble performance |
67 | | -# ==================================== |
68 | | -print(api.run_history, api.trajectory) |
| 70 | +# ------------------------------------ |
69 | 71 | y_pred = api.predict(X_test) |
70 | 72 | score = api.score(y_pred, y_test) |
71 | 73 | print(score) |
72 | 74 | # Print the final ensemble built by AutoPyTorch |
73 | 75 | print(api.show_models()) |
74 | 76 |
|
| 77 | +# Print statistics from search |
| 78 | +print(api.sprint_statistics()) |
| 79 | + |
75 | 80 | ############################################################################ |
76 | 81 |
|
| 82 | +############################################################################ |
| 83 | +# Cross validation Resampling Strategy |
| 84 | +# ===================================== |
| 85 | + |
77 | 86 | ############################################################################ |
78 | 87 | # Build and fit a classifier with Cross validation resampling strategy |
79 | | -# ==================================================================== |
| 88 | +# -------------------------------------------------------------------- |
80 | 89 | api = TabularClassificationTask( |
81 | 90 | resampling_strategy=CrossValTypes.k_fold_cross_validation, |
82 | 91 | resampling_strategy_args={'num_splits': 3} |
83 | 92 | ) |
84 | 93 |
|
85 | 94 | ############################################################################ |
86 | 95 | # Search for an ensemble of machine learning algorithms |
87 | | -# ===================================================== |
| 96 | +# ----------------------------------------------------------------------- |
| 97 | + |
88 | 98 | api.search( |
89 | 99 | X_train=X_train, |
90 | 100 | y_train=y_train, |
|
97 | 107 |
|
98 | 108 | ############################################################################ |
99 | 109 | # Print the final ensemble performance |
100 | | -# ==================================== |
101 | | -print(api.run_history, api.trajectory) |
| 110 | +# ------------ |
102 | 111 | y_pred = api.predict(X_test) |
103 | 112 | score = api.score(y_pred, y_test) |
104 | 113 | print(score) |
105 | 114 | # Print the final ensemble built by AutoPyTorch |
106 | 115 | print(api.show_models()) |
107 | 116 |
|
| 117 | +# Print statistics from search |
| 118 | +print(api.sprint_statistics()) |
| 119 | + |
108 | 120 | ############################################################################ |
109 | 121 |
|
| 122 | +############################################################################ |
| 123 | +# Stratified Resampling Strategy |
| 124 | +# =============================== |
| 125 | + |
110 | 126 | ############################################################################ |
111 | 127 | # Build and fit a classifier with Stratified resampling strategy |
112 | | -# ============================================================== |
| 128 | +# -------------------------------------------------------------- |
113 | 129 | api = TabularClassificationTask( |
114 | 130 | # For demonstration purposes, we use |
115 | 131 | # Stratified hold out validation. However, |
|
120 | 136 |
|
121 | 137 | ############################################################################ |
122 | 138 | # Search for an ensemble of machine learning algorithms |
123 | | -# ===================================================== |
| 139 | +# ----------------------------------------------------- |
124 | 140 | api.search( |
125 | 141 | X_train=X_train, |
126 | 142 | y_train=y_train, |
|
134 | 150 | ############################################################################ |
135 | 151 | # Print the final ensemble performance |
136 | 152 | # ==================================== |
137 | | -print(api.run_history, api.trajectory) |
138 | 153 | y_pred = api.predict(X_test) |
139 | 154 | score = api.score(y_pred, y_test) |
140 | 155 | print(score) |
141 | 156 | # Print the final ensemble built by AutoPyTorch |
142 | 157 | print(api.show_models()) |
| 158 | + |
| 159 | +# Print statistics from search |
| 160 | +print(api.sprint_statistics()) |
0 commit comments