![]() I am trying to use sklearn regression within my cost function, but that seems to. However, I want to know why it is not working when I use the same strategy as the tutorial and how to get it to work in a similar fashion.Īny help would be much appreciated. ValueError: setting an array element with a sequence. ![]() Python: 'ValueError: setting an array element with a sequence' when using sklearn. immatrix is an array holding image matrices: for file in files: path os.path.join(root, file) immatrix.append (mpimg.imread. When I replace the line clf.fit(train, labels) with clf.fit(vectors_train, labels), the error goes away. ValueError: setting an array element with a sequence. Logistic regression is an estimator for functions of form: Rd -> 0,1 But your data clearly is not a subset of Rd, as each sample in a has different length (number of dimensions), thus it cannot be applied. labels is an array, and the error specifically points to the first parameter being the problem, so is there a data type conversion I have to do? What array element is being set to a sequence, and where is this sequence? I'm also aware that train is a DataFrame object, and that the fit() function takes in two parameters, both of which must be array-like. I am confused by what the error actually means. The detected shape was (2,) + inhomogeneous part. The requested array has an inhomogeneous shape after 1 dimensions. Labels_train, uniques = pd.factorize(train, sort = True)Ĭlf.fit(train, labels) # Value error occurs here ValueError: setting an array element with a sequence. Train, test = dataframe=True], dataframe=False] An array, any object exposing the array interface, an object whose array method returns an array, or any (nested) sequence. ![]() TestingData =, 0.77],, 30],, 0.77],, 0.77]]ĭataframe_training = pd.DataFrame(trainingData)ĭataframe_testing = pd.DataFrame(testingData)įrames = ĭataframe.rename(index = str, columns = ) ValueError: setting an array element with a sequence.įrom sklearn.ensemble import RandomForestClassifierįrom trics import confusion_matrix Without getting into details, I can see why it would complain a 'setting with a sequence - the sequence being the array. When I call the fit() function, I get the following error: So X is a (29,2) array of dtypeobject, and one of the elements (2nd column) is itself an an array. In my code, I have 1 feature (1 column in the data table), and each entry in a column is a numpy array. In the tutorial, there are 4 features (4 columns in the data table), and each entry in a column is a number. My code follows this tutorial line by line, but the only major difference is the structure of the data. similaritymatrix cosinesimilarity (downsamplematrix) plt.matshow (similaritymatrix) plt. I have been using this tutorial as a guide. As part of a project, I am trying to use the random forest classifier from Python's SKLearn library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |