Skip to content

Commit ce6c4fd

Browse files
committed
streamlined vector value extractor
1 parent c80de8c commit ce6c4fd

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

common/core/src/test/java/zingg/common/core/executor/MatchThresholdBasedExecutorTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected void runUntilThreshold() {
3737
LOG.info("total number of matches discovered, " + matchCount);
3838
LOG.info("total number of non-matches discovered, " + notAMatchCount);
3939
} catch (Exception | ZinggClientException exception) {
40-
throw new ZinggException("Exception occurred while running threshold based runner, " + exception.getMessage());
40+
throw new ZinggException("Exception occurred while running threshold based runner, " + exception.getMessage(), exception);
4141
}
4242
}
4343

spark/core/src/main/java/zingg/spark/core/model/SparkMLPipeline.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,25 @@ public SparkMLPipeline(Map<FieldDefinition, Feature<DataType>> featurers, ModelC
5757
public void buildPipeline(Map<FieldDefinition, Feature<DataType>> featurers, ModelColumnHelper columnHelper) {
5858
pipelineStage = new ArrayList<>();
5959

60-
featureCreators = new SparkFeatureCreators(featurers, columnHelper);
60+
featureCreators = getFeatureCreators(featurers);
6161
pipelineStage.addAll(featureCreators.getTransformers());
6262

6363
pipelineStage.add(getAssembler());
6464
pipelineStage.add(getPolyExpansion());
6565
pipelineStage.add(getLR());
6666

67-
vve = new VectorValueExtractor(ColName.PROBABILITY_COL, ColName.SCORE_COL);
68-
columnHelper.getColumnsAdded().add(ColName.PROBABILITY_COL);
69-
columnHelper.getColumnsAdded().add(ColName.RAW_PREDICTION);
67+
//vve is not used in all cases, but since we dont have a different flow for prediction
68+
//creating it here so it gets registered
69+
vve = getVVE();
70+
71+
7072
}
7173

74+
protected SparkFeatureCreators getFeatureCreators(Map<FieldDefinition, Feature<DataType>> featurers){
75+
featureCreators = new SparkFeatureCreators(featurers, columnHelper);
76+
return featureCreators;
77+
}
78+
7279
protected VectorAssembler getAssembler() {
7380
VectorAssembler assembler = new VectorAssembler();
7481
assembler.setInputCols(columnHelper.getColumnsAdded().toArray(new String[0]))
@@ -123,11 +130,18 @@ public ZFrame<Dataset<Row>, Row, Column> fit(ZFrame<Dataset<Row>, Row, Column> i
123130
public ZFrame<Dataset<Row>, Row, Column> predict(ZFrame<Dataset<Row>, Row, Column> data) {
124131
LOG.info("threshold while predicting is " + lr.getThreshold());
125132
Dataset<Row> predictWithFeatures = transformer.transform(data.df());
126-
predictWithFeatures = vve.transform(predictWithFeatures);
133+
predictWithFeatures = getVVE().transform(predictWithFeatures);
127134
LOG.debug("Return schema is " + predictWithFeatures.schema());
128135
return new SparkFrame(predictWithFeatures);
129136
}
130137

138+
public VectorValueExtractor getVVE() {
139+
vve = new VectorValueExtractor(ColName.PROBABILITY_COL, ColName.SCORE_COL);
140+
columnHelper.getColumnsAdded().add(ColName.PROBABILITY_COL);
141+
columnHelper.getColumnsAdded().add(ColName.RAW_PREDICTION);
142+
return vve;
143+
}
144+
131145
public void register(SparkSession session) {
132146
featureCreators.register(session);
133147
vve.register(session);
@@ -141,7 +155,5 @@ public void save(String path) throws IOException {
141155
((CrossValidatorModel) transformer).write().overwrite().save(path);
142156
}
143157

144-
public List<SparkTransformer> getFeatureCreators() {
145-
return featureCreators.getTransformers();
146-
}
158+
147159
}

0 commit comments

Comments
 (0)