![]() ![]() ![]() Note make sure that Venue Categories column has same number of elements for each row of data, else a new problem will arise again. A numpy array is being created, and numpy doesnt know how to cram multivalued tuples or arrays into single element slots. Train_data,test_data,train_labels,test_labels = train_test_split(data,labels,test_size=0.20) Return np.array( for col in other_features]+categories for i in range(len(categories))]), np.array(df.values)ĭff = labelencoder.fit_transform(dff)ĭata, labels = make_data(dff, 'Venue', 'Venue Categories') As an alternative for onehotencoder from scikit you can use getdummies from pandas and concat it to dataframe i.e. I managed to make it work, by combining the city column with the venue categories column into a 2D (numpy) array which can be used by the RandomForestClassifier of sklearn.įrom sklearn.preprocessing import LabelEncoderįrom sklearn.ensemble import RandomForestClassifierįrom sklearn.model_selection import train_test_splitĭef make_data(df, target_column='Venue', categories_column='Venue Categories'):Ĭategories = df.values Its because the X values are much like 0,0,1,0,2 which aint a correct 2D data and this will lead to Setting an array element with a sequence. This will looks weird, I want to make it global, means there should not need to touch the code if we may increase the number of columns. I want to add more columns, then I again write everything for each feature just like shown below, if i want to add type column and owner column city = dff.valuesĬategories = dff.valuesĭata = np.array(, owner, type categories) for i in range(len(city))]) One of the main causes for the ValueError: setting array element with a sequence is when youre trying to insert arrays of different dimensions into a NumPy. Let's say, if I want to increase the number of features. During programming, there will be instances when you will need to convert existing lists to arrays in order to perform certain operations on them (arrays. Creates an array containing the elements of a sequence. I am passing this data to my machine learning model, but model.fit is not accepting the input, My code is shown below, that I am trying, labelencoder = LabelEncoder()ĭff=labelencoder.fit_transform(dff) newSeqT for creating new sequences of type T for converting arrays and strings to sequences add for adding new elements to strings and sequences. You can create an empty array by specifying the Element type of your array. WaterFront Austria Īeronaut Marvilles Īeronaut Paris I have the columns in my Data Frame as shown below: Venue city Venue Categories ValueError: setting an array element with a sequence- Anndata object Ask Question Asked today Modified today Viewed 3 times 0 I have an anndata object, and I am trying to reassign the raw counts to the X layer of the anndata object using this code: adata2.X adata2.layers 'counts'.copy () adata2. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |