Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. from pydantic import BaseModel
  2.  
  3. import numpy as np
  4.  
  5.  
  6. class HousingFeatures(BaseModel):
  7. CRIM: float
  8. ZN: float
  9. INDUS: float
  10. CHAS: float
  11. NOX: float
  12. RM: float
  13. AGE: float
  14. DIS: float
  15. RAD: float
  16. TAX: float
  17. PTRATIO: float
  18. B: float
  19. LSTAT: float
  20.  
  21. def to_numpy(self):
  22. return np.array(
  23. [
  24. self.CRIM,
  25. self.ZN,
  26. self.INDUS,
  27. self.CHAS,
  28. self.NOX,
  29. self.RM,
  30. self.AGE,
  31. self.DIS,
  32. self.RAD,
  33. self.TAX,
  34. self.PTRATIO,
  35. self.B,
  36. self.LSTAT,
  37. ]
  38. ).astype(np.float32)
  39.  
  40.  
  41. class PredictionResult(BaseModel):
  42. predicted: float
  43.  
  44.  
  45. def pre_inference(sample, metadata):
  46. return HousingFeatures(**sample).to_numpy()
  47.  
  48.  
  49. def post_inference(prediction, metadata):
  50. return PredictionResult(**{'predicted': prediction[0][0]}).dict()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement