@Test public void testFormula() { System.out.println("formula"); Formula formula = Formula.of("salary", $("age")); assertEquals("salary ~ age", formula.toString()); DataFrame output = formula.frame(df); System.out.println(output); assertEquals(df.size(), output.size()); assertEquals(2, output.ncols()); smile.data.type.StructType schema = DataTypes.struct( new StructField("salary", DataTypes.object(Double.class)), new StructField("age", DataTypes.IntegerType) ); assertEquals(schema, output.schema()); DataFrame x = formula.x(df); System.out.println(x); assertEquals(df.size(), x.size()); assertEquals(1, x.ncols()); smile.data.type.StructType xschema = DataTypes.struct( new StructField("age", DataTypes.IntegerType) ); assertEquals(xschema, x.schema()); assertEquals(10000.0, formula.y(df.get(0)), 1E-7); assertEquals(Double.NaN, formula.y(df.get(1)), 1E-7); Matrix matrix = formula.matrix(df); assertEquals(df.size(), matrix.nrows()); assertEquals(2, matrix.ncols()); }
public Formula(Term response, Term... predictors) { if (response instanceof Dot || response instanceof FactorCrossing) { throw new IllegalArgumentException("The response variable cannot be '.' or FactorCrossing."); } this.response = response; this.predictors = predictors; }
Formula implements Serializable { public Formula(Term response, Term... predictors) { if (response instanceof Dot || response instanceof FactorCrossing) { throw new IllegalArgumentException("The response variable cannot be '.' or FactorCrossing."); } this.response = response; this.predictors = predictors; } }
Formula implements Serializable { public Formula(Term response, Term... predictors) { if (response instanceof Dot || response instanceof FactorCrossing) { throw new IllegalArgumentException("The response variable cannot be '.' or FactorCrossing."); } this.response = response; this.predictors = predictors; } Formula(Term response, Term... predictors); }
Formula implements Serializable { public Formula(Term response, Term... predictors) { if (response instanceof Dot || response instanceof FactorCrossing) { throw new IllegalArgumentException("The response variable cannot be '.' or FactorCrossing."); } this.response = response; this.predictors = predictors; } Formula(Term response, Term... predictors); Term[] predictors(); Term response(); @Override String toString(); @Override boolean equals(Object o); static Formula lhs(String lhs); static Formula lhs(Term lhs); static Formula rhs(String... predictors); static Formula rhs(Term... predictors); static Formula of(String response, String... predictors); static Formula of(String response, Term... predictors); static Formula of(Term response, Term... predictors); Formula expand(StructType inputSchema); StructType bind(StructType inputSchema); Tuple apply(Tuple t); Tuple x(Tuple t); DataFrame frame(DataFrame df); DataFrame x(DataFrame df); Matrix matrix(DataFrame df); Matrix matrix(DataFrame df, boolean bias); BaseVector y(DataFrame df); double y(Tuple t); int yint(Tuple t); }
Formula implements Serializable { public Formula(Term response, Term... predictors) { if (response instanceof Dot || response instanceof FactorCrossing) { throw new IllegalArgumentException("The response variable cannot be '.' or FactorCrossing."); } this.response = response; this.predictors = predictors; } Formula(Term response, Term... predictors); Term[] predictors(); Term response(); @Override String toString(); @Override boolean equals(Object o); static Formula lhs(String lhs); static Formula lhs(Term lhs); static Formula rhs(String... predictors); static Formula rhs(Term... predictors); static Formula of(String response, String... predictors); static Formula of(String response, Term... predictors); static Formula of(Term response, Term... predictors); Formula expand(StructType inputSchema); StructType bind(StructType inputSchema); Tuple apply(Tuple t); Tuple x(Tuple t); DataFrame frame(DataFrame df); DataFrame x(DataFrame df); Matrix matrix(DataFrame df); Matrix matrix(DataFrame df, boolean bias); BaseVector y(DataFrame df); double y(Tuple t); int yint(Tuple t);  }