@Test public void testShap() { MathEx.setSeed(19650218); GradientTreeBoost model = GradientTreeBoost.fit(Iris.formula, Iris.data, 100, 20, 6, 5, 0.05, 0.7); String[] fields = java.util.Arrays.stream(model.schema().fields()).map(field -> field.name).toArray(String[]::new); double[] importance = model.importance(); double[] shap = model.shap(Iris.data); System.out.println("----- importance -----"); for (int i = 0; i < importance.length; i++) { System.out.format("%-15s %.4f%n", fields[i], importance[i]); } System.out.println("----- SHAP -----"); for (int i = 0; i < fields.length; i++) { System.out.format("%-15s %.4f %.4f %.4f%n", fields[i], shap[2*i], shap[2*i+1], shap[2*i+2]); } }
public double[] shap(DataFrame data) { formula.bind(data.schema()); return shap(data.stream().parallel()); }
GradientTreeBoost implements SoftClassifier<Tuple>, DataFrameClassifier, SHAP<Tuple> { public double[] shap(DataFrame data) { formula.bind(data.schema()); return shap(data.stream().parallel()); } }
GradientTreeBoost implements SoftClassifier<Tuple>, DataFrameClassifier, SHAP<Tuple> { public double[] shap(DataFrame data) { formula.bind(data.schema()); return shap(data.stream().parallel()); } GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance, IntSet labels);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance, IntSet labels); }
GradientTreeBoost implements SoftClassifier<Tuple>, DataFrameClassifier, SHAP<Tuple> { public double[] shap(DataFrame data) { formula.bind(data.schema()); return shap(data.stream().parallel()); } GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance, IntSet labels);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance, IntSet labels); static GradientTreeBoost fit(Formula formula, DataFrame data); static GradientTreeBoost fit(Formula formula, DataFrame data, Properties prop); static GradientTreeBoost fit(Formula formula, DataFrame data, int ntrees, int maxDepth,
                                        int maxNodes, int nodeSize, double shrinkage, double subsample); @Override Formula formula(); @Override StructType schema(); double[] importance(); int size(); RegressionTree[] trees(); void trim(int ntrees); @Override int predict(Tuple x); @Override int predict(Tuple x, double[] posteriori); int[][] test(DataFrame data); double[] shap(DataFrame data); @Override double[] shap(Tuple x); }
GradientTreeBoost implements SoftClassifier<Tuple>, DataFrameClassifier, SHAP<Tuple> { public double[] shap(DataFrame data) { formula.bind(data.schema()); return shap(data.stream().parallel()); } GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[] trees, double b, double shrinkage, double[] importance, IntSet labels);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance);  GradientTreeBoost(Formula formula, RegressionTree[][] forest, double shrinkage, double[] importance, IntSet labels); static GradientTreeBoost fit(Formula formula, DataFrame data); static GradientTreeBoost fit(Formula formula, DataFrame data, Properties prop); static GradientTreeBoost fit(Formula formula, DataFrame data, int ntrees, int maxDepth,
                                        int maxNodes, int nodeSize, double shrinkage, double subsample); @Override Formula formula(); @Override StructType schema(); double[] importance(); int size(); RegressionTree[] trees(); void trim(int ntrees); @Override int predict(Tuple x); @Override int predict(Tuple x, double[] posteriori); int[][] test(DataFrame data); double[] shap(DataFrame data); @Override double[] shap(Tuple x);  }