diff --git a/pmml-sklearn-extension/src/main/java/category_encoders/BaseNEncoder.java b/pmml-sklearn-extension/src/main/java/category_encoders/BaseNEncoder.java index b3671ada7..ad406db04 100644 --- a/pmml-sklearn-extension/src/main/java/category_encoders/BaseNEncoder.java +++ b/pmml-sklearn-extension/src/main/java/category_encoders/BaseNEncoder.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import com.google.common.base.Strings; import com.google.common.collect.LinkedHashMultimap; @@ -64,13 +65,13 @@ public List encodeFeatures(List features, SkLearnEncoder encod Object missingCategory = null; - if((BaseNEncoder.HANDLEMISSING_VALUE).equals(handleMissing)){ + if(Objects.equals(BaseNEncoder.HANDLEMISSING_VALUE, handleMissing)){ missingCategory = BaseEncoder.CATEGORY_NAN; } Integer defaultValue = null; - if((BaseNEncoder.HANDLEUNKNOWN_VALUE).equals(handleUnknown)){ + if(Objects.equals(BaseNEncoder.HANDLEUNKNOWN_VALUE, handleUnknown)){ defaultValue = 0; } diff --git a/pmml-sklearn-extension/src/main/java/category_encoders/CountEncoder.java b/pmml-sklearn-extension/src/main/java/category_encoders/CountEncoder.java index 14317d417..72a9fd1c7 100644 --- a/pmml-sklearn-extension/src/main/java/category_encoders/CountEncoder.java +++ b/pmml-sklearn-extension/src/main/java/category_encoders/CountEncoder.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import com.google.common.base.Functions; @@ -63,13 +64,13 @@ public List encodeFeatures(List features, SkLearnEncoder encod Object missingCategory = null; - if((CountEncoder.HANDLEMISSING_COUNT).equals(handleMissing) || (CountEncoder.HANDLEMISSING_VALUE).equals(handleMissing)){ + if(Objects.equals(CountEncoder.HANDLEMISSING_COUNT, handleMissing) || Objects.equals(CountEncoder.HANDLEMISSING_VALUE, handleMissing)){ missingCategory = BaseEncoder.CATEGORY_NAN; } Integer defaultValue = null; - if((CountEncoder.HANDLEUNKNOWN_VALUE).equals(handleUnknown)){ + if(Objects.equals(CountEncoder.HANDLEUNKNOWN_VALUE, handleUnknown)){ defaultValue = getDefaultValue(); } diff --git a/pmml-sklearn-extension/src/main/java/category_encoders/MeanEncoder.java b/pmml-sklearn-extension/src/main/java/category_encoders/MeanEncoder.java index dfd0efd18..2ff05d570 100644 --- a/pmml-sklearn-extension/src/main/java/category_encoders/MeanEncoder.java +++ b/pmml-sklearn-extension/src/main/java/category_encoders/MeanEncoder.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.BiFunction; import com.google.common.base.Functions; @@ -63,13 +64,13 @@ public List encodeFeatures(List features, SkLearnEncoder encod Object missingCategory = null; - if((MeanEncoder.HANDLEMISSING_VALUE).equals(handleMissing)){ + if(Objects.equals(MeanEncoder.HANDLEMISSING_VALUE, handleMissing)){ missingCategory = BaseEncoder.CATEGORY_NAN; } Number defaultValue = null; - if((MeanEncoder.HANDLEUNKNOWN_VALUE).equals(handleUnknown)){ + if(Objects.equals(MeanEncoder.HANDLEUNKNOWN_VALUE, handleUnknown)){ defaultValue = getMean(); } diff --git a/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalEncoder.java b/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalEncoder.java index f783542e1..98d5d0a70 100644 --- a/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalEncoder.java +++ b/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalEncoder.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import com.google.common.base.Function; import com.google.common.base.Functions; @@ -52,13 +53,13 @@ public List encodeFeatures(List features, SkLearnEncoder encod Integer mapMissingTo = null; - if((OrdinalEncoder.HANDLEMISSING_VALUE).equals(handleMissing)){ + if(Objects.equals(OrdinalEncoder.HANDLEMISSING_VALUE, handleMissing)){ mapMissingTo = -1; } Integer defaultValue = null; - if((OrdinalEncoder.HANDLEUNKNOWN_VALUE).equals(handleUnknown)){ + if(Objects.equals(OrdinalEncoder.HANDLEUNKNOWN_VALUE, handleUnknown)){ defaultValue = -2; } diff --git a/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalMapEncoder.java b/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalMapEncoder.java index f6e624554..c937fa410 100644 --- a/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalMapEncoder.java +++ b/pmml-sklearn-extension/src/main/java/category_encoders/OrdinalMapEncoder.java @@ -23,6 +23,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import numpy.core.ScalarUtil; import org.dmg.pmml.Field; @@ -55,13 +56,13 @@ public List encodeFeatures(List features, SkLearnEncoder encod Object missingCategory = null; - if((OrdinalMapEncoder.HANDLEMISSING_VALUE).equals(handleMissing)){ + if(Objects.equals(OrdinalMapEncoder.HANDLEMISSING_VALUE, handleMissing)){ missingCategory = BaseEncoder.CATEGORY_NAN; } Object unknownCategory = null; - if((OrdinalMapEncoder.HANDLEUNKNOWN_VALUE).equals(handleUnknown)){ + if(Objects.equals(OrdinalMapEncoder.HANDLEUNKNOWN_VALUE, handleUnknown)){ unknownCategory = OrdinalEncoder.CATEGORY_UNKNOWN; } diff --git a/pmml-sklearn/src/main/java/sklearn/compose/ColumnTransformer.java b/pmml-sklearn/src/main/java/sklearn/compose/ColumnTransformer.java index b87538396..d2c65b846 100644 --- a/pmml-sklearn/src/main/java/sklearn/compose/ColumnTransformer.java +++ b/pmml-sklearn/src/main/java/sklearn/compose/ColumnTransformer.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.dmg.pmml.PMML; import org.jpmml.converter.Feature; @@ -106,11 +107,11 @@ protected Transformer getTransformer(Object[] fittedTransformer){ @Override public Transformer apply(Object object){ - if((SkLearnSteps.DROP).equals(object)){ + if(Objects.equals(SkLearnSteps.DROP, object)){ return Drop.INSTANCE; } else - if((SkLearnSteps.PASSTHROUGH).equals(object)){ + if(Objects.equals(SkLearnSteps.PASSTHROUGH, object)){ return PassThrough.INSTANCE; } diff --git a/pmml-sklearn/src/main/java/sklearn/feature_selection/SelectKBest.java b/pmml-sklearn/src/main/java/sklearn/feature_selection/SelectKBest.java index baa39c16e..72e1df509 100644 --- a/pmml-sklearn/src/main/java/sklearn/feature_selection/SelectKBest.java +++ b/pmml-sklearn/src/main/java/sklearn/feature_selection/SelectKBest.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import com.google.common.primitives.Booleans; import org.jpmml.converter.ValueUtil; @@ -43,7 +44,7 @@ public List getSupportMask(){ Object k = getK(); List scores = getScores(); - if(("all").equals(k)){ + if(Objects.equals("all", k)){ return null; } diff --git a/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java b/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java index 9c9e3ee3e..cd35ab647 100644 --- a/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java +++ b/pmml-sklearn/src/main/java/sklearn/linear_model/logistic/LogisticRegression.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.dmg.pmml.DataType; import org.dmg.pmml.MiningFunction; @@ -59,7 +60,7 @@ public Model encodeModel(Schema schema){ String sklearnVersion = getSkLearnVersion(); String multiClass = getMultiClass(); - if((LogisticRegression.MULTICLASS_AUTO).equals(multiClass)){ + if(Objects.equals(LogisticRegression.MULTICLASS_AUTO, multiClass)){ int[] shape = getCoefShape(); String solver = getSolver(); @@ -166,7 +167,7 @@ public String getMultiClass(){ String multiClass = getEnum("multi_class", this::getString, Arrays.asList(LogisticRegression.MULTICLASS_AUTO, LogisticRegression.MULTICLASS_MULTINOMIAL, LogisticRegression.MULTICLASS_OVR, LogisticRegression.MULTICLASS_WARN)); // SkLearn 0.20 - if((LogisticRegression.MULTICLASS_WARN).equals(multiClass)){ + if(Objects.equals(LogisticRegression.MULTICLASS_WARN, multiClass)){ multiClass = LogisticRegression.MULTICLASS_OVR; } @@ -182,7 +183,7 @@ private String getAutoMultiClass(String solver, int[] shape){ int numberOfClasses = shape[0]; int numberOfFeatures = shape[1]; - if((LogisticRegression.SOLVER_LIBLINEAR).equals(solver)){ + if(Objects.equals(LogisticRegression.SOLVER_LIBLINEAR, solver)){ return LogisticRegression.MULTICLASS_OVR; } // End if diff --git a/pmml-sklearn/src/main/java/sklearn/pipeline/SkLearnPipeline.java b/pmml-sklearn/src/main/java/sklearn/pipeline/SkLearnPipeline.java index 6fc35f35c..e039fa5eb 100644 --- a/pmml-sklearn/src/main/java/sklearn/pipeline/SkLearnPipeline.java +++ b/pmml-sklearn/src/main/java/sklearn/pipeline/SkLearnPipeline.java @@ -19,6 +19,7 @@ package sklearn.pipeline; import java.util.List; +import java.util.Objects; import com.google.common.collect.Lists; import net.razorvine.pickle.objects.ClassDict; @@ -80,7 +81,7 @@ public boolean hasFinalEstimator(){ Object step = TupleUtil.extractElement(finalStep, 1); - if((step == null) || (SkLearnSteps.PASSTHROUGH).equals(step)){ + if((step == null) || Objects.equals(SkLearnSteps.PASSTHROUGH, step)){ return false; } // End if @@ -130,7 +131,7 @@ public List getTransformers(){ @Override public Transformer apply(Object object){ - if((object == null) || (SkLearnSteps.PASSTHROUGH).equals(object)){ + if((object == null) || Objects.equals(SkLearnSteps.PASSTHROUGH, object)){ return PassThrough.INSTANCE; } @@ -163,7 +164,7 @@ public E getFinalEstimator(Class clazz){ Object step = TupleUtil.extractElement(finalStep, 1); - if((step == null) || (SkLearnSteps.PASSTHROUGH).equals(step)){ + if((step == null) || Objects.equals(SkLearnSteps.PASSTHROUGH, step)){ throw new SkLearnException("The pipeline ends with a transformer-like object"); } @@ -195,7 +196,7 @@ public Step getHead(){ @Override public Step apply(Object object){ - if((object == null) || (SkLearnSteps.PASSTHROUGH).equals(object)){ + if((object == null) || Objects.equals(SkLearnSteps.PASSTHROUGH, object)){ return null; } diff --git a/pmml-sklearn/src/main/java/sklearn/preprocessing/Imputer.java b/pmml-sklearn/src/main/java/sklearn/preprocessing/Imputer.java index a74eb5b35..4fef922c7 100644 --- a/pmml-sklearn/src/main/java/sklearn/preprocessing/Imputer.java +++ b/pmml-sklearn/src/main/java/sklearn/preprocessing/Imputer.java @@ -19,6 +19,7 @@ package sklearn.preprocessing; import java.util.List; +import java.util.Objects; import sklearn.impute.SimpleImputer; @@ -32,7 +33,7 @@ public Imputer(String module, String name){ public Object getMissingValues(){ Object missingValues = super.getMissingValues(); - if(("NaN").equals(missingValues)){ + if(Objects.equals("NaN", missingValues)){ missingValues = null; } diff --git a/pmml-sklearn/src/main/java/sklearn/preprocessing/OneHotEncoder.java b/pmml-sklearn/src/main/java/sklearn/preprocessing/OneHotEncoder.java index b24e44ccf..e8d917e9b 100644 --- a/pmml-sklearn/src/main/java/sklearn/preprocessing/OneHotEncoder.java +++ b/pmml-sklearn/src/main/java/sklearn/preprocessing/OneHotEncoder.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import com.google.common.collect.ContiguousSet; import com.google.common.collect.DiscreteDomain; @@ -107,7 +108,7 @@ public List getValues(){ Object numberOfValues = getOptionalScalar("n_values"); - if(("auto").equals(numberOfValues)){ + if(Objects.equals("auto", numberOfValues)){ return getActiveFeatures(); } diff --git a/pmml-sklearn/src/main/java/sklearn/preprocessing/OrdinalEncoder.java b/pmml-sklearn/src/main/java/sklearn/preprocessing/OrdinalEncoder.java index 62b6cd40f..cd4dbbbfc 100644 --- a/pmml-sklearn/src/main/java/sklearn/preprocessing/OrdinalEncoder.java +++ b/pmml-sklearn/src/main/java/sklearn/preprocessing/OrdinalEncoder.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import org.dmg.pmml.DataType; import org.dmg.pmml.InvalidValueTreatmentMethod; @@ -48,7 +49,7 @@ public List encodeFeatures(List features, SkLearnEncoder encod if(handleUnknown != null){ - if((OrdinalEncoder.HANDLEUNKNOWN_USE_ENCODED_VALUE).equals(handleUnknown)){ + if(Objects.equals(OrdinalEncoder.HANDLEUNKNOWN_USE_ENCODED_VALUE, handleUnknown)){ unknownValue = getUnknownValue(); if(ValueUtil.isNaN(unknownValue)){ diff --git a/pmml-sklearn/src/main/java/sklearn2pmml/CustomizationUtil.java b/pmml-sklearn/src/main/java/sklearn2pmml/CustomizationUtil.java index b7eb6435a..b907ccb8e 100644 --- a/pmml-sklearn/src/main/java/sklearn2pmml/CustomizationUtil.java +++ b/pmml-sklearn/src/main/java/sklearn2pmml/CustomizationUtil.java @@ -390,7 +390,7 @@ private DocumentNamespaceContext(Document document){ public String getNamespaceURI(String prefix){ Document document = getDocument(); - if((XMLConstants.DEFAULT_NS_PREFIX).equals(prefix)){ + if(Objects.equals(XMLConstants.DEFAULT_NS_PREFIX, prefix)){ return document.lookupNamespaceURI(null); } diff --git a/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/ConcatTransformer.java b/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/ConcatTransformer.java index ea7aa3051..d8633cb06 100644 --- a/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/ConcatTransformer.java +++ b/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/ConcatTransformer.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import org.dmg.pmml.Apply; import org.dmg.pmml.DataType; @@ -50,7 +51,7 @@ public List encodeFeatures(List features, SkLearnEncoder encod for(int i = 0; i < features.size(); i++){ Feature feature = features.get(i); - if((i > 0) && !("").equals(separator)){ + if((i > 0) && !Objects.equals("", separator)){ expressions.add(ExpressionUtil.createConstant(DataType.STRING, separator)); } diff --git a/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/SeriesConstructor.java b/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/SeriesConstructor.java index ed4a93c89..0a2f4dbdd 100644 --- a/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/SeriesConstructor.java +++ b/pmml-sklearn/src/main/java/sklearn2pmml/preprocessing/SeriesConstructor.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import org.dmg.pmml.DataType; import org.jpmml.converter.Feature; @@ -57,7 +58,7 @@ public List encodeFeatures(List features, SkLearnEncoder encod feature = CategoricalDtypeUtil.refineFeature(feature, categoricalDtype, encoder); } // End if - if(name != null && !(feature.getName()).equals(name)){ + if(name != null && !Objects.equals(feature.getName(), name)){ encoder.renameFeature(feature, name); } diff --git a/pmml-sklearn/src/main/java/sklearn_pandas/CategoricalImputer.java b/pmml-sklearn/src/main/java/sklearn_pandas/CategoricalImputer.java index a7148d7e8..e13bf08c5 100644 --- a/pmml-sklearn/src/main/java/sklearn_pandas/CategoricalImputer.java +++ b/pmml-sklearn/src/main/java/sklearn_pandas/CategoricalImputer.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import org.dmg.pmml.MissingValueTreatmentMethod; import org.jpmml.converter.Feature; @@ -41,7 +42,7 @@ public List encodeFeatures(List features, SkLearnEncoder encod ClassDictUtil.checkSize(1, features); - if(("NaN").equals(missingValues)){ + if(Objects.equals("NaN", missingValues)){ missingValues = null; }