2

I want to predict for each row in the dataframe by iterating through the rows.

I have tried the solution mentioned in Row-wise prediction over Pandas dataframe by passing sklearn.predict to df.apply but this is only for a single row.

Here's a snippet of what I've so far tried.

prediction = X_test.apply(lambda x: model.predict([x])[0],axis=1)
predictions = [round(value) for value in prediction]

accuracy = accuracy_score(Y_test, predictions)
print("Test Accuracy: %.2f%%" % (accuracy * 100.0))

I want to be able to loop this code for all present rows.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
prai
  • 39
  • 3
  • 1
    did you try `prediction = model.predict(X_test)`? – Quang Hoang Aug 01 '19 at 20:42
  • @QuangHoang I want to save the prediction for each row. Using model.predict(X_test) won't help with that – prai Aug 01 '19 at 20:44
  • 1
    for a general `sklearn` model, `model.predict(X_test)` does give prediction for each row. – Quang Hoang Aug 01 '19 at 20:48
  • @QuangHoang Sorry for being unclear, but my end goal is to predict time taken for prediction of each row. I'm not sure how to do that simply with model.predict(X_test) – prai Aug 01 '19 at 20:56
  • What you wrote there is for *all* rows in `X_test`. What do you mean by *all present rows*? – Quang Hoang Aug 01 '19 at 20:58

0 Answers0