원클릭으로
pyrsm-dtree
Build, validate, solve, and interpret decision trees with pyrsm.model.dtree
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Build, validate, solve, and interpret decision trees with pyrsm.model.dtree
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Create custom plots from a polars DataFrame in Python using the pyrsm library's `visualize` function — a plotnine wrapper supporting 8 geom types (dist / hist / density / scatter / bar / line / box / violin) with full control over aesthetics (color / fill / shape / group / linetype), faceting (facet_wrap / facet_grid), aggregation, smoothing (lm / loess), jitter, titles, and multiple x/y variables. The return value is a `plotnine.ggplot` object for one plot or a plotnine composition for multiple plots, and users can extend the result with plotnine layers — scales, themes, geom_smooth, geom_vline, custom labels — making plotnine extensibility a first-class part of this skill. Triggers include phrases like "scatter plot of x vs y", "histogram of price", "box plot of price by cut", "line chart over time, colored by region", "facet by category", "add a regression line", "use plotnine to plot", "density plot of carat by cut", or any request for a specific plot in a marketing/business analytics context.
Combine two polars DataFrames in Python using the pyrsm library's `combine` function — supporting inner / left / right / full / semi / anti joins, vertical and horizontal binds, and set operations (intersect / union / setdiff). Use this skill whenever a student or analyst wants to merge two tables on a key, stack two tables of the same schema, identify rows that appear in both tables (or in one but not the other), or work with the pyrsm package for any two-DataFrame combining task. The output is a polars DataFrame the user can keep chaining onto. Triggers include phrases like "join these two tables", "merge on customer_id", "left join", "stack two datasets", "concatenate rows", "find rows in A but not in B", "anti join to find unmatched", "set intersection of two tables", "bind columns side by side", or any mention of combining two tabular datasets in a marketing/business analytics context.
Compare means of a numeric variable across two or more groups in Python using the pyrsm library's `compare_means` class. Use this skill whenever a student or analyst wants to run a two-sample t-test, a paired t-test, or an ANOVA-style set of pairwise comparisons; switch to a Wilcoxon rank-sum / signed-rank test for skewed or small samples; apply Bonferroni adjustment to control family-wise error across multiple comparisons; choose between independent and paired samples; or work with the pyrsm package for any group-mean-comparison task — even if they don't explicitly say "pyrsm" or "compare_means". Triggers include phrases like "compare means across groups", "t-test between two groups", "ANOVA across professor ranks", "is salary different by sex/discipline", "before-after paired test", "Wilcoxon rank-sum test", "Bonferroni adjustment", "pairwise comparisons with multiple-testing correction", or any mention of comparing a continuous outcome across categorical groups in a marketing/business analytics class.
Compare proportions of a categorical outcome across two or more groups in Python using the pyrsm library's `compare_props` class. Use this skill whenever a student or analyst wants to test if the proportion of a "success" level (yes / churned / clicked / survived) differs across groups defined by another categorical variable, focus on specific pair comparisons via `comb`, apply Bonferroni adjustment, validate the chi-squared cell-count assumption, or work with the pyrsm package for any group-proportion-comparison task — even if they don't explicitly say "pyrsm" or "compare_props". Triggers include phrases like "compare proportions across groups", "does survival rate differ by class", "did the click-rate change between A and B and C", "two-proportion z-test", "is the yes-rate the same for males and females", "pairwise proportion comparisons with adjustment", or any mention of comparing a binary outcome across two or more categorical groups in a marketing/business analytics class.
Compute and interpret correlation matrices in Python using the pyrsm library's `correlation` class. Use this skill whenever a student or analyst wants to measure the strength and direction of pairwise relationships among numeric variables, choose between Pearson, Spearman, Kendall, or polychoric correlation, build a scatter-matrix visualization with significance stars, screen for multicollinearity in a dataset before fitting a regression, or work with the pyrsm package for any correlation task — even if they don't explicitly say "pyrsm" or "correlation". Triggers include phrases like "how correlated are X and Y", "compute a correlation matrix", "is there a relationship between these variables", "check for multicollinearity", "Pearson vs Spearman", "what's the rank correlation", "scatter matrix with regression lines", or any mention of measuring pairwise linear/monotonic association among continuous variables in a marketing/business analytics class.
Build and interpret two-way contingency tables and chi-squared tests of independence in Python using the pyrsm library's `cross_tabs` class. Use this skill whenever a student or analyst wants to test whether two categorical variables are associated, build observed/expected/chi-squared/standardized-deviation tables, identify which cells drive an omnibus rejection, compute row/column/total percentages, validate the expected-cell-count assumption, or work with the pyrsm package for any contingency-table task — even if they don't explicitly say "pyrsm" or "cross_tabs". Triggers include phrases like "is X associated with Y", "chi-square test of independence", "cross-tab", "contingency table", "does income predict newspaper choice", "which cells contribute to the chi-squared", "standardized residuals", "expected vs observed frequencies", "row percentages vs column percentages", or any mention of analyzing the relationship between two categorical variables in a marketing/business analytics class.
| name | pyrsm-dtree |
| description | Build, validate, solve, and interpret decision trees with pyrsm.model.dtree |
pyrsm.model.dtree)This skill teaches how to construct a decision tree in YAML, calculate
expected monetary value (EMV) via expected-value rollback, and interpret
the recommended decision. It mirrors Radiant's classic dtree() analysis
with one important difference: the Python engine is built around typed
node objects, structured diagnostics, and a safe expression evaluator
instead of free-form eval.
Reach for dtree whenever a student needs to choose between several
courses of action whose outcomes depend on uncertain events. Typical
prompts include:
Do not use a decision tree for prediction problems (use
pyrsm.model.regress, logistic, rforest, etc.) or for general
exploratory analysis.
| Node kind | YAML marker | Meaning |
|---|---|---|
| Decision | type: decision | A choice you control. Children are options. The decision node's payoff is max (or min) of its options. |
| Chance | type: chance | Random event. Children are outcomes with probabilities p:. The chance node's payoff is the probability-weighted average of its children. |
| Terminal | (no type:, no children) | A leaf with a numeric payoff:. |
Each non-root node can also carry a cost:. Cost is subtracted from the
rolled-up payoff of that node.
name: Sign contract
type: decision
Sign with Movie Company:
type: chance
Small Box Office:
p: 0.3
payoff: 200000
Medium Box Office:
p: 0.6
payoff: 1000000
Large Box Office:
p: 0.1
payoff: 3000000
Sign with TV Network:
payoff: 900000
import pyrsm as rsm
tree = rsm.model.dtree(yaml_text, opt="max")
tree.summary(input=False, output=True)
print(tree.solution_df)
print(tree.to_mermaid(final=True))
tree.payoff gives the root EMV. tree.normalized.chosen_child_ids
gives the optimal branches. tree.to_yaml() re-serializes the parsed
tree for storage.
Reusable constants go in a variables: block. Later variables may
reference earlier ones, and p, cost, and payoff may reference any
variable by name:
variables:
legal fees: 5000
p_small: 0.3
p_medium: 0.6
p_large: 1 - p_small - p_medium
Allowed operators: +, -, *, /, **, parentheses, unary +/-.
Anything else (function calls, attribute access, list indexing) is
rejected. This is enforced by a small AST evaluator, not Python eval.
tree = rsm.model.dtree(yaml_text, opt="max")
Roll-back rules:
payoff - cost (if cost is set on the leaf;
prefer folding cost into payoff for single-leaf situations).sum(p_i * child_payoff_i) - cost.max(child_payoff) (or min if opt="min"),
minus any cost on the decision node itself.node.chosen_child_ids and
flagged with a decision_tie warning.tree.diagnostics returns a list of Diagnostic(severity, code, message, path) records. The common codes:
| Code | Severity | Meaning |
|---|---|---|
chance_probabilities_not_one | error | A chance node's p values do not sum to 1. |
chance_probability_out_of_range | error | A p is outside [0, 1]. |
chance_child_missing_probability | error | A chance branch has no p:. |
terminal_missing_payoff | error | A leaf has no payoff:. |
unresolved_variable | error | A p/cost/payoff references a name that is not in variables:. |
unsafe_expression | error | A p/cost/payoff uses unsupported syntax (e.g., a function call). |
duplicate_sibling_label | error | Two children of the same parent share a label. |
missing_node_type | warning | A node has children but no type:; defaulted to decision. |
terminal_has_cost | warning | Terminal uses cost:. Prefer folding into payoff. |
decision_tie | warning | A decision node has more than one optimal branch. |
A tree with any error-severity diagnostic does not roll back —
tree.is_solved is False and tree.payoff is None. Surface the
diagnostics in the UI rather than silently swallowing them.
When explaining the result to a student:
tree.solution_df to show each
branch's EMV and the probability-weighted contributions of chance
outcomes.p: .4. YAML accepts this, but for clarity prefer 0.4.cost: on a terminal. Replace with an adjusted payoff:.legal_fees_pct instead of p).cost: on a parent
that applies to all children is more compact than repeating the same
number on each terminal.solution_df and the Mermaid
graph and serve as the analysis narrative.