本文整理汇总了Java中tech.tablesaw.api.Table.sampleSplit方法的典型用法代码示例。如果您正苦于以下问题:Java Table.sampleSplit方法的具体用法?Java Table.sampleSplit怎么用?Java Table.sampleSplit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tech.tablesaw.api.Table
的用法示例。
在下文中一共展示了Table.sampleSplit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
out(example.structure().printHtml());
// show all the label values
out(example.shortColumn("Label").asSet());
Scatter.show("Example data", example.nCol(0), example.nCol(1), example.splitOn(example.shortColumn(2)));
// two fold validation
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
RandomForest model = RandomForest.learn(10, train.shortColumn(2), train.nCol("X"), train.nCol("Y"));
ConfusionMatrix matrix = model.predictMatrix(test.shortColumn(2), test.nCol("X"), test.nCol("Y"));
// Prediction
out(matrix.toTable().printHtml());
out(String.valueOf(matrix.accuracy()));
}
示例2: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
out(example.structure().printHtml());
// show all the label values
out(example.shortColumn("Label").asSet());
Scatter.show("Example data", example.nCol(0), example.nCol(1), example.splitOn(example.shortColumn(2)));
// two fold validation
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
DecisionTree model = DecisionTree.learn(10, train.shortColumn(2), train.nCol("X"), train.nCol("Y"));
ConfusionMatrix matrix = model.predictMatrix(test.shortColumn(2), test.nCol("X"), test.nCol("Y"));
// Prediction
out(matrix.toTable().printHtml());
out(String.valueOf(matrix.accuracy()));
}
示例3: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
out(example.structure().printHtml());
// show all the label values
out(example.shortColumn("Label").asSet());
Scatter.show("Example data", example.nCol(0), example.nCol(1), example.splitOn(example.shortColumn(2)));
// two fold validation
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
LogisticRegression model = LogisticRegression.learn(train.shortColumn(2), train.nCol("X"), train.nCol("Y"));
ConfusionMatrix matrix = model.predictMatrix(test.shortColumn(2), test.nCol("X"), test.nCol("Y"));
// Prediction
out(matrix.toTable().printHtml());
out(String.valueOf(matrix.accuracy()));
}
示例4: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
out(example.structure().printHtml());
// show all the label values
out(example.shortColumn("Label").asSet());
Scatter.show("Example data", example.nCol(0), example.nCol(1), example.splitOn(example.shortColumn(2)));
// two fold validation
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
Lda model = Lda.learn(train.shortColumn(2), train.nCol("X"), train.nCol("Y"));
ConfusionMatrix matrix = model.predictMatrix(test.shortColumn(2), test.nCol("X"), test.nCol("Y"));
// Prediction
out(matrix.toTable().printHtml());
out(String.valueOf(matrix.accuracy()));
}
示例5: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
out(example.structure().printHtml());
// show all the label values
out(example.shortColumn("Label").asSet());
Scatter.show("Example data", example.nCol(0), example.nCol(1), example.splitOn(example.shortColumn(2)));
// two fold validation
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
Knn knn = Knn.learn(2, train.shortColumn(2), train.nCol("X"), train.nCol("Y"));
ConfusionMatrix matrix = knn.predictMatrix(test.shortColumn(2), test.nCol("X"), test.nCol("Y"));
// Prediction
out(matrix.toTable().printHtml());
out(String.valueOf(matrix.accuracy()));
}
示例6: testAsTable
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
@Test
public void testAsTable() throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
KNN<double[]> knn = KNN.learn(
DoubleArrays.to2dArray(train.nCol("X"), train.nCol("Y")),
train.shortColumn(2).toIntArray(), 2);
int[] predicted = new int[test.rowCount()];
SortedSet<Object> lableSet = new TreeSet<>(train.shortColumn(2).asSet());
ConfusionMatrix confusion = new StandardConfusionMatrix(lableSet);
for (int row : test) {
double[] data = new double[2];
data[0] = test.floatColumn(0).getFloat(row);
data[1] = test.floatColumn(1).getFloat(row);
predicted[row] = knn.predict(data);
confusion.increment((int) test.shortColumn(2).get(row), predicted[row]);
}
}
示例7: testWithBooleanColumn
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
@Test
public void testWithBooleanColumn() throws Exception {
Table example = Table.read().csv("../data/KNN_Example_1.csv");
BooleanColumn booleanTarget = example.selectIntoColumn("bt", column("Label").isEqualTo(1));
example.addColumn(booleanTarget);
Table[] splits = example.sampleSplit(.5);
Table train = splits[0];
Table test = splits[1];
LogisticRegression lr = LogisticRegression.learn(
train.booleanColumn(3), train.nCol("X"), train.nCol("Y"));
//TODO(lwhite): Better tests
int[] predicted = new int[test.rowCount()];
SortedSet<Object> lableSet = new TreeSet<>(train.shortColumn(2).asSet());
ConfusionMatrix confusion = new StandardConfusionMatrix(lableSet);
for (int row : test) {
double[] data = new double[2];
data[0] = test.floatColumn(0).getFloat(row);
data[1] = test.floatColumn(1).getFloat(row);
predicted[row] = lr.predict(data);
confusion.increment((int) test.shortColumn(2).get(row), predicted[row]);
}
//TODO(lwhite): Better tests
assertNotNull(confusion);
}