17.2.8 Training a Supervised GraphWise Model
You can train a Supervised GraphWise model on a graph as described in the following code:
opg4j> model.fit(trainGraph)
model.fit(trainGraph);
model.fit(train_graph)
You can also add a validation step to the training. When training a
model, the optimal number of training epochs is not known in advance and it is one
of the key parameters that determines the model quality. Being able to monitor the
training and validation losses helps you to identify a good value for the model
parameters and gain visibility in the training process. The evaluation frequency can
be specified in terms of epoch or step. To configure a validation step, create a
GraphWiseValidationConfig
and pass it to the model builder as
shown:
opg4j> import oracle.pgx.config.mllib.EvaluationFrequencyScale;
opg4j> var validationConfig = analyst.graphWiseValidationConfigBuilder().
setEvaluationFrequency(2). // set the evaluation frequency (default: 1)
setEvaluationFrequencyScale(EvaluationFrequencyScale.EPOCH). // available options: EPOCH, STEP (default: EPOCH)
build()
opg4j> var model = analyst.supervisedGraphWiseModelBuilder().
setVertexInputPropertyNames("features").
setVertexTargetPropertyName("labels").
setValidationConfig(validationConfig). // configuring the validation to be executed every 2 epochs
build()
import oracle.pgx.config.mllib.GraphWiseValidationConfig;
import oracle.pgx.config.mllib.EvaluationFrequencyScale;
GraphWiseValidationConfig validationConfig = analyst.graphWiseValidationConfigBuilder()
.setEvaluationFrequency(2) // set the evaluation frequency (default: 1)
.setEvaluationFrequencyScale(EvaluationFrequencyScale.EPOCH) // available options: EPOCH, STEP (default: EPOCH)
.build();
SupervisedGraphWiseModel model = analyst.supervisedGraphWiseModelBuilder()
.setVertexInputPropertyNames("features")
.setVertexTargetPropertyName("labels")
.setValidationConfig(validationConfig) // configuring the validation to be executed every 2 epochs
.build();
validation_config = analyst.graphwise_validation_config(
evaluation_frequency=2, # set the evaluation frequency (default: 1)
evaluation_frequency_scale="epoch", # available options: "epoch", "step" (default: "epoch")
)
params = dict(vertex_target_property_name="labels"
vertex_input_property_names=["features"],
validation_config=validation_config, # configuring the validation to be executed every 2 epochs
seed=17)
model = analyst.supervised_graphwise_builder(**params)
After configuring a validation step, you can then pass a graph for validation to the
fit
method together with the graph for training:
opg4j> model.fit(trainGraph, valGraph)
model.fit(trainGraph,valGraph);
model.fit(train_graph,valGraph)