<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Set up the dataset
Step1:  Set up the pipeline
Step2:  Extract relevant parameters for dtreeviz from the pipeline
As the model used has several preprocessing steps prior the decision tree, its feature space is different from dataset[features]. Hence, we first have to extract the relevant parameters from the pipeline before passing them to dtreeviz. Here, we use the following helper function from the dtreeviz.utils module
Step3:  Initialize shadow tree
Step4:  Visualizations
viz_leaf_samples
Step5:  ctreeviz_leaf_samples
Step6:  dtreeviz
Step7:  show just path
Step8:  viz_leaf_criterion
Step9:  describe_node_sample
<ASSISTANT_TASK:>
Python Code:
random_state = 1234
dataset = pd.read_csv("../data/titanic/titanic.csv")
# Fill missing values for Age
dataset.fillna({"Age":dataset.Age.mean()}, inplace=True)
# Encode categorical variables
dataset["Sex_label"] = dataset.Sex.astype("category").cat.codes
dataset["Cabin_label"] = dataset.Cabin.astype("category").cat.codes
dataset["Embarked_label"] = dataset.Embarked.astype("category").cat.codes
features = ["Pclass", "Age", "Fare", "Sex_label", "Cabin_label", "Embarked_label"]
target = "Survived"
Explanation: Set up the dataset
End of explanation
from sklearn.tree import DecisionTreeClassifier
from sklearn.feature_selection import VarianceThreshold
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import PolynomialFeatures
model = make_pipeline(
    VarianceThreshold(0.5),
    PolynomialFeatures(degree=2, interaction_only=True),
    DecisionTreeClassifier(max_depth=4))
model.fit(dataset[features], dataset[target])
Explanation: Set up the pipeline
End of explanation
from dtreeviz.utils import extract_params_from_pipeline
tree_classifier, x_data, features_model = extract_params_from_pipeline(
    pipeline=model,
    x_data=dataset[features],
    feature_names=features)
y_data = dataset[target]
features_model
Explanation: Extract relevant parameters for dtreeviz from the pipeline
As the model used has several preprocessing steps prior the decision tree, its feature space is different from dataset[features]. Hence, we first have to extract the relevant parameters from the pipeline before passing them to dtreeviz. Here, we use the following helper function from the dtreeviz.utils module:
End of explanation
sk_dtree = ShadowSKDTree(tree_classifier, x_data, y_data, features_model, target, [0, 1])
Explanation: Initialize shadow tree
End of explanation
trees.viz_leaf_samples(tree_classifier, x_data, features)
trees.viz_leaf_samples(sk_dtree)
Explanation: Visualizations
viz_leaf_samples
End of explanation
trees.ctreeviz_leaf_samples(tree_classifier, x_data, y_data, features)
trees.ctreeviz_leaf_samples(sk_dtree)
Explanation: ctreeviz_leaf_samples
End of explanation
trees.dtreeviz(tree_classifier, x_data, y_data, features_model, target, class_names=[0, 1])
trees.dtreeviz(sk_dtree, fancy=False)
Explanation: dtreeviz
End of explanation
trees.dtreeviz(sk_dtree, show_just_path=True, X = x_data.iloc[10])
Explanation: show just path
End of explanation
trees.viz_leaf_criterion(tree_classifier)
trees.viz_leaf_criterion(sk_dtree)
Explanation: viz_leaf_criterion
End of explanation
trees.describe_node_sample(tree_classifier, node_id=10, x_data=x_data, feature_names=features_model)
trees.describe_node_sample(sk_dtree, node_id=10)
Explanation: describe_node_sample
End of explanation
<END_TASK>