Hot answers tagged

9

Welcome to the community! You can replace your code by the following code. double[] prediction=classifier.distributionForInstance(instance); for (int k<prediction.length; k++){ System.out.println("Probability of class "+ trains.classAttribute().value(k)+ " : "+Double.toString(prediction[k])); } This loop prints all the four ...


8

This is a bit off topic for this SE, or maybe opinion-based, but, I work in this field and I'd recommend Scala. No I would not characterize Scala as a "stats-oriented" Java. I'd describe it as what you get if you asked 3 people to design "Java 11" and then used all of their ideas at once. Java 8 remains great, but Scala fully embraces just about all the ...


8

Welcome to the community. You can use the following code: import weka.filters.supervised.instance.SMOTE; import weka.core.Instances; import weka.core.converters.ConverterUtils.DataSource; import weka.filters.Filter; Instances data = DataSource.read(".../file.arff"); //Dataset SMOTE smote=new SMOTE(); //create object of SMOTE smote.setInputFormat(data); ...


7

I work with python and java in big-data settings every day. python is definitely my language of choice when researching, experimenting and fitting models. python has a ton of very useful libraries such as spacy, nltk and sklearn that makes exploration very easy, especially in within a jupyter notebook. When running the code in production, If performance is ...


7

You can try the following code. import weka.core.converters.ConverterUtils.DataSource; import weka.filters.unsupervised.attribute.StringToWordVector; import weka.core.Instances; Instances data = DataSource.read(".../document.txt"); //Your document . filter.setInputFormat(data); StringToWordVector filter = new StringToWordVector(); filter.setStopwords(new ...


7

First of all you have to prepare a text file for your custom stopwords. Then you can use the following code: import weka.filters.unsupervised.attribute.StringToWordVector; StringToWordVector filter = new StringToWordVector(10000); filter.setStopwords(new File(".../stopwords.txt")); Hope it will help you.


6

To calculate TPR and FPR for different threshold values, you can follow the following steps: First calculate prediction probability for each class instead of class prediction. Sorting the testing cases based on the probability values of positive class (Assume binary classes are positive and negative class). Then set the different cutoff/threshold values ...


4

The OP asks two different questions: (1) how to extract key words and (2) how to assign keywords a sentiment class (pos/neg/neu). I will address the keyword identification piece in this answer as many others have discussed how to do sentiment analysis (e.g., this post). The approach I would suggest is a key keyword approach advocated by Mike Scott (author ...


4

There is an overloaded sort method in java.util.Arrays class which takes two arguments: the array to sort and a java.util.Comparator object. You can add the following lines of code with your program to get the expected result. import java.util.Arrays; import java.util.Comparator; Arrays.sort(testdatset, new Comparator<double[]>() { @...


3

Data intensity is a critical factor, but that factor alone is not sufficient to choose a programming language. Please go through this article from your use case perspective and you can more easily evaluate Python with Java: https://togglebrains.wordpress.com/2017/11/05/select-programming-language-for-machine-learning/


3

In the Weka explorer, go to the classify tab and train/test your algorithm. The result buffer appears in the bottom left box under the section labeled "result list" Right click the result buffer and click visualize threshold curve, then select the class you want to analyze to save the ROC curve as an image, hold shift + alt and left click on the graph


3

The other side of the coin: I don't have an extensive experience with Scala; I have written approximately 10,000 lines of Scala code. However, consider that Scala code is often much shorter than its rough equivalent of 40,000 lines of Java. On short I don't like Scala at all. I love it's goals, it's ideas but for production use I consider the ...


3

One needs to use an artificial intelligence (AI) API, if there is a need to add AI functionality to a software application - this is pretty obvious. Traditionally, my advice on machine learning (ML) software includes the following two excellent curated lists of resources: this one and this one. However, keep in mind that ML is just a subset of AI domain, so ...


2

Short answers Tooling. Python has fantastic math, statistics, and linear algebra libraries. Less Code, Same Result. Python provides quick and simple ways of achieving programming solutions compared to C#, Java, C++, etc. This means you'll write less code and achieve the same result.


2

If you're just looking to rank documents according to how many appearances your words w1,..,wn contain, then there's no need for clustering or machine learning in general: Clustering your 50 results will give you a partition of these results into clusters containing results that are similar to one another and different from the results in other clusters. ...


2

The two languages have pretty similar benefits since Scala can call Java libraries. So Java machine learning packages like Weka (http://www.cs.waikato.ac.nz/ml/weka/), can in theory be easily used with Scala. There are minor pros and cons to each, however: Java is a language that most software engineers with 5+ years of experience understand. If you go to ...


2

You could convert your decision tree model to the PMML format. In Java you could use JPMML to parse/read the model and predict.


2

Many neural network examples you see in the literature are doing classification problems, E.g. LeNet, AlexNet, Inception, etc are all image classification problems. In this domain, it's useful for the neural network to give outputs between 0 and 1 because an output between 0 and 1 can be interpreted, in some sense, as a probability. The reason these networks ...


2

Is sounds like you want to use Neural Networks to do a regression problem instead of classification. This post gives an example of using a neural network to do regression.


2

Giving you some links which have worked: deploying-keras-deep-learning-models-with-java : this uses DeepLearning4J, ND4J which supposedly you have tried already. tensorflow-keras-java And same question is asked here - converting-keras-in-python-to-java . It uses KerasModelImport.importKerasSequentialModelAndWeight You should give HDF5 file operation ...


2

I'm not too familiar with PMML, but probability calibration (or at least, the most well-known methods, Platt scaling and isotonic regression) can be viewed as a stacked ensemble, with the output of your model being fed into a univariate regression model. PMML appears to support ensembling; see the fourth example at http://dmg.org/pmml/v4-3/MultipleModels....


2

When it comes to picking a language for a certain application, many factors may play a role: Who will be building/maintaining the application and are they familiar with that language? What other systems will the application need to communicate with and is one language easier to do that with than the other? Is this project experimental or is it supposed to ...


1

It is work good, thanks a lot.There are some correction: //Dont forget create new Instance for prediction. DenseInstance newinstance = new DenseInstance(2); double[] prediction=classifier.distributionForInstance(newinstance); //Some correction in for for (int k =0; k<prediction.length; k++){ System.out.println("...


1

train.py code: builder = tf.saved_model.builder.SavedModelBuilder("/home/datam/cnn-text-classification-tf/model/20180423") builder.add_meta_graph_and_variables( sess, [tf.saved_model.tag_constants.SERVING], clear_devices=True ) builder.save() Java Coding: SavedModelBundle model = SavedModelBundle.load(SAVED_MODEL_PATH+"/20180423", "serve"); ...


1

I took an introductory computer science course on Coursera a few years back where we had to use a Monte Carlo algorithm to build a tic-tac-toe AI. Instead of using historical data, we generated data using a function that would play through a series of games with random moves, but I think the principle is basically the same. Each square on the board has a ...


1

Recurrent neural network may fit your needs. Read about LSTM & GRU , which has been implemented into various NN libraires. Here is the link to the keras documentayion of RNN : https://keras.io/layers/recurrent/ Some interesting music project that takes advantage of RNN : https://github.com/tensorflow/magenta https://github.com/jisungk/deepjazz


1

One easy solution is to prepare a emotion dictionary first. Such dictionary can be found online easily such as http://www.psychpage.com/learning/library/assess/feelings.html. A simple workflow will be as follow: For each tweet, tokenize the tweet into a list of vocabularies For each list of vocabularies, count the (positive, neutral, negative) words ...


1

I'm sorry I'm not a Java user and I never worked with StanfordNLP. But I do know that the gini impurity criterion with and without decision tree were successfully applied for text classification. Moreover these tools have the ability to let you easily understand which features ( i.e. words in your case) contribute to the decision. I know that ...


1

Supervised vs. Unsupervised Learning You will first need to decide whether to approach this as a supervised or unsupervised learning problem. For supervised learning, you would need to take some portion of the data and hand score it as harsh/aggressive and normal. I suggest you not go this route to start. But if you do, I suggest using a support vector ...


1

Should I choose cluster based / density based approach? Yes, but depends on how good the algorithm is, and how effectively is the algorithm identifying important clusters. There is a lot of literature where people have taken the clustering approach. If I were to go with the clustering approach, I would go with the hierarchical clustering technique, cause ...


Only top voted, non community-wiki answers of a minimum length are eligible