Exemple #1
0
def automl_predict(
        input: Path,
        output: Path = Path("output.csv"),
        model: Path = Path("automl.bin"),
        ignore_cols: List[int] = typer.Option([]),
        format: str = None,
):
    """
    🔮 Predict with a previously trained AutoML instance.
    """

    try:
        dataset = _load_dataset(format, input, ignore_cols)
    except ValueError as e:
        logger.error(f"⚠️  Error: {str(e)}")
        return

    try:
        with model.open("rb") as fp:
            automl = AutoML.load(fp)
    except TypeError as e:
        logger.error(f"⚠️  Error: {str(e)}")
        return

    console.print(f"🔮 Predicting {len(dataset)} items with the pipeline:")
    console.print(repr(automl.best_pipeline_))

    X = dataset.values
    y = automl.predict(X)

    with output.open("wt") as fp:
        df = pd.DataFrame(y, columns=["y"])
        df.to_csv(fp)

    console.print(f"💾 Predictions saved to [blue]{output.absolute()}[/]")
Exemple #2
0
def automl_inspect(model: Path = Path("automl.bin")):
    """
    🔍 Inspect a trained AutoML model.
    """

    with model.open("rb") as fp:
        automl = AutoML.load(fp)

    console.print(f"🔍 Inspecting AutoML model: [green]{model.absolute()}[/]")

    console.print(f"⭐ Best pipeline (score={automl.best_score_:0.3f}):")
    console.print(repr(automl.best_pipeline_))
Exemple #3
0
def test_automl_save_load():
    X, y = dummy.generate(seed=0)
    automl = AutoML(search_iterations=3, registry=[DummyAlgorithm])
    automl.fit(X, y)
    pipe = automl.best_pipeline_

    fp = BytesIO()

    automl.save(fp)
    fp.seek(0)

    automl2 = AutoML.load(fp)
    pipe2 = automl2.best_pipeline_

    assert repr(pipe) == repr(pipe2)
Exemple #4
0
def test_automl_save_load():
    X, y = dummy.generate(seed=0)
    automl = AutoML(
        input=(MatrixContinuousDense, Supervised[VectorCategorical]),
        output=VectorCategorical,
        search_iterations=3,
        registry=[DummyAlgorithm],
    )

    automl.fit(X, y)
    pipe = automl.best_pipeline_

    fp = BytesIO()

    automl.save(fp)
    fp.seek(0)

    automl2 = AutoML.load(fp)
    pipe2 = automl2.best_pipeline_

    assert repr(pipe) == repr(pipe2)