Skip to content

Commit

Permalink
Refactored attribute accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Apr 23, 2024
1 parent 79c3ac1 commit cc11856
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ private Learner loadLearner(ByteOrder byteOrder, String charset){
}

public Integer getBestNTreeLimit(){

if(!hasattr("best_ntree_limit")){
return null;
}

return getInteger("best_ntree_limit");
return getOptionalInteger("best_ntree_limit");
}

public byte[] getHandle(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface HasMetric {

String getMetric();

int getP();
Integer getP();
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public String getMetric(){
}

@Override
public int getP(){
public Integer getP(){
return getInteger("p");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String getMetric(){
}

@Override
public int getP(){
public Integer getP(){
return getInteger("p");
}

Expand Down
19 changes: 11 additions & 8 deletions pmml-sklearn/src/main/java/sklearn/neighbors/KNeighborsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,24 @@ private <E extends Estimator & HasMetric> ComparisonMeasure encodeComparisonMeas
static
private <E extends Estimator & HasMetric> Measure encodeMeasure(E estimator){
String metric = estimator.getMetric();
int p = estimator.getP();

switch(metric){
case KNeighborsConstants.METRIC_EUCLIDEAN:
return new Euclidean();
case KNeighborsConstants.METRIC_MANHATTAN:
return new CityBlock();
case KNeighborsConstants.METRIC_MINKOWSKI:
switch(p){
case 1:
return new CityBlock();
case 2:
return new Euclidean();
default:
return new Minkowski(p);
{
Integer p = estimator.getP();

switch(p){
case 1:
return new CityBlock();
case 2:
return new Euclidean();
default:
return new Minkowski(p);
}
}
default:
throw new IllegalArgumentException(metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ public String getMetric(){
}

@Override
public int getP(){

// XXX
if(!hasattr("p")){
return -1;
}

public Integer getP(){
return getInteger("p");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getMetric(){
}

@Override
public int getP(){
public Integer getP(){
return getInteger("p");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Feature[] apply(Feature feature){
return result;
}

public int getDegree(){
public Integer getDegree(){
return getInteger("degree");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public MLPRegressor getMLP(){
return get("mlp_", MLPRegressor.class);
}

public int getTransformerOutputLayer(){
public Integer getTransformerOutputLayer(){
return getInteger("transformer_output_layer");
}
}

0 comments on commit cc11856

Please sign in to comment.