view.py
def output(request):
dff = pd.read_csv(r'C:\Users\Downloads\data.csv')
y = dff['diagnosis'].values
x = dff.drop('diagnosis', axis=1).values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.40)
model = LogisticRegression()
model.fit(x_train, y_train)
v1 = np.array((request.GET['n1']))
pred = model.predict([v1])
pred1 = ""
if pred==[1]:
pred1 = "positive"
else:
pred1 = "negative"
return render(request, 'prediction.html', {"predictResult":**pred1**})
prediction.html
<div>
<form action="output">
<table >
<tr>
<td align="right">Pregnancies</td>
<td align="left"><input type="text" name="n1"></td>
</tr>
</table>
<input type="submit">
</form>
Result:{{ predictResult }}
</div>
How to feed 30 comma sepetared values into this code v1 = np.array((request.GET[‘n1’])) of view.py
I tried above but
** getting error mesage as below**
ValueError at /prediction/output
Expected 2D array, got 1D array instead:
array=[‘17.99,10.38,122.8,1001,0.1184,0.2776,0.3001,0.1471,0.2419,0.07871,1.095,0.9053,8.589,153.4,0.006399,0.04904,0.05373,0.01587,0.03003,0.006193,25.38,17.33,184.6,2019,0.1622,0.6656,0.7119,0.2654,0.4601,0.1189’].
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.