Java Code Examples for org.datavec.api.transform.ColumnType#Categorical

The following examples show how to use org.datavec.api.transform.ColumnType#Categorical . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataAnalysis.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Deprecated //Legacy format, no longer used
private Map<String, List<Map<String, Object>>> getJsonRepresentation() {
    Map<String, List<Map<String, Object>>> jsonRepresentation = new LinkedHashMap<>();
    List<Map<String, Object>> list = new ArrayList<>();
    jsonRepresentation.put("DataAnalysis", list);

    for (String colName : schema.getColumnNames()) {
        Map<String, Object> current = new LinkedHashMap<>();
        int idx = schema.getIndexOfColumn(colName);
        current.put(COL_NAME, colName);
        current.put(COL_IDX, idx);
        ColumnType columnType = schema.getMetaData(colName).getColumnType();
        current.put(COL_TYPE, columnType);
        if (columnType == ColumnType.Categorical) {
            current.put(CATEGORICAL_STATE_NAMES,
                            ((CategoricalMetaData) schema.getMetaData(colName)).getStateNames());
        }
        current.put(ANALYSIS, Collections.singletonMap(columnAnalysis.get(idx).getClass().getSimpleName(),
                        columnAnalysis.get(idx)));

        list.add(current);
    }

    return jsonRepresentation;
}
 
Example 2
Source File: DataAnalysis.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Deprecated //Legacy format, no longer used
private Map<String, List<Map<String, Object>>> getJsonRepresentation() {
    Map<String, List<Map<String, Object>>> jsonRepresentation = new LinkedHashMap<>();
    List<Map<String, Object>> list = new ArrayList<>();
    jsonRepresentation.put("DataAnalysis", list);

    for (String colName : schema.getColumnNames()) {
        Map<String, Object> current = new LinkedHashMap<>();
        int idx = schema.getIndexOfColumn(colName);
        current.put(COL_NAME, colName);
        current.put(COL_IDX, idx);
        ColumnType columnType = schema.getMetaData(colName).getColumnType();
        current.put(COL_TYPE, columnType);
        if (columnType == ColumnType.Categorical) {
            current.put(CATEGORICAL_STATE_NAMES,
                            ((CategoricalMetaData) schema.getMetaData(colName)).getStateNames());
        }
        current.put(ANALYSIS, Collections.singletonMap(columnAnalysis.get(idx).getClass().getSimpleName(),
                        columnAnalysis.get(idx)));

        list.add(current);
    }

    return jsonRepresentation;
}
 
Example 3
Source File: CategoricalMetaData.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnType getColumnType() {
    return ColumnType.Categorical;
}
 
Example 4
Source File: CategoricalAnalysis.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnType getColumnType() {
    return ColumnType.Categorical;
}
 
Example 5
Source File: DataAnalysis.java    From DataVec with Apache License 2.0 4 votes vote down vote up
private static DataAnalysis fromMapper(ObjectMapper om, String json) {

        List<ColumnMetaData> meta = new ArrayList<>();
        List<ColumnAnalysis> analysis = new ArrayList<>();
        try {
            JsonNode node = om.readTree(json);
            Iterator<String> fieldNames = node.fieldNames();
            boolean hasDataAnalysis = false;
            while (fieldNames.hasNext()) {
                if ("DataAnalysis".equals(fieldNames.next())) {
                    hasDataAnalysis = true;
                    break;
                }
            }
            if (!hasDataAnalysis) {
                throw new RuntimeException();
            }

            ArrayNode arrayNode = (ArrayNode) node.get("DataAnalysis");
            for (int i = 0; i < arrayNode.size(); i++) {
                JsonNode analysisNode = arrayNode.get(i);
                String name = analysisNode.get(COL_NAME).asText();
                int idx = analysisNode.get(COL_IDX).asInt();
                ColumnType type = ColumnType.valueOf(analysisNode.get(COL_TYPE).asText());

                JsonNode daNode = analysisNode.get(ANALYSIS);
                ColumnAnalysis dataAnalysis = om.treeToValue(daNode, ColumnAnalysis.class);

                if (type == ColumnType.Categorical) {
                    ArrayNode an = (ArrayNode) analysisNode.get(CATEGORICAL_STATE_NAMES);
                    List<String> stateNames = new ArrayList<>(an.size());
                    Iterator<JsonNode> iter = an.elements();
                    while (iter.hasNext()) {
                        stateNames.add(iter.next().asText());
                    }
                    meta.add(new CategoricalMetaData(name, stateNames));
                } else {
                    meta.add(type.newColumnMetaData(name));
                }

                analysis.add(dataAnalysis);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Schema schema = new Schema(meta);
        return new DataAnalysis(schema, analysis);
    }
 
Example 6
Source File: CategoricalMetaData.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnType getColumnType() {
    return ColumnType.Categorical;
}
 
Example 7
Source File: CategoricalAnalysis.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnType getColumnType() {
    return ColumnType.Categorical;
}
 
Example 8
Source File: DataAnalysis.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
private static DataAnalysis fromMapper(ObjectMapper om, String json) {

        List<ColumnMetaData> meta = new ArrayList<>();
        List<ColumnAnalysis> analysis = new ArrayList<>();
        try {
            JsonNode node = om.readTree(json);
            Iterator<String> fieldNames = node.fieldNames();
            boolean hasDataAnalysis = false;
            while (fieldNames.hasNext()) {
                if ("DataAnalysis".equals(fieldNames.next())) {
                    hasDataAnalysis = true;
                    break;
                }
            }
            if (!hasDataAnalysis) {
                throw new RuntimeException();
            }

            ArrayNode arrayNode = (ArrayNode) node.get("DataAnalysis");
            for (int i = 0; i < arrayNode.size(); i++) {
                JsonNode analysisNode = arrayNode.get(i);
                String name = analysisNode.get(COL_NAME).asText();
                int idx = analysisNode.get(COL_IDX).asInt();
                ColumnType type = ColumnType.valueOf(analysisNode.get(COL_TYPE).asText());

                JsonNode daNode = analysisNode.get(ANALYSIS);
                ColumnAnalysis dataAnalysis = om.treeToValue(daNode, ColumnAnalysis.class);

                if (type == ColumnType.Categorical) {
                    ArrayNode an = (ArrayNode) analysisNode.get(CATEGORICAL_STATE_NAMES);
                    List<String> stateNames = new ArrayList<>(an.size());
                    Iterator<JsonNode> iter = an.elements();
                    while (iter.hasNext()) {
                        stateNames.add(iter.next().asText());
                    }
                    meta.add(new CategoricalMetaData(name, stateNames));
                } else {
                    meta.add(type.newColumnMetaData(name));
                }

                analysis.add(dataAnalysis);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Schema schema = new Schema(meta);
        return new DataAnalysis(schema, analysis);
    }