![]() Without getting into details, I can see why it would complain a setting with a sequence - the sequence being the array. ValueError: setting an array element with a sequence. ValueError: setting an array element with a sequence. So X is a (29,2) array of dtypeobject, and one of the elements (2nd column) is itself an an array. Return array(a, dtype, copy=False, order=order) X_2d = np.asarray(np.atleast_2d(X), dtype=dtype, order=order)įile "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 320, in asarray X = atleast2d_or_csr(X, dtype=np.float64, order="C")įile "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 134, in atleast2d_or_csrįile "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 111, in _atleast2d_or_sparseįile "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 91, in array2d I get error: Traceback (most recent call last):įile "D:/Users/jures/Desktop/logisticRegression.py", line 45, in įile "C:\Python27\lib\site-packages\sklearn\svm\base.py", line 668, in fit Intercept_scaling=1, penalty='l2', random_state=None, tol=0.0001) Logreg = linear_model.LogisticRegression(C=1.0, class_weight='auto', dual=False, fit_intercept=True, The following is my code, adapted from the example on the scikit-learn website: data = If i try 3mio data the i get this exception But on 23 examples i didn't get this exception. Is there any other way to solve this problem? Think.I want to predict if user click on link or not. 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. By convention, we assume ans as max and ans as min 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ġ. I am trying to call scikit learn fit functions on dataframes where the elements of each column are numpy arrays. 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. Solution The solution of this is straightforward if you need either you declare only floating numbers inside an array or if you want both, then make sure that you change the dtype as an object instead of float as shown below. 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). 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? ( Classification test in Scikit-learn, ValueError: setting an array element with a sequence 31 ValueError: setting an array element with a sequence. For example: import numpy as np arr np.array( 1,2, 1,2,3, dtypeint) print(arr) Output: ValueError: setting an array element with a sequence. Your algorithm should make the minimum number of comparisons. One of the main causes for the ValueError: setting array element with a sequence is when you’re trying to insert arrays of different dimensions into a NumPy array. ![]() Given an array A of size n, you need to find the maximum and minimum element present in the array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |