17.5.7 Training an Unsupervised EdgeWise Model
UnsupervisedEdgeWiseModel
on a graph as
shown:
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(100). // set the evaluation frequency (default: 1)
setEvaluationFrequencyScale(EvaluationFrequencyScale.STEP). // available options: EPOCH, STEP (default: EPOCH)
build()
opg4j> var model = analyst.unsupervisedEdgeWiseModelBuilder().
setVertexInputPropertyNames("vertex_features").
setEdgeInputPropertyNames("edge_features").
setValidationConfig(validationConfig). // configuring the validation to be executed every 100 steps
build()
import oracle.pgx.config.mllib.GraphWiseValidationConfig;
import oracle.pgx.config.mllib.EvaluationFrequencyScale;
GraphWiseValidationConfig validationConfig = analyst.graphWiseValidationConfigBuilder()
.setEvaluationFrequency(100) // set the evaluation frequency (default: 1)
.setEvaluationFrequencyScale(EvaluationFrequencyScale.STEP) // available options: EPOCH, STEP (default: EPOCH)
.build();
UnsupervisedEdgeWiseModel model = analyst.unsupervisedEdgeWiseModelBuilder()
.setVertexInputPropertyNames("vertex_features")
.setEdgeInputPropertyNames("edge_features")
.setValidationConfig(validationConfig) // configuring the validation to be executed every 100 steps
.build();
validation_config = analyst.graphwise_validation_config(
evaluation_frequency=100, # set the evaluation frequency (default: 1)
evaluation_frequency_scale="step", # available options: "epoch", "step" (default: "epoch")
)
params = dict(vertex_input_property_names=["vertex_features"],
edge_input_property_names=["edge_features"],
validation_config=validation_config, # configuring the validation to be executed every 100 steps
seed=17)
model = analyst.unsupervised_edgewise_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)
Parent topic: Using the Unsupervised EdgeWise Algorithm