datatypes

Continuing the discussion from FAQ: Multiple Linear Regression - Multiple Linear Regression: Scikit-Learn:

In this exercise, for this variable: sonny’s_apartment = [[1, 1, 620, 16, 1, 98, 1, 0, 1, 0, 0, 1, 1, 0]]
what datatype is this? I think its a list but im not sure because of the double brackets.

When in doubt, use type to find out. For pure Python [[1, 2, 3]] for example would be a list which contains a single element, that single element is itself a list containing three elements.

lst = [[1, 2, 3,],]
print(len(lst))  # Out: 1
print(lst[0])  # Out: [1, 2, 3,]
print(type(lst))  # Out: <class 'list'>
print(type(lst[0]))  # Out: <class 'list'>

I can’t see the full context but are you perhaps feeding that data to something that takes multiple sequences as arguments?

Hi,
For this exercise we had to feed that list into this statement ( where mlr is the multiple linear regression object) :

price_sonny_apartment = mlr.predict([ [1, 1, 620, 16, 1, 98, 1, 0, 1, 0, 0, 1, 1, 0] ])

When I run the above statement using only one bracket for the list it says :

ValueError: Expected 2D array, got 1D array instead: array=[ 1 1 620 16 1 98 1 0 1 0 0 1 1 0].

So I’m confused about what type of argument the predict method would take? Also, what does that Error message mean?

Jumping in here… If the member has skipped the Learn Python 3 track, then it would be advisable to pause this course, and embark on that course in the fullest possible way. Things that trip us up in this course often trace back to missing aspects that will be well covered in those lessons. Highly suggested segue, at this time.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.