Java Code Examples for org.neuroph.core.data.DataSet#setColumnNames()

The following examples show how to use org.neuroph.core.data.DataSet#setColumnNames() . 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: IrisFlowers.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void run() throws InterruptedException, ExecutionException {
    System.out.println("Creating training set...");
    // get path to training set
    String dataSetFile = "data_sets/iris_data_normalised.txt";
    int inputsCount = 4;
    int outputsCount = 3;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",");
 //   dataSet.setColumnNames(new String[]{"sepal.length", "sepal.width", "petal.length", "petal.width",  "setosa", "versicolor", "virginica"});
    dataSet.setColumnNames(new String[]{"setosa", "versicolor", "virginica"});
    dataSet.shuffle();

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 5, outputsCount);

    String[] classLabels = new String[]{"setosa", "versicolor", "virginica"};
    neuralNet.setOutputLabels(classLabels);

    KFoldCrossValidation crossVal = new KFoldCrossValidation(neuralNet, dataSet, 5);
    EvaluationResult totalResult= crossVal.run();
    List<FoldResult> cflist= crossVal.getResultsByFolds();

}
 
Example 2
Source File: SubSampling.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public DataSet[] sample(DataSet dataSet) {
    // if object was initializes by specifying numParts calculate subSetSizes so all subsets are equally sized
    if (subSetSizes == null) {
        final double singleSubSetSize = 1.0d / numSubSets;
        subSetSizes = new double[numSubSets];
        for (int i = 0; i < numSubSets; i++) {
            subSetSizes[i] = singleSubSetSize;
        }
    }

    // create list of data sets to return
    List<DataSet> subSets = new ArrayList<>();

    // shuffle dataset in order to randomize rows that will be used to fill subsets
    dataSet.shuffle();

    int idxCounter = 0; // index of main data set
    for (int subSetIdx = 0; subSetIdx < numSubSets; subSetIdx++) {
        // create new subset
        DataSet newSubSet = new DataSet(dataSet.getInputSize(), dataSet.getOutputSize());
        // cop column names if there are any
        newSubSet.setColumnNames(dataSet.getColumnNames());

        // fill subset with rows
        long subSetSize = Math.round(subSetSizes[subSetIdx] * dataSet.size()); // calculate size of the current subset
        for (int i = 0; i < subSetSize; i++) {
            if (idxCounter >= dataSet.size()) {
                break;
            }
            newSubSet.add(dataSet.getRowAt(idxCounter));
            idxCounter++;
        }

        // add current subset to list that will be returned
        subSets.add(newSubSet);
    }

    return subSets.toArray(new DataSet[numSubSets]);
}