Example usage for weka.classifiers.functions RBFNetwork setMinStdDev

List of usage examples for weka.classifiers.functions RBFNetwork setMinStdDev

Introduction

In this page you can find the example usage for weka.classifiers.functions RBFNetwork setMinStdDev.

Prototype

public void setMinStdDev(double newMinStdDev) 

Source Link

Document

Set the MinStdDev value.

Usage

From source file:org.jaqpot.algorithm.resource.WekaRBF.java

License:Open Source License

@POST
@Path("training")
public Response training(TrainingRequest request) {

    try {// w  w w.j  a v  a 2  s.  c  o  m
        if (request.getDataset().getDataEntry().isEmpty()
                || request.getDataset().getDataEntry().get(0).getValues().isEmpty()) {
            return Response.status(Response.Status.BAD_REQUEST).entity(
                    ErrorReportFactory.badRequest("Dataset is empty", "Cannot train model on empty dataset"))
                    .build();
        }
        List<String> features = request.getDataset().getDataEntry().stream().findFirst().get().getValues()
                .keySet().stream().collect(Collectors.toList());

        Instances data = InstanceUtils.createFromDataset(request.getDataset(), request.getPredictionFeature());

        Map<String, Object> parameters = request.getParameters() != null ? request.getParameters()
                : new HashMap<>();

        Double minStdDev = Double.parseDouble(parameters.getOrDefault("minStdDev", _minStdDev).toString());
        Double ridge = Double.parseDouble(parameters.getOrDefault("ridge", _ridge).toString());
        Integer seed = Integer.parseInt(parameters.getOrDefault("seed", _seed).toString());
        Integer maxIts = Integer.parseInt(parameters.getOrDefault("maxIts", _maxIts).toString());
        Integer numClusters = Integer.parseInt(parameters.getOrDefault("numClusters", _numClusters).toString());

        RBFNetwork rbf = new RBFNetwork();

        rbf.setMinStdDev(minStdDev);
        rbf.setRidge(ridge);
        rbf.setClusteringSeed(seed);
        rbf.setMaxIts(maxIts);
        rbf.setNumClusters(numClusters);

        rbf.buildClassifier(data);

        WekaModel model = new WekaModel();
        model.setClassifier(rbf);

        TrainingResponse response = new TrainingResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(baos);
        out.writeObject(model);
        String base64Model = Base64.getEncoder().encodeToString(baos.toByteArray());
        response.setRawModel(base64Model);
        List<String> independentFeatures = features.stream()
                .filter(feature -> !feature.equals(request.getPredictionFeature()))
                .collect(Collectors.toList());
        response.setIndependentFeatures(independentFeatures);
        //            response.setPmmlModel(pmml);
        response.setAdditionalInfo(request.getPredictionFeature());
        response.setPredictedFeatures(
                Arrays.asList("Weka RBF prediction of " + request.getPredictionFeature()));

        return Response.ok(response).build();
    } catch (Exception ex) {
        Logger.getLogger(WekaMLR.class.getName()).log(Level.SEVERE, null, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
    }
}

From source file:org.jaqpot.algorithms.resource.WekaRBF.java

License:Open Source License

@POST
@Path("training")
public Response training(TrainingRequest request) {

    try {//from   w  w  w.ja  va2  s  . c  om
        if (request.getDataset().getDataEntry().isEmpty()
                || request.getDataset().getDataEntry().get(0).getValues().isEmpty()) {
            return Response.status(Response.Status.BAD_REQUEST)
                    .entity("Dataset is empty. Cannot train model on empty dataset.").build();
        }
        List<String> features = request.getDataset().getDataEntry().stream().findFirst().get().getValues()
                .keySet().stream().collect(Collectors.toList());

        Instances data = InstanceUtils.createFromDataset(request.getDataset(), request.getPredictionFeature());

        Map<String, Object> parameters = request.getParameters() != null ? request.getParameters()
                : new HashMap<>();

        Double minStdDev = Double.parseDouble(parameters.getOrDefault("minStdDev", _minStdDev).toString());
        Double ridge = Double.parseDouble(parameters.getOrDefault("ridge", _ridge).toString());
        Integer seed = Integer.parseInt(parameters.getOrDefault("seed", _seed).toString());
        Integer maxIts = Integer.parseInt(parameters.getOrDefault("maxIts", _maxIts).toString());
        Integer numClusters = Integer.parseInt(parameters.getOrDefault("numClusters", _numClusters).toString());

        RBFNetwork rbf = new RBFNetwork();

        rbf.setMinStdDev(minStdDev);
        rbf.setRidge(ridge);
        rbf.setClusteringSeed(seed);
        rbf.setMaxIts(maxIts);
        rbf.setNumClusters(numClusters);

        rbf.buildClassifier(data);

        WekaModel model = new WekaModel();
        model.setClassifier(rbf);

        TrainingResponse response = new TrainingResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(baos);
        out.writeObject(model);
        String base64Model = Base64.getEncoder().encodeToString(baos.toByteArray());
        response.setRawModel(base64Model);
        List<String> independentFeatures = features.stream()
                .filter(feature -> !feature.equals(request.getPredictionFeature()))
                .collect(Collectors.toList());
        response.setIndependentFeatures(independentFeatures);
        //            response.setPmmlModel(pmml);
        response.setAdditionalInfo(request.getPredictionFeature());
        response.setPredictedFeatures(
                Arrays.asList("Weka RBF prediction of " + request.getPredictionFeature()));

        return Response.ok(response).build();
    } catch (Exception ex) {
        Logger.getLogger(WekaMLR.class.getName()).log(Level.SEVERE, null, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
    }
}