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)