Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package Beans;
- import java.util.ArrayList;
- import javax.faces.application.FacesMessage;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.RequestScoped;
- import javax.faces.context.FacesContext;
- import weka.classifiers.Classifier;
- import weka.core.Attribute;
- import weka.core.DenseInstance;
- import weka.core.Instance;
- import weka.core.Instances;
- import weka.core.SparseInstance;
- /**
- *
- * @author Kaprawiec
- */
- @ManagedBean
- @RequestScoped
- public class Classify {
- public String getLCORE() {
- return LCORE;
- }
- public void setLCORE(String LCORE) {
- this.LCORE = LCORE;
- }
- public String getLSURF() {
- return LSURF;
- }
- public void setLSURF(String LSURF) {
- this.LSURF = LSURF;
- }
- public String getLO2() {
- return LO2;
- }
- public void setLO2(String LO2) {
- this.LO2 = LO2;
- }
- public String getLBP() {
- return LBP;
- }
- public void setLBP(String LBP) {
- this.LBP = LBP;
- }
- public String getSURFSTBL() {
- return SURFSTBL;
- }
- public void setSURFSTBL(String SURFSTBL) {
- this.SURFSTBL = SURFSTBL;
- }
- public String getCORESTBL() {
- return CORESTBL;
- }
- public void setCORESTBL(String CORESTBL) {
- this.CORESTBL = CORESTBL;
- }
- public String getBPSTBL() {
- return BPSTBL;
- }
- public void setBPSTBL(String BPSTBL) {
- this.BPSTBL = BPSTBL;
- }
- public int getCOMFORT() {
- return COMFORT;
- }
- /**
- * Creates a new instance of java
- */
- public void setCOMFORT(int COMFORT) {
- this.COMFORT = COMFORT;
- }
- private String LCORE;
- private String LSURF;
- private String LO2;
- private String LBP;
- private String SURFSTBL;
- private String CORESTBL;
- private String BPSTBL;
- private int COMFORT;
- public Classify() {
- }
- public void classify() throws Exception
- {
- FacesContext context = FacesContext.getCurrentInstance();
- Classifier cl = (Classifier) weka.core.SerializationHelper.read("d:\\weka\\model.model");
- // CREATE NOMINAL VALUES
- ArrayList<String> cls = new ArrayList<>();
- cls.add("I");
- cls.add("S");
- cls.add("A");
- ArrayList<String> hml = new ArrayList<>();
- hml.add("high");
- hml.add("mid");
- hml.add("low");
- ArrayList<String> egfp = new ArrayList<>();
- egfp.add("excellent");
- egfp.add("good");
- egfp.add("fair");
- egfp.add("poor");
- ArrayList<String> smu = new ArrayList<>();
- smu.add("stable");
- smu.add("mod-stable");
- smu.add("unstable");
- //CREATE ATTRIBUTES
- Attribute lcore = new Attribute("L-CORE",hml);
- Attribute lsurf = new Attribute("L-SURF",hml);
- Attribute lo2 = new Attribute("L-O2",egfp);
- Attribute lbp = new Attribute("L-BP",hml);
- Attribute surfstbl = new Attribute("SURF-STBL",smu);
- Attribute corestbl = new Attribute("CORE-STBL",smu);
- Attribute bpstbl = new Attribute("BP-STBL",smu);
- Attribute comfort = new Attribute("COMFORT");
- Attribute admdecs=new Attribute("ADM-DECS",cls);
- ArrayList<Attribute> attributes = new ArrayList<Attribute>();
- attributes.add(lcore);
- attributes.add(lsurf);
- attributes.add(lo2);
- attributes.add(lbp);
- attributes.add(surfstbl);
- attributes.add(corestbl);
- attributes.add(bpstbl);
- attributes.add(comfort);
- attributes.add(admdecs);
- Instances dataset = new Instances("Test-dataset",attributes,0);
- double[]values = new double[dataset.numAttributes()];
- values[0]=hml.indexOf(LCORE);
- values[1]=hml.indexOf(LSURF);
- values[2]=egfp.indexOf(LO2);
- values[3]=hml.indexOf(LBP);
- values[4]=smu.indexOf(SURFSTBL);
- values[5]=smu.indexOf(CORESTBL);
- values[6]=smu.indexOf(BPSTBL);
- values[7]=COMFORT;
- values[8]=0;
- for(double a : values)
- {
- System.out.print(a+" ");
- }
- System.out.print("\n");
- Instance inst = new DenseInstance(1.0,values);
- dataset.add(inst);
- System.out.println("$$$$$$$$$"+" "+(dataset.numAttributes()-1));
- System.out.println(LCORE+" "+LSURF+" "+LO2+" "+LBP+" "+SURFSTBL+" "+CORESTBL+" "+BPSTBL+" "+COMFORT);
- dataset.setClassIndex(dataset.numAttributes()-1);
- /* Instances nowy=new Instances(dataset);
- double t = cl.classifyInstance(dataset.instance(0));*/
- //////////////////////
- Instances nowy=new Instances(dataset);
- for(int i=0; i<nowy.numInstances();++i)
- {
- double clsLAbel=cl.classifyInstance(dataset.instance(i));
- System.out.println("$$$$$$$$$"+" "+clsLAbel);
- nowy.instance(i).setClassValue(clsLAbel);
- }
- // TODO output your page here
- Instance x=nowy.instance(0);
- String wynik1 = Double.toString(x.value(admdecs));
- ///////////////////////
- String wynik="";
- switch((int)x.value(admdecs))
- {
- case 0:
- wynik="Pacjent wysłany na intensywną terapie (klasyfikcja: I)";
- break;
- case 1:
- wynik="Pacjent zwolniony do domu (klasyfikcja: S)";
- break;
- case 2:
- wynik="Pacjent wysłany do szpitlnych sal (klasyfikcja: A)";
- break;
- }
- // TODO output your page here
- context.addMessage(null, new FacesMessage(wynik));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement