本文整理汇总了Java中tech.tablesaw.api.Table.addColumn方法的典型用法代码示例。如果您正苦于以下问题:Java Table.addColumn方法的具体用法?Java Table.addColumn怎么用?Java Table.addColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tech.tablesaw.api.Table
的用法示例。
在下文中一共展示了Table.addColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: labeledCentroids
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public Table labeledCentroids() {
Table table = Table.create("Centroids");
CategoryColumn labelColumn = new CategoryColumn("Cluster");
table.addColumn(labelColumn);
for (NumericColumn inputColumn : inputColumns) {
FloatColumn centroid = new FloatColumn(inputColumn.name());
table.addColumn(centroid);
}
double[][] centroids = model.centroids();
for (int i = 0; i < centroids.length; i++) {
labelColumn.appendCell(String.valueOf(i));
double[] values = centroids[i];
for (int k = 0; k < values.length; k++) {
table.floatColumn(k + 1).append((float) values[k]);
}
}
return table;
}
示例2: labeledCentroids
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public Table labeledCentroids() {
Table table = Table.create("Centroids");
CategoryColumn labelColumn = new CategoryColumn("Cluster");
table.addColumn(labelColumn);
for (NumericColumn inputColumn : inputColumns) {
FloatColumn centroid = new FloatColumn(inputColumn.name());
table.addColumn(centroid);
}
double[][] centroids = kMeans.centroids();
for (int i = 0; i < centroids.length; i++) {
labelColumn.appendCell(String.valueOf(i));
double[] values = centroids[i];
for (int k = 0; k < values.length; k++) {
table.floatColumn(k + 1).append((float) values[k]);
}
}
return table;
}
示例3: AssociationRuleMining
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public AssociationRuleMining(IntColumn sets, CategoryColumn items, double support) {
Table temp = Table.create("temp");
temp.addColumn(sets.copy());
temp.addColumn(items.toIntColumn());
temp.sortAscendingOn(sets.name(), items.name());
ViewGroup baskets = temp.splitOn(temp.column(0));
int[][] itemsets = new int[baskets.size()][];
int basketIndex = 0;
for (TemporaryView basket : baskets) {
IntRBTreeSet set = new IntRBTreeSet(basket.intColumn(1).data());
int itemIndex = 0;
itemsets[basketIndex] = new int[set.size()];
for (int item : set) {
itemsets[basketIndex][itemIndex] = item;
itemIndex++;
}
basketIndex++;
}
this.model = new ARM(itemsets, support);
}
示例4: FrequentItemset
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public FrequentItemset(ShortColumn sets, ShortColumn items, double support) {
Table temp = Table.create("temp");
temp.addColumn(sets.copy());
temp.addColumn(items.copy());
temp.sortAscendingOn(sets.name(), items.name());
ViewGroup baskets = temp.splitOn(temp.column(0));
this.setCount = baskets.size();
int[][] itemsets = new int[setCount][];
int basketIndex = 0;
for (TemporaryView basket : baskets) {
ShortRBTreeSet set = new ShortRBTreeSet(basket.shortColumn(1).data());
int itemIndex = 0;
itemsets[basketIndex] = new int[set.size()];
for (short item : set) {
itemsets[basketIndex][itemIndex] = item;
itemIndex++;
}
basketIndex++;
}
this.model = new FPGrowth(itemsets, support);
}
示例5: clustered
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public Table clustered(Column labels) {
Table table = Table.create("Clusters");
CategoryColumn labelColumn = new CategoryColumn("Label");
IntColumn clusterColumn = new IntColumn("Cluster");
table.addColumn(labelColumn);
table.addColumn(clusterColumn);
int[] clusters = kMeans.getClusterLabel();
for (int i = 0; i < clusters.length; i++) {
labelColumn.appendCell(labels.getString(i));
clusterColumn.append(clusters[i]);
}
table = table.sortAscendingOn("Cluster", "Label");
return table;
}
示例6: 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);
}
示例7: defineSchema
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
private static Table defineSchema() {
Table t;
t = Table.create("Observations");
CategoryColumn conceptId = new CategoryColumn("concept");
DateColumn date = new DateColumn("date");
FloatColumn value = new FloatColumn("value");
IntColumn patientId = new IntColumn("patient");
t.addColumn(conceptId);
t.addColumn(date);
t.addColumn(value);
t.addColumn(patientId);
return t;
}
示例8: asTable
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public Table asTable() {
Table table = Table.create(this.name());
for (Column column : columns()) {
table.addColumn(column.subset(rowMap));
}
return table;
}
示例9: asTable
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public Table asTable() {
Table t = Table.create(name);
CategoryColumn measure = new CategoryColumn("Measure");
FloatColumn value = new FloatColumn("Value");
t.addColumn(measure);
t.addColumn(value);
measure.add("n");
value.append(n);
measure.add("sum");
value.append(sum());
measure.add("Mean");
value.append(mean());
measure.add("Min");
value.append(min());
measure.add("Max");
value.append(max());
measure.add("Range");
value.append(range());
measure.add("Variance");
value.append(variance());
measure.add("Std. Dev");
value.append(standardDeviation());
return t;
}
示例10: read
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
/**
* Returns a new table with the given tableName, constructed from the given result set
*
* @throws SQLException
*/
public static Table read(ResultSet resultSet, String tableName) throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
Table table = Table.create(tableName);
// Setup the columns and add to the table
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String name = metaData.getColumnName(i);
ColumnType type = SQL_TYPE_TO_TABLESAW_TYPE.get(metaData.getColumnType(i));
Preconditions.checkState(type != null,
"No column type found for %s as specified for column %s", metaData.getColumnType(i), name);
Column newColumn = TypeUtils.newColumn(name, type);
table.addColumn(newColumn);
}
// Add the rows
while (resultSet.next()) {
for (int i = 1; i <= metaData.getColumnCount(); i++) {
Column column = table.column(i - 1); // subtract 1 because results sets originate at 1 not 0
column.appendCell(resultSet.getString(i));
}
}
return table;
}
示例11: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table ops = Table.create("../data/operations.csv");
out(ops.structure());
out(ops);
DateTimeColumn start = ops.dateColumn("Date").atTime(ops.timeColumn("Start"));
DateTimeColumn end = ops.dateColumn("Date").atTime(ops.timeColumn("End"));
for (int row : ops) {
if (ops.timeColumn("End").get(row).isBefore(ops.timeColumn("Start").get(row))) {
end.get(row).plusDays(1);
}
}
// Calc duration
LongColumn duration = start.differenceInSeconds(end);
ops.addColumn(duration);
duration.setName("Duration");
out(ops);
Table q2_429_assembly = ops.selectWhere(
allOf
(column("date").isInQ2(),
(column("SKU").startsWith("429")),
(column("Operation").isEqualTo("Assembly"))));
Table durationByFacilityAndShift = q2_429_assembly.median("Duration").by("Facility", "Shift");
out(durationByFacilityAndShift);
durationByFacilityAndShift.write().csv("/tmp/durationByFacilityAndShift.csv");
}
示例12: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Get the data
Table baseball = Table.read().csv("../data/baseball.csv");
out(baseball.structure());
// filter to the data available in the 2002 season
Table moneyball = baseball.selectWhere(column("year").isLessThan(2002));
// plot regular season wins against year, segregating on whether the team made the plays
NumericColumn wins = moneyball.numericColumn("W");
NumericColumn year = moneyball.numericColumn("Year");
Column playoffs = moneyball.column("Playoffs");
Scatter.show("Regular season wins by year", wins, year, moneyball.splitOn(playoffs));
// Calculate the run difference for use in the regression model
IntColumn runDifference = moneyball.shortColumn("RS").subtract(moneyball.shortColumn("RA"));
moneyball.addColumn(runDifference);
runDifference.setName("RD");
// Plot RD vs Wins to see if the relationship looks linear
Scatter.show("RD x Wins", moneyball.numericColumn("RD"), moneyball.numericColumn("W"));
// Create the regression model
//ShortColumn wins = moneyball.shortColumn("W");
LeastSquares winsModel = LeastSquares.train(wins, runDifference);
out(winsModel);
// Make a prediction of how many games we win if we score 135 more runs than our opponents
double[] testValue = new double[1];
testValue[0] = 135;
double prediction = winsModel.predict(testValue);
out("Predicted wins with RD = 135: " + prediction);
// Predict runsScored based on On-base percentage, batting average and slugging percentage
LeastSquares runsScored = LeastSquares.train(moneyball.nCol("RS"),
moneyball.nCol("OBP"), moneyball.nCol("BA"), moneyball.nCol("SLG"));
out(runsScored);
LeastSquares runsScored2 = LeastSquares.train(moneyball.nCol("RS"),
moneyball.nCol("OBP"), moneyball.nCol("SLG"));
out(runsScored2);
Histogram.show(runsScored2.residuals());
Scatter.fittedVsResidual(runsScored2);
Scatter.actualVsFitted(runsScored2);
// We use opponent OBP and opponent SLG to model the efficacy of our pitching and defence
Table moneyball2 = moneyball.selectWhere(column("year").isGreaterThan(1998));
LeastSquares runsAllowed = LeastSquares.train(moneyball2.nCol("RA"),
moneyball2.nCol("OOBP"), moneyball2.nCol("OSLG"));
out(runsAllowed);
}
示例13: setUp
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Table table = Table.create("Test");
column1 = new DateColumn("Game date", Locale.ENGLISH);
table.addColumn(column1);
}
示例14: main
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Table table = Table.read().csv(CsvReadOptions
.builder("../data/movielens.data")
.separator('\t'));
out(table.structure());
out(table.shape());
ShortColumn movie = table.shortColumn("movie");
CategoryColumn moviecat = new CategoryColumn("MovieCat");
for (int i = 0; i < movie.size(); i++) {
moviecat.appendCell(movie.getString(i));
}
table.addColumn(moviecat);
out(table.shortColumn("user").unique().size());
out(table.shortColumn("movie").unique().size());
FrequentItemset model = new FrequentItemset(table.shortColumn("user"), table.categoryColumn("MovieCat"), .24);
List<ItemSet> itemSetList = model.learn();
out("Frequent Itemsets");
for (ItemSet itemSet : itemSetList) {
if (itemSet.items.length == 2)
out(itemSet);
}
out(model.supportMap(250));
Object2DoubleOpenHashMap<IntRBTreeSet> confidenceMap = model.confidenceMap(.90);
Object2DoubleMap.FastEntrySet<IntRBTreeSet> entrySet = confidenceMap.object2DoubleEntrySet();
out("");
out("Confidence Map");
for (Object2DoubleMap.Entry<IntRBTreeSet> entry : entrySet) {
out(entry.getKey() + " : " + entry.getDoubleValue());
}
Object2DoubleOpenHashMap<IntRBTreeSet> confidenceMap2 = model.confidenceMap();
Object2DoubleMap.FastEntrySet<IntRBTreeSet> entrySet2 = confidenceMap2.object2DoubleEntrySet();
out("");
out("Confidence Map2");
for (Object2DoubleMap.Entry<IntRBTreeSet> entry2 : entrySet2) {
out(entry2.getKey() + " : " + entry2.getDoubleValue());
}
}
示例15: headerOnly
import tech.tablesaw.api.Table; //导入方法依赖的package包/类
/**
* Returns a Table constructed from a CSV File with the given file name
* <p>
* The @code{fileName} is used as the initial table name for the new table
*
* @param types An array of the types of columns in the file, in the order they appear
* @param header Is the first row in the file a header?
* @param columnSeparator the delimiter
* @param file The fully specified file name. It is used to provide a default name for the table
* @return A Relation containing the data in the csv file.
* @throws IOException if file cannot be read
*/
public static Table headerOnly(ColumnType types[], boolean header, char columnSeparator, File file)
throws IOException {
FileInputStream fis = new FileInputStream(file);
// make sure we don't have leading Unicode BOM
UnicodeBOMInputStream ubis = new UnicodeBOMInputStream(fis);
ubis.skipBOM();
Reader reader = new InputStreamReader(ubis);
BufferedReader streamReader = new BufferedReader(reader);
Table table;
CSVParser csvParser = new CSVParserBuilder()
.withSeparator(columnSeparator)
.build();
try (CSVReader csvReader = new CSVReaderBuilder(streamReader).withCSVParser(csvParser).build()) {
String[] nextLine;
String[] columnNames;
List<String> headerRow;
if (header) {
nextLine = csvReader.readNext();
headerRow = Lists.newArrayList(nextLine);
columnNames = selectColumnNames(headerRow, types);
} else {
columnNames = makeColumnNames(types);
headerRow = Lists.newArrayList(columnNames);
}
table = Table.create(file.getName());
for (int x = 0; x < types.length; x++) {
if (types[x] != SKIP) {
Column newColumn = TypeUtils.newColumn(headerRow.get(x).trim(), types[x]);
table.addColumn(newColumn);
}
}
int[] columnIndexes = new int[columnNames.length];
for (int i = 0; i < columnIndexes.length; i++) {
// get the index in the original table, which includes skipped fields
columnIndexes[i] = headerRow.indexOf(columnNames[i]);
}
}
return table;
}