
535
13
장
텐서플로에서 데이터 적재와 전처리하기
import tensorflow_transform as tft
def preprocess(inputs):
# inputs = 입력 특성의 배치
median_age = inputs["housing_median_age"]
ocean_proximity = inputs["ocean_proximity"]
standardized_age = tft.scale_to_z_score(median_age)
ocean_proximity_id = tft.compute_and_apply_vocabulary(ocean_proximity)
return {
"standardized_median_age": standardized_age,
"ocean_proximity_id": ocean_proximity_id
}
그다음 아파치 빔을 사용해 이
preprocess
()
함수를 전체 훈련 세트에 적용할 수 있습니다
(이를 위해
TF
변환은 아파치 빔 파이프라인에서 사용할 수 있는
AnalyzeAndTransformData
set
클래스를 제공합니다 ). 이 과정에서 전체 훈련 세트에 대해서 필요한 모든 통계를 계산합
니다. 이 예에서는
housing
_
median
_
age
특성의 평균, 표준편차와
ocean
_
proximity
특성의
어휘 사전을 ...