输入 [ ]
已复制!
pip install ydf -U
pip install ydf -U
输入 [1]
已复制!
import ydf
import pandas as pd
import ydf import pandas as pd
输入 [2]
已复制!
ds_path = "https://raw.githubusercontent.com/google/yggdrasil-decision-forests/main/yggdrasil_decision_forests/test_data/dataset"
train_ds = pd.read_csv(f"{ds_path}/adult_train.csv")
test_ds = pd.read_csv(f"{ds_path}/adult_test.csv")
# Print the first 5 training examples
train_ds.head(5)
# Train a model
model = ydf.RandomForestLearner(label="income").train(train_ds)
ds_path = "https://raw.githubusercontent.com/google/yggdrasil-decision-forests/main/yggdrasil_decision_forests/test_data/dataset" train_ds = pd.read_csv(f"{ds_path}/adult_train.csv") test_ds = pd.read_csv(f"{ds_path}/adult_test.csv") # 打印前 5 个训练示例 train_ds.head(5) # 训练模型 model = ydf.RandomForestLearner(label="income").train(train_ds)
Train model on 22792 examples Model trained in 0:00:01.194396
预测分析¶
与模型分析 (model.analyze
) 不同,模型分析检查模型的整体情况,而预测分析 (model.analyze_prediction
) 解释模型的单个预测。下一个示例解释模型对第一个测试示例的预测。
输入 [3]
已复制!
model.analyze_prediction(test_ds.iloc[:1])
model.analyze_prediction(test_ds.iloc[:1])
输出[3]