Skip to main content

ML - MLModelBuilder

ML.MLModelBuilder

A builder to define (and optionally train) a machine learning model.

Example

  // use a DictType stream
const training_stream = Stream(
"My Stream",
DictType(
StringType,
StructType({
x: FloatType,
y: FloatType,
})
)
);

// create a gradient boosted tree
const ml_model = new MLModelBuilder("ML Training")
.feature("x", FloatType)
.output(FloatType)
.model({ type: "boosted_trees", noise: "none" })
.trainFromStream({
output_name: "y",
input: training_stream,
});

Type parameters

NameType
Nameextends string
Featuresextends Record =

ML

constructor

new MLModelBuilder(name, module?):

MLModelBuilder

Construct a new ML model with a given name

Type parameters

NameType
Nameextends string
Featuresextends Record =

Parameters

NameType
nameName
module?ModulePath | ModuleBuilder

Returns

MLModelBuilder

Example

  // use a DictType stream
const training_stream = Stream(
"My Stream",
DictType(
StringType,
StructType({
x: FloatType,
y: FloatType,
})
)
);

// create a gradient boosted tree
const ml_model = new MLModelBuilder("ML Training")
.feature("x", FloatType)
.output(FloatType)
.model({ type: "boosted_trees", noise: "none" })
.trainFromStream({
output_name: "y",
input: training_stream,
});

feature

feature(name, type):

MLModelBuilder<Name, Features & { [K in string]: T }>

Define an input feature for the model.

Type parameters

NameType
FeatureNameextends string
Textends EastType

Parameters

NameTypeDescription
nameFeatureNamethe name of the feature
typeTthe EastType of the feature

Returns

MLModelBuilder<Name, Features & { [K in string]: T }>

Example

  // create a gradient boosted tree
const ml_model = new MLModelBuilder("ML Training")
.feature("x", FloatType)
.output(FloatType)

output

output(type): T extends

FloatType ? FloatMLBuilder<Name, Features, { noise: "gaussian" ; type: "gaussian_process" }> : StringMLBuilder<Name, Features, { noise: "weighted" ; type: "boosted_trees_string" }>

Define the EastType the model will predict.

Type parameters

NameType
Textends FloatType | StringType

Parameters

NameTypeDescription
typeTthe EastType of the output

Returns

T extends

FloatType ? FloatMLBuilder<Name, Features, { noise: "gaussian" ; type: "gaussian_process" }> : StringMLBuilder<Name, Features, { noise: "weighted" ; type: "boosted_trees_string" }>

Example

  // create a gradient boosted tree
const ml_model = new MLModelBuilder("ML Training")
.output(FloatType)