0

I'm running into a weird issue with some linear regression stuff from sklearn. Specifically, linear_model.

I'm trying to do some basic machine learning, and so I have a part of my script that combs through my data and extracts features into a list (of lists) X, and then another part that feeds those features into the fit function. So I've got (roughly)

from sklearn import linear_model
X, y = extractFeaturesFromData(data,numfeatures)   # my homemade function
reg = linear_model.LinearRegression()
reg.fit(X,y)

When I run this, I get (along with the traceback)

ValueError: setting an array element with a sequence.

The example here ran fine. And the X and y that extractFeaturesFromData returns are of type 'list', same as in the example. If I use the dummy X and y from the example page, it works fine, but using mine causes it to throw an error.

I've tried varying the number of features extracted into X, and printing out the X and y returned from my function (which shows them to be the same format as their dummy counterparts from the example), but haven't had any luck so far. I'm running python 2.7 on a macbook running 10.9.5. Any idea why this might be happening? Any help would be much appreciated.

2
  • can you show us your X and y ?
    – MMF
    Oct 8, 2016 at 11:55
  • Actually, I figured out the issue: one of the files I was importing was too large, and I think it was being automatically segmented into an array of several files. Removing that one caused everything to work fine.
    – macinblack
    Oct 9, 2016 at 19:22

1 Answer 1

0

Figured it out! It was completely unrelated to my code itself; one of the files that I was importing was a good bit larger than the others, and (I think) was being automatically split into an array, causing the error. Removing that file made everything run fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.