Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: LoadError: MethodError: getindex has no method matching getindex(:DataFrames.DataFrame, :: ASCIIString) #13782

Closed
DaronAyer opened this issue Oct 26, 2015 · 6 comments

Comments

@DaronAyer
Copy link

Below after the line of ****'s is the I am trying to run. It is a tutorial from the Kaggle website dealing with character recognition. I am getting an error when I try to run this:

xTrain = read_data("train", labelsInfoTrain, imageSize, path)

portion of the code. The error seems to be the result of a conflict between Images and DataFrames, the error occurs when the above portion of the code gets to this part:

for (index, idImage) in enumerate(labelsInfoTrain["ID"])

and then I get the error:

Error: LoadError: MethodError: `getindex` has no method matching getindex(::DataFrames.DataFrame, :: ASCIIString)

Look forward to hearing about this


#Install required packages
Pkg.add("Images")
Pkg.add("DataFrames")
using Images
using DataFrames


#typeData could be either "train" or "test.
#labelsInfo should contain the IDs of each image to be read
#The images in the trainResized and testResized data files
#are 20x20 pixels, so imageSize is set to 400.
#path should be set to the location of the data files.

function read_data(typeData, labelsInfo, imageSize, path)

#Intialize x matrix
 x = zeros(size(labelsInfo, 1), imageSize)

 for (index, idImage) in enumerate(labelsInfoTrain["ID"])
  #Read image file
  nameFile = "$(path)/$(typeData)Resized/$(idImage).Bmp"
  img = imread(nameFile)
  #Convert img to float values
  temp = float32sc(img)
  #Convert color images to gray images
  #by taking the average of the color scales.
  if ndims(temp) == 3
   temp = mean(temp.data, 1)
  end
  #Transform image matrix to a vector and store
  #it in data matrix
  x[index, :] = reshape(temp, 1, imageSize)
 end
 return x
end
imageSize = 400 # 20 x 20 pixels

#Set location of data files , folders
path = "C:\\Users\\Aaron\\Downloads\\Math512Project"

#Read i
labelsInfoTest = readtable("$(path)/sampleSubmissionJulia.csv")

#Read test matrixnformation about training data , IDs.
labelsInfoTrain = readtable("$(path)/trainLabels.csv")

#Read training matrix
xTrain = read_data("train", labelsInfoTrain, imageSize, path)

#Read information about test data ( IDs ).
labelsInfoTest = readtable("$(path)/sampleSubmissionJulia.csv")

#Read test matrix
xTest = read_data("test", labelsInfoTest, imageSize, path)

#Get only first character of string (convert from string to character).
#Apply the function to each element of the column "Class"
yTrain = map(x -> x[1], labelsInfoTrain["Class"])

#Convert from character to integer
yTrain = int(yTrain)

Pkg.add("DecisionTree")
Pkg.build("DecisionTree")
using DecisionTree

#Train random forest with
#20 for number of features chosen at each random split,
#50 for number of trees,
#and 1.0 for ratio of subsampling.
model = build_forest(yTrain, xTrain, 20, 50, 1.0)

#Get predictions for test data
predTest = apply_forest(model, xTest)

#Convert integer predictions to character
labelsInfoTest["Class"] = char(predTest)

#Save predictions
writetable("$(path)/juliaSubmission.csv", labelsInfoTest, separator=',', header=true)

#Run 4 fold cross validation
accuracy = nfoldCV_forest(yTrain, xTrain, 20, 50, 4, 1.0);
println ("4 fold accuracy: $(mean(accuracy))")
@yuyichao
Copy link
Contributor

This is a user question about packages that should go to the julia-user mailing list.

I've never used the DataFrames package but a breif look at it suggests that you might want to index it with a symbol instead of a string i.e. lablesInfoTrain[:ID].

P.S. Please quote your code so that it's easier to tell them from your comments.

@tkelman
Copy link
Contributor

tkelman commented Oct 27, 2015

ref https://groups.google.com/forum/?nomobile=true#!topic/julia-users/NISyks0j7gw

Try not to double post in different places. Mailing list should be first place to go with questions. If someone responds with a "yes that looks like a bug, please open an issue with a cross-reference link back to this thread" then it's okay, but that happens in a small subset of posts.

@DaronAyer
Copy link
Author

Hi Tony,

Sorry for contacting you directly. I am new to this kind of thing. I
believe i posted my problem in the correct area, this is the Julia-users,
thread. Now do i wait until someone can help me ?

On Mon, Oct 26, 2015 at 9:46 PM, Tony Kelman [email protected]
wrote:

ref
https://groups.google.com/forum/?nomobile=true#!topic/julia-users/NISyks0j7gw

Try not to double post in different places. Mailing list should be first
place to go with questions. If someone responds with a "yes that looks like
a bug, please open an issue with a cross-reference link back to this
thread" then it's okay, but that happens in a small subset of posts.


Reply to this email directly or view it on GitHub
#13782 (comment).

Aaron Dyer
University of Delaware '15
Bachelors of Arts in Mathematics
Career Ambassador Program President

@johnmyleswhite
Copy link
Member

Daron, you need to use a symbol instead of a string, so replace labelsInfoTrain["ID"] with labelsInfoTrain[:ID].

In the future, usage questions like this should really go to StackOverflow or the julia-users Google Group. If you're unfamiliar with either, you should start using StackOverflow for a few months. They're a very supportive community who have the resources to help get you on track. We unfortunately don't have enough people with free time on their hands to answer most usage questions.

@DaronAyer
Copy link
Author

Hi John,
My team and I have tried your suggestion multiple times and doing so it causes another error in our code at this portion:

xTrain = read_data("train", labelsInfoTrain, imageSize, path)

The error reads:

imread not defined
in read_data at rf_julia_benchmark.jl:21

any suggestions

@johnmyleswhite
Copy link
Member

Please post all questions to StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants