

I don't see how this could be due to mismatch of sizes of array of X_train because each element of X_train is a list of 1024 normalized pixel values and each element of y_train corresponds to a list of 14 attributes. ValueError: setting an array element with a sequence. > 373 array = np.array(array, dtype=dtype, order=order, copy=copy) > 150 X = check_array(X, accept_sparse='csr', dtype=np.float64, order='C')Ĭ:\Users\user\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) ValueError: setting an array element with a sequence. So you should refactor your cost function to accept 1d arrays as a first argument. So on a second iteration fmin passes a 1D array (thats how it supposed to work) and the result becomes non-scalar. ValueError Traceback (most recent call last)Ĭ:\Users\user\Anaconda3\lib\site-packages\sklearn\svm\base.py in fit(self, X, y, sample_weight)ġ48 self._sparse = sparse and not callable(self.kernel) The reason is that the starting point (initialtheta) you gave to fmin is not a 1D array but a 2D array. Resized_imgs = cv2.resize(images,(32,32)) #Resizing images Images = cv2.imread(join(mypath,k),0) #Reading images in grayscale Resized_imgs = np.empty((len(k)-1),dtype=object) df A, B, C minmaxscaler. Images = np.empty((len(k)-1), dtype=object) I always get this error 'ValueError: setting an array element with a sequence'. Im using minmaxscaler.fittransform () to rescale each column in the Dataframe - df. Is there any other way to solve this problem? Think.I'm trying to do image classification using SVM in python with 1022 images and 1022 multi-class labels (each label has 14 classes). Why incrementing the loop by 2 help to reduce the total number of comparsion ? Why min and max are initialized differently for even and odd sized arrays? Time Complexity is O(n) and Space Complexity is O(1).įor each pair, there are a total of three comparisons, first among the elements of the pair and the other two with min and max. 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. By convention, we assume ans as max and ans as min
Setting an array element with a sequence rd.fit update#
We initialize both minimum and maximum element to the first element and then traverse the array, comparing each element and update minimum and maximum whenever necessary. Searching linearly: Increment the loop by 1 Searching linearly: Increment the loop by 1Ĭomparison in pairs: Increment the loop by 2ġ. You need to decrease the number of comparisons as much as you can. The bottleneck parameter in this problem is the number of comparisons that your algorithm requires to determine the maximum and the minimum element. Id like to train data given df X and Y X is feature while Y is target variable.

The interviewer would not judge your algorithm for this question based on the time complexity as all solution has the time complexity of O(n). ValueError: setting an array element with a sequence when clf.fit. No, they can be positive, negative, or zero)Īre the array element sorted ? (Ans: No, they can be in any order)

Possible follow-up questions to ask the interviewer :-Īre the array elements necessarily positive? ( Your algorithm should make the minimum number of comparisons. For instance, programmers and developers face this issue when a built-in function or operation gets an argument with the correct type and invalid value. Given an array A of size n, you need to find the maximum and minimum element present in the array. The valueerror: setting an array element with a sequence fromiter happens due to different array dimensions and shapes inside the syntax.
