2D array value error

Hie guys am having this error in my code

Expected 2D array, got 1D array instead:array=[0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0].Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Here’s my code

def sanfrancisco(request):
filename = ‘prediction.sav’
module_dir = os.path.dirname(file)
file_path = os.path.join(module_dir, filename)
model = pickle.load(open(file_path, ‘rb’))
p = [0] * 17
day = ‘Sunday’
place = ‘BAYVIEW’
if day == ‘Friday’:
p[0]= 1
if day == ‘Monday’:
p[1]= 1
if day == ‘Saturday’:
p[2]= 1
if day == ‘Sunday’:
p[3]= 1
if day == ‘Thursday’:
p[4]= 1
if day == ‘Tuesday’:
p[5]= 1
if day == ‘Wednesday’:
p[6]= 1
if place == ‘BAYVIEW’:
p[7] = 1
if place == ‘CENTRAL’:
p[8] = 1
if place == ‘INGLESIDE’:
p[9] = 1
if place == ‘MISSION’:
p[10] = 1
if place == ‘NORTHERN’:
p[11] = 1
if place == ‘PARK’:
p[12] = 1
if place == ‘RICHMOND’:
p[13] = 1
if place == ‘SOUTHERN’:
p[14] = 1
if place == ‘TARAVAL’:
p[15] = 1
if place == ‘TENDERLOIN’:
p[16] = 1
array = model.predict_proba([p])
print ("Probability of Arson: ",(array[0][0])* 100, “%”)
return HttpResponse(array[0][0]*100)

Hi Snook,

Okay, you got an error. Did you follow the instructions given in the
error message?

I tried am still having the same error can you help me please

Okay, you tried to reshape the array. Did it reshape to what you expect?
How did you reshape it?

Can I mail you my code bro it’s machine learning project I’ve spent 2momths and I haven’t solved the error

You don’t have to email me your code. It is one line of code to
reshape the array. Did you try it?

The error message gives two suggestions.

“Reshape your data either using array.reshape(-1, 1) if your data has a
single feature or array.reshape(1, -1) if it contains a single sample.”

It’s your data, you should know which is the relevant case. Does it have
a single feature, or a single sample?

(I don’t know what that means. I’m not an expert on machine learning.)

If you don’t know, because you are a student, you should ask your
teacher, lecturer or tutor to explain the difference.

Or you could just try both versions:

>>> from numpy import array
>>> a = array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> b = a.reshape(-1, 1)
>>> c = a.reshape(1, -1)

Now try applying the model to b and c and see what happens. If it works
with b but not c, or c but not b, then you know what you need to do.