C.W.K.
Stream
Lesson 01 of 05 · published

TF Probability와 TF Decision Forests

~11 min · tfp, tf-df, tabular, uncertainty

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

신경망이 못 하는 걸 잘하는 라이브러리

표준 신경망은 단일 point estimate 출력. Probabilistic model은 분포 출력해서 불확실성 잡아. 의료 진단 (단순히 "종양/아님"이 아닌 신뢰 구간 필요), 금융 예측, 안전 핵심 로보틱스에 결정적.

TensorFlow Probability (TFP)는 분포, bijector (normalizing flow용), MCMC sampler, Bayesian 신경망용 DenseVariational layer 제공.

TensorFlow Decision Forests (TF-DF)는 random forest와 gradient boosted tree를 Keras API에 들여와. Tabular 데이터 (엔터프라이즈 ML에서 가장 흔한 데이터 타입)에선 GBT가 보통 신경망 능가 (수백만 행 없는 한). TF-DF가 Keras 관습, TFX 통합, TF Serving 호환으로 그 힘 줘 — 도구 전환 불필요.

Code

TFP — 분포와 Bayesian NN·python
import tensorflow as tf
import tensorflow_probability as tfp

tfd = tfp.distributions

# Distributions
normal = tfd.Normal(loc=0., scale=1.)
samples = normal.sample(100)
log_prob = normal.log_prob(0.5)

# Mixture of Gaussians
mixture = tfd.MixtureSameFamily(
    mixture_distribution=tfd.Categorical(probs=[0.3, 0.7]),
    components_distribution=tfd.Normal(loc=[-2., 2.], scale=[0.5, 0.5]),
)

# Bayesian neural network for uncertainty
model = tf.keras.Sequential([
    tfp.layers.DenseVariational(
        units=64,
        make_prior_fn=prior,
        make_posterior_fn=posterior,
    ),
    tf.keras.layers.Dense(1),
])
TF Decision Forests — tabular의 좋은 친구·python
import tensorflow_decision_forests as tfdf
import pandas as pd

# pip install tensorflow_decision_forests
df = pd.read_csv("adult_income.csv")
train_df, test_df = df[:800], df[800:]

train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(train_df, label="income")
test_ds  = tfdf.keras.pd_dataframe_to_tf_dataset(test_df,  label="income")

# Random Forest — no LR tuning, no feature normalization needed
model = tfdf.keras.RandomForestModel()
model.fit(train_ds)

model.compile(metrics=["accuracy"])
print(model.evaluate(test_ds, return_dict=True))
model.summary()                 # built-in feature importance

# Save as TF SavedModel for deployment
model.save("decision_forest_model/")

External links

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.