本文整理汇总了Java中com.rapidminer.example.table.SparseFormatDataRowReader类的典型用法代码示例。如果您正苦于以下问题:Java SparseFormatDataRowReader类的具体用法?Java SparseFormatDataRowReader怎么用?Java SparseFormatDataRowReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparseFormatDataRowReader类属于com.rapidminer.example.table包,在下文中一共展示了SparseFormatDataRowReader类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSparseString
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
/**
* Returns regular and some special attributes (label, id, and example weight) in sparse format.
*
* @param format
* one of the formats specified in {@link SparseFormatDataRowReader}
*/
public String toSparseString(int format, int fractionDigits, boolean quoteNominal) {
StringBuffer str = new StringBuffer();
// label
Attribute labelAttribute = getAttributes().getSpecial(Attributes.LABEL_NAME);
if ((format == SparseFormatDataRowReader.FORMAT_YX) && (labelAttribute != null)) {
str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal) + " ");
}
// id
Attribute idAttribute = getAttributes().getSpecial(Attributes.ID_NAME);
if (idAttribute != null) {
str.append("id:" + getValueAsString(idAttribute, fractionDigits, quoteNominal) + " ");
}
// weight
Attribute weightAttribute = getAttributes().getSpecial(Attributes.WEIGHT_NAME);
if (weightAttribute != null) {
str.append("w:" + getValueAsString(weightAttribute, fractionDigits, quoteNominal) + " ");
}
// batch
Attribute batchAttribute = getAttributes().getSpecial(Attributes.BATCH_NAME);
if (batchAttribute != null) {
str.append("b:" + getValueAsString(batchAttribute, fractionDigits, quoteNominal) + " ");
}
// attributes
str.append(getAttributesAsSparseString(SEPARATOR, SPARSE_SEPARATOR, fractionDigits, quoteNominal) + " ");
// label (format xy & prefix)
if ((format == SparseFormatDataRowReader.FORMAT_PREFIX) && (labelAttribute != null)) {
str.append("l:" + getValueAsString(labelAttribute, fractionDigits, quoteNominal));
}
if ((format == SparseFormatDataRowReader.FORMAT_XY) && (labelAttribute != null)) {
str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal));
}
return str.toString();
}
示例2: testFormatXY
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
@Test
public void testFormatXY() throws Exception {
StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
input.append(ATTRIBUTE_STRINGS[i] + " " + LABEL[i] + Tools.getLineSeparator());
}
readerTest(SparseFormatDataRowReader.FORMAT_XY, new StringReader(input.toString()), null);
}
示例3: testFormatYX
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
@Test
public void testFormatYX() throws Exception {
StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
input.append(LABEL[i] + " " + ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
}
readerTest(SparseFormatDataRowReader.FORMAT_YX, new StringReader(input.toString()), null);
}
示例4: testFormatPrefix
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
@Test
public void testFormatPrefix() throws Exception {
StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
input.append("l:" + LABEL[i] + " " + ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
}
readerTest(SparseFormatDataRowReader.FORMAT_PREFIX, new StringReader(input.toString()), null);
}
示例5: testFormatSeparate
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
@Test
public void testFormatSeparate() throws Exception {
StringBuffer input = new StringBuffer("# comment" + Tools.getLineSeparator());
StringBuffer label = new StringBuffer();
for (int i = 0; i < ATTRIBUTE_STRINGS.length; i++) {
label.append(LABEL[i] + Tools.getLineSeparator());
input.append(ATTRIBUTE_STRINGS[i] + Tools.getLineSeparator());
}
readerTest(SparseFormatDataRowReader.FORMAT_SEPARATE_FILE, new StringReader(input.toString()), new StringReader(label.toString()));
}
示例6: toSparseString
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
/**
* Returns regular and some special attributes (label, id, and example
* weight) in sparse format.
*
* @param format
* one of the formats specified in
* {@link SparseFormatDataRowReader}
*/
public String toSparseString(int format, int fractionDigits, boolean quoteNominal) {
StringBuffer str = new StringBuffer();
// label
Attribute labelAttribute = getAttributes().getSpecial(Attributes.LABEL_NAME);
if ((format == SparseFormatDataRowReader.FORMAT_YX) && (labelAttribute != null)) {
str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal) + " ");
}
// id
Attribute idAttribute = getAttributes().getSpecial(Attributes.ID_NAME);
if (idAttribute != null) {
str.append("id:" + getValueAsString(idAttribute, fractionDigits, quoteNominal) + " ");
}
// weight
Attribute weightAttribute = getAttributes().getSpecial(Attributes.WEIGHT_NAME);
if (weightAttribute != null) {
str.append("w:" + getValueAsString(weightAttribute, fractionDigits, quoteNominal) + " ");
}
// batch
Attribute batchAttribute = getAttributes().getSpecial(Attributes.BATCH_NAME);
if (batchAttribute != null) {
str.append("b:" + getValueAsString(batchAttribute, fractionDigits, quoteNominal) + " ");
}
// attributes
str.append(getAttributesAsSparseString(SEPARATOR, SPARSE_SEPARATOR, fractionDigits, quoteNominal) + " ");
// label (format xy & prefix)
if ((format == SparseFormatDataRowReader.FORMAT_PREFIX) && (labelAttribute != null)) {
str.append("l:" + getValueAsString(labelAttribute, fractionDigits, quoteNominal));
}
if ((format == SparseFormatDataRowReader.FORMAT_XY) && (labelAttribute != null)) {
str.append(getValueAsString(labelAttribute, fractionDigits, quoteNominal));
}
return str.toString();
}
示例7: readerTest
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
public void readerTest(int format, Reader input, Reader labelInput) throws Exception {
AttributeSet attributeSet = new AttributeSet();
Attribute att1 = ExampleTestTools.attributeDogCatMouse();
Attribute att2 = ExampleTestTools.attributeReal(1);
Attribute att3 = ExampleTestTools.attributeReal(2);
Attribute att4 = ExampleTestTools.attributeReal(3);
Attribute att5 = ExampleTestTools.attributeReal(4);
Attribute att6 = ExampleTestTools.attributeYesNo();
attributeSet.addAttribute(att1);
attributeSet.addAttribute(att2);
attributeSet.addAttribute(att3);
attributeSet.addAttribute(att4);
attributeSet.addAttribute(att5);
attributeSet.setSpecialAttribute("label", att6);
java.util.Map<String, String> prefixMap = new java.util.HashMap<String, String>();
prefixMap.put("l", "label");
SparseFormatDataRowReader reader = new SparseFormatDataRowReader(new DataRowFactory(DataRowFactory.TYPE_SPARSE_MAP, '.'),
format, prefixMap, attributeSet, input, labelInput, -1, false, '"');
MemoryExampleTable table = new MemoryExampleTable(attributeSet.getAllAttributes());
table.readExamples(reader);
ExampleSet exampleSet = table.createExampleSet(attributeSet);
Iterator<Example> r = exampleSet.iterator();
Example e = r.next();
assertEquals("example 1, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 1, column 2", 8.0, e.getValue(att2), 0.00000001);
assertEquals("example 1, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 1, column 4", 0.0, e.getValue(att4), 0.00000001);
assertEquals("example 1, column 5", 3.0, e.getValue(att5), 0.00000001);
assertEquals("example 1, label", "yes", e.getValueAsString(att6));
e = r.next();
assertEquals("example 2, column 1", "cat", e.getValueAsString(att1));
assertEquals("example 2, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 2, column 3", 2.5, e.getValue(att3), 0.00000001);
assertEquals("example 2, column 4", 0.15, e.getValue(att4), 0.00000001);
assertEquals("example 2, column 5", 0.0, e.getValue(att5), 0.00000001);
assertEquals("example 2, label", "no", e.getValueAsString(att6));
e = r.next();
assertEquals("example 3, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 3, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 3, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 3, column 4", 0.0, e.getValue(att4), 0.00000001);
assertEquals("example 3, column 5", 1.0, e.getValue(att5), 0.00000001);
assertEquals("example 3, label", "no", e.getValueAsString(att6));
e = r.next();
assertEquals("example 4, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 4, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 4, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 4, column 4", 73, e.getValue(att4), 0.00000001);
assertEquals("example 4, column 5", 0.0, e.getValue(att5), 0.00000001);
assertEquals("example 4, label", "yes", e.getValueAsString(att6));
}
示例8: readerTest
import com.rapidminer.example.table.SparseFormatDataRowReader; //导入依赖的package包/类
public void readerTest(int format, Reader input, Reader labelInput) throws Exception {
AttributeSet attributeSet = new AttributeSet();
Attribute att1 = ExampleTestTools.attributeDogCatMouse();
Attribute att2 = ExampleTestTools.attributeReal(1);
Attribute att3 = ExampleTestTools.attributeReal(2);
Attribute att4 = ExampleTestTools.attributeReal(3);
Attribute att5 = ExampleTestTools.attributeReal(4);
Attribute att6 = ExampleTestTools.attributeYesNo();
attributeSet.addAttribute(att1);
attributeSet.addAttribute(att2);
attributeSet.addAttribute(att3);
attributeSet.addAttribute(att4);
attributeSet.addAttribute(att5);
attributeSet.setSpecialAttribute("label", att6);
java.util.Map<String, String> prefixMap = new java.util.HashMap<String, String>();
prefixMap.put("l", "label");
SparseFormatDataRowReader reader = new SparseFormatDataRowReader(
new DataRowFactory(DataRowFactory.TYPE_SPARSE_MAP, '.'), format, prefixMap, attributeSet, input, labelInput,
-1, false, '"');
ExampleSet exampleSet = ExampleSets.from(attributeSet.getAllAttributes()).withDataRowReader(reader)
.withRole(att6, Attributes.LABEL_NAME).build();
Iterator<Example> r = exampleSet.iterator();
Example e = r.next();
assertEquals("example 1, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 1, column 2", 8.0, e.getValue(att2), 0.00000001);
assertEquals("example 1, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 1, column 4", 0.0, e.getValue(att4), 0.00000001);
assertEquals("example 1, column 5", 3.0, e.getValue(att5), 0.00000001);
assertEquals("example 1, label", "yes", e.getValueAsString(att6));
e = r.next();
assertEquals("example 2, column 1", "cat", e.getValueAsString(att1));
assertEquals("example 2, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 2, column 3", 2.5, e.getValue(att3), 0.00000001);
assertEquals("example 2, column 4", 0.15, e.getValue(att4), 0.00000001);
assertEquals("example 2, column 5", 0.0, e.getValue(att5), 0.00000001);
assertEquals("example 2, label", "no", e.getValueAsString(att6));
e = r.next();
assertEquals("example 3, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 3, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 3, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 3, column 4", 0.0, e.getValue(att4), 0.00000001);
assertEquals("example 3, column 5", 1.0, e.getValue(att5), 0.00000001);
assertEquals("example 3, label", "no", e.getValueAsString(att6));
e = r.next();
assertEquals("example 4, column 1", "dog", e.getValueAsString(att1));
assertEquals("example 4, column 2", 0.0, e.getValue(att2), 0.00000001);
assertEquals("example 4, column 3", 0.0, e.getValue(att3), 0.00000001);
assertEquals("example 4, column 4", 73, e.getValue(att4), 0.00000001);
assertEquals("example 4, column 5", 0.0, e.getValue(att5), 0.00000001);
assertEquals("example 4, label", "yes", e.getValueAsString(att6));
}