Created
October 4, 2019 10:13
-
-
Save naxty/e680c74d272e9d4ef2a7148f24ba868c to your computer and use it in GitHub Desktop.
Boston features handler for cortex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel | |
import numpy as np | |
class HousingFeatures(BaseModel): | |
CRIM: float | |
ZN: float | |
INDUS: float | |
CHAS: float | |
NOX: float | |
RM: float | |
AGE: float | |
DIS: float | |
RAD: float | |
TAX: float | |
PTRATIO: float | |
B: float | |
LSTAT: float | |
def to_numpy(self): | |
return np.array( | |
[ | |
self.CRIM, | |
self.ZN, | |
self.INDUS, | |
self.CHAS, | |
self.NOX, | |
self.RM, | |
self.AGE, | |
self.DIS, | |
self.RAD, | |
self.TAX, | |
self.PTRATIO, | |
self.B, | |
self.LSTAT, | |
] | |
).astype(np.float32) | |
class PredictionResult(BaseModel): | |
predicted: float | |
def pre_inference(sample, metadata): | |
return HousingFeatures(**sample).to_numpy() | |
def post_inference(prediction, metadata): | |
return PredictionResult(**{'predicted': prediction[0][0]}).dict() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment