![]() ![]() KModel = kmeans.fit(example_animals.data) #fit a model using the training data, in this case original example food data passed throughĬrosstab = pd.crosstab(example_animals.target,KModel. #make numpy array into 1 dimensional array This means if importing pictures, the pictures need to be resized, converted into a numpy array (a format that is compatible with Kmeans) and finally made into a 1 dimensional array. Kmeans requires the data arrays for comparison need to be the same size. I found the solution to error setting an array element with a sequence I would appreciate any insight how I fix the error 'setting an array element with a sequence' so that the images will be compatible with the sklearn processing. If you have a list of lists that you want to convert to a DataFrame, you can use the pd.DataFrame constructor to create a new DataFrame. Monkey = np.asarray(Image.open("monkey.jpg")) To fix the error, you can use the at or iat accessor methods to assign a scalar value to a single cell of the column, or you can use the pd.Series constructor to create a new column from a list or an array. ** 'setting an array element with a sequence'** # The code below where I have converted images to NumPy array doesn't work. I have looked into how to make an image into a NumPy array at KModel = kmeans.fit(example_animals.data) #fit a model using the training data, in this case original example animal data passed throughĬrosstab = pd.crosstab(example_animals.target,KModel.labels_) ![]() Kmeans = KMeans(n_clusters=2) #with KMeans you get to pre specify the number of Clusters ![]() #Įxample_animals = Bunch(data = np.array(),target = np.array()) It works fine when it is a non image NumPy array. I would like the code below to work with classifying images. There is no other way - either rethink representation of your data, or change approach.I am trying to create a simple image classification tool.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |