Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def predict_row(row, clf):
  2. """
  3. Transform row to a 1-row pandas.DataFrame and predict
  4.  
  5. When iterating of rows of a DataFrame, each row is represented as a
  6. pd.Series. The classifiers in use are expecting a DataFrame. This function
  7. turns the row into a 1 x n_featurs DataFrame and apply the prediction of a
  8. trained classier.
  9.  
  10. Parameters
  11. ----------
  12. row : pandas.Series
  13. An instance from the data.
  14. clf
  15. Predictor which expects the features which are the index of ``row``
  16. and is already trained
  17.  
  18. Returns
  19. -------
  20. int
  21. Value of the prediction
  22. """
  23.  
  24. return clf.predict(
  25. pd.DataFrame(row).T
  26. )[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement