How do I use WEKA for the actual training and classification (Openshift) - music genre classification [CODE]?
-
Hello, I am struggling to actually implement the classifying part of my investigations into the possibility of classifying music according to some features of music files. What I have currently produced is code that reads a table of features from the DB and then puts it back into the DB in another table. The problem ist that I do not know how to work with the instances type. Documentation is crap - I have no clue what to do. ========= What I want to do: I want to use a given set of music files and compute their feature vectors. After this data has been put into arff, I would manually join it with genre data (the gial i.e.). and then save it into a mysql table. AFAIU the chain should be like this: a) Read from DB b) somehow (?) train a K-nearest neighbor classifier on a set of the features (relted to genre) per music file for a body of 10 files. c) use this to classify a set of files with the same features but unknow genre. d) somehow (?) output results so that they can be machine-readable in the DBase I have found no examples of the output of the data actually being used for furhter processing so I cannoct further haggle :/ == Code == After this has been done, I would like to read it back and conduct a classification on a new body of music (the features I have computed by musicg or useingf a sapmple file set). The results should be put back into the DB in yet another new table, detailing what file has which vetegory (assigned). Here is my code: package org.tuhh.cpmgg.weka; import weka.core.*; import weka.core.converters.*; import weka.experiment.InstanceQuery; import http://java.io.*; import java.util.ArrayList; import http://javax.ws.rs.GET; import http://javax.ws.rs.Path; import http://javax.ws.rs.Produces; import http://javax.ws.rs.core.MediaType; @Path("/weka2") public class weka_chain { /** * loads a dataset from mysql db * @param args the commandline arguments */ @GET @Produces(MediaType.TEXT_PLAIN) public String main() throws Exception { java.util.List resultList; /*Gets data from DB*/ InstanceQuery query = new InstanceQuery(); query.setDatabaseURL("jdbc:mysql://127.2.73.130:3306/cpmgg"); query.setUsername("adminnNWqHkW"); query.setPassword("zLlkWsd-NsnQ"); query.setQuery("SELECT * FROM features"); //Read table Instances data = query.retrieveInstances(); //into data data.setClassIndex(data.numAttributes() - 1); //sets the number of classes (creates index) /*Classifiers */ String algorithm = "weka.classifiers.bayes.NaiveBayes"; // Sets the type of classifier (many available) resultList = new ArrayList(); Weka1 weka; try { weka = new Weka1(algorithm, "lol"); resultList = weka.weka(algorithm, data); //Essentially what is happening /* TODO: * Define Output so that it is in table form/instance form * This means creating output using the old applet and somehow (?) distilling it into table shape */ /* Saves Results to DB */ DatabaseSaver save = new DatabaseSaver(); // save.setUrl("jdbc:mysql://localhost:3306/weka_test"); save.setUrl("jdbc:mysql://127.2.73.130:3306/cpmgg"); //save.setUrl("jdbc:mysql://localhost:3306/hibernate"); save.setUser("AMDINADMIN"); save.setPassword("PASS_ PASS"); save.setInstances(data); // define outputtype save.setRelationForTableName(false); save.setTableName("weka_rslts"); save.connectToDatabase(); save.writeBatch(); return "done"; } }
-
Answer:
I believe you have solved the problem using Weka UI already and now trying to implement your own program. Make your db is jdbc compatible.Then follow these links: http://weka.wikispaces.com/Databases http://weka.wikispaces.com/Use+Weka+in+your+Java+code Let me know if you are still stuck. Should be able to guide you further.
Rahul Verma at Quora Visit the source
Related Q & A:
- Where do I find my Yahoo briefcase and how do I use it?Best solution by Yahoo! Answers
- How can I hook my phone up to my car to play music?Best solution by Yahoo! Answers
- How do I use an actual picture for my icon?Best solution by Yahoo! Answers
- How do I use chat when I am in a room?Best solution by Yahoo! Answers
- How do i change my myspace music player back to a single music player?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.