Skip to main content

from_yaml()

Reconstruct a FittedRecipe from the YAML produced by to_yaml.

Usage

Source

from_yaml(
    text,
    *,
    trusted=(),
)

Takes the same trusted argument as from_dict and raises the same ValueError for a class outside the trusted packages. The YAML is parsed without building arbitrary objects, and the class names inside it are restricted by from_dict, as they are for JSON.

Parameters

text: str

The YAML text produced by to_yaml.

trusted: Iterable[type] = ()
Classes whose top-level packages the payload may also name classes from; see from_dict. Defaults to none.

Returns

FittedRecipe
The recipe, ready to FittedRecipe.transform new data.

Raises

ImportError
If the optional pyyaml package is not installed (pip install mlfeatures[yaml]).

Examples

recipe = Recipe().add(StepNormalize(s.numeric_features()))
fitted = recipe.fit(credit)
restored = from_yaml(to_yaml(fitted))
restored.transform(credit).head()
shape: (5, 14)
StatusSeniorityHomeTimeAgeMaritalRecordsJobExpensesIncomeAssetsDebtAmountPrice
strf64strf64f64strstrstrf64f64f64f64f64f64
"good"0.104473"rent"0.911743-0.630317"married""no""freelance"0.887353-0.157881-0.541693-0.313105-0.501373-0.997081
"good"1.086074"rent"0.9117431.909999"widow""no""fixed"-0.404875-0.133084-0.541693-0.313105-0.0657050.344189
"bad"0.227173"owner"-0.7385060.821292"married""yes""freelance"1.7660690.722397-0.220497-0.3131052.1126372.536142
"good"-0.999828"rent"0.911743-1.17467"single""no""fixed"0.3704620.499228-0.274029-0.313105-0.283539-0.205864
"good"-0.999828"rent"-0.738506-0.993219"single""no""fixed"-0.508253-0.430643-0.541693-0.313105-1.56876-0.891365