This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!

Glenda Karen

Ranch Hand
+ Follow
since Oct 02, 2020
Cows and Likes
Cows
Total received
1
In last 30 days
1
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
28
Given in last 30 days
28
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Glenda Karen

Stephan van Hulst wrote:Note that "arrow function" is JavaScript parlance. Java calls them "lambda expressions".

Thank you!!

Paul Clapham wrote:Just to clarify, here's some of your code in a (hopefully) slightly more readable format:


But I still don't understand it. On the left side of .equals you have row.getString("index"). I'm going to assume that returns a String. So the right side should be a String as well, but it's something which tries to iterate over an array of integer values.

From your comments it looks like you have something and you want to match it against that array of integer values. But arrays don't have a convenient "contains" operation. Instead I would use a Set<Integer>:

And then you could filter on indexSet.contains(whatever integer value you get out of your rows).

Note: Set.of() is a Java 9 method so if you're still on Java 8 you'll have to build the Set the hard way.



Thank you! Yes the row.getString("index") is to get the column name in the dataframe, the .equals() gets the row. What I was hoping to do is get the column, which has the name index and then get all the rows that have those numbers in the array, in that column.

When I looked at the dataframe it recognized that index contains ints but when I tried:
it didn't work even though the rows are ints but when I put in "1" like a string it did get back the correct rows. So yes would appear it needs to be a string.

I did find a another way to get the column, which would allow me to use integers for .equals()

Would it be possible to use the lamda expression here to loop through the array? Or can I only use Set.of() in this case as well?
37 minutes ago
I'm using the Smile-Statistical Machine Intelligence and Learning Engine library and I'm trying to get a new dataframe by selecting column and row.
For the row I want to loop though an array and get the rows corresponding to those numbers.


but I'm having some trouble with the forEach loop. I'm wondering how I can properly loop through the indexArray to set the numbers in .equal()

Thanks so much!
12 hours ago

Paul Clapham wrote:Should be


That worked, thanks!

Updated code:


I'm getting a new error:
19 hours ago

Mike Simmons wrote:I think you need to count the parentheses carefully in the mapToInt() line - you have one more '(' than ')'.


Thanks, I added another ")" but still getting same error.
23 hours ago

Piet Souris wrote: You can also do (if it is a joinery dataframe)


Thank you, I am using the joinery, I tried this out and I'm getting:
1 day ago

Mike Simmons wrote:I suspect it would be helpful to find out what class is in that array:


Thanks, so I tried and it's a String

Mike Simmons wrote:


Thank you, maybe for the someMethodToConvert... I can convert to char and use promotion operator as Campbell Ritchie suggested.
1 day ago
Thanks so much everybody for all your help!

Campbell Ritchie wrote:maybe the quickest way to turn it into an int is with the promotion operator.

Thanks, I can look into this.

Campbell Ritchie wrote:Are you aware of the Character#getNumericValue() method?  

No I was not aware, thanks so much, that's a good point, I wasn't thinking about before.

Campbell Ritchie wrote:If you are reading from a text file, I am not sure I would use an array in the first place.


I'm reading from a csv but I presume it's the same as a text file just with comma separation.
1 day ago

Campbell Ritchie wrote:You can treat each of the elements as a one‑letter String and convert that letter to a char, which gives you its Unicode value (not ASCII strictly). But this approach is dependent on the elements of the array having  a particular type; even using a String[] would be horribly error‑prone.


Thanks! So I could convert to a char[] and then to an int[]?

Carey Brown wrote:I think we need more background on what it is that you're actually trying to achieve, perhaps with an example. What kinds of objects do you anticipate that your Object[] will hold?


Ya sorry I can give more of a background.
Basically what I'm trying to do is use the Smile-Statistical Machine Intelligence and Machine Learning Library to use the k-nearest neighbour classifier to make data science predictions.
To use the Knn.fit method, I need the training labels(which is the second argument) to be an int[], however right now my labels are a 1 column dataframe with rows containing a single letter converted to an Object[] so I'm trying to convert to int[] to use in Knn.fit.

For ex.


3 days ago
I have an Obejct[] which is a [Ljava.lang.Object;,

When I use toString():

it returns something that looks like:

I'm wondering how I can convert this to an int[], like each letter would become the corresponding ASCII value.

I did find online a function to convert to numbers but I need a String[] but myString returns as just a String.

So I'm wondering how I could go about the conversion of the Object[] to an int[]?

Thanks so much!
3 days ago
So I have it working now, needed to use append instead of add:

For adding in the column name, I used add like:

Thanks Piet for all your help!
4 days ago
Thanks so much!

Piet Souris wrote:


I tried this out and I mostly got it but the rows are inverted so instead of
I got:


Piet Souris wrote:Second: in another topic I described how you could add a column with the values 0, 1, 2, 3.... Now,having done that, you can do a select on that DataFrame, where you can test in the Predicate if the value in that index column is present in the List of indices.

By the way: using the method 'select' will give you a new DataFrame (see the API), so use it like:


That's great thanks so much, just checked the api and seems like I could do a .get() inside select where it equals the indices. I'm gonna try this out.
4 days ago
Thanks so much! I would definitely use python but I neglected to mention in my previous post that I'm working on a project translating ml python code to java to integrate into a java stack. I was asked specifically to use java but ya otherwise I'd definitely consider using python.
Hi,

I'm wondering if anybody can please suggest a good alternative to scikit-learn for java?

I want to be able to use things like KNeighborsClassifier for knn.fit, knn.predict as well as other scikit learning tools like confusion_matrix, LinearSVC, RandomForestClassifier etc.

Any ideas would be appreciated, thanks so much!
I recently posted about using the joinery library in How to filter a dataframe?

I'm now trying to perform a similar idea to the pandas .loc method which is used to "Access a group of rows and columns by label(s) or a boolean array."

Basically the .loc method can be used by giving an array of indices from one dataframe and returning a new dataframe based on the rows corresponding to the indices given.

For ex. in python pandas:

I'm trying to do something similar in java.
In the joinery library there is a method .row() which gives a row back given an index, however it returns as a list and just displays the row but I need a new dataframe with the column headers as well.

So far I have:


To summarize, I'm trying to get a new dataframe, tallTrain, which is based on the indices from the shortAndTall array.

Thanks so much!
5 days ago