-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6083e8d
commit 7140702
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Union | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from sklearn.exceptions import NotFittedError | ||
from sklearn.metrics import f1_score | ||
|
||
from experiment.runner import AutoMLRunner | ||
from flaml import AutoML | ||
|
||
|
||
class FLAMLExperimentRunner(AutoMLRunner): | ||
def fit(self, X_train: Union[np.ndarray, pd.DataFrame], y_train: Union[np.ndarray, pd.Series], target_label: str, | ||
dataset_name: str): | ||
flaml = AutoML() | ||
flaml.fit(X_train, y_train, task='classification', time_budget=-1, metric='f1') | ||
|
||
best_loss = flaml.best_loss | ||
best_model = flaml.best_estimator | ||
self._log_val_loss_alongside_model_class({best_model: best_loss}) | ||
|
||
self._fitted_model = flaml | ||
|
||
def predict(self, X_test: Union[np.ndarray, pd.DataFrame]) -> np.ndarray: | ||
if self._fitted_model is None: | ||
raise NotFittedError() | ||
|
||
predictions = self._fitted_model.predict(X_test) | ||
return predictions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters