-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.R
More file actions
83 lines (71 loc) · 3.39 KB
/
Copy pathexample.R
File metadata and controls
83 lines (71 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# atlas test drive ------------------------------------------------------
#
# One-time setup:
# 1. install this branch:
# pak::local_install(".") # from the package directory
# # or: remotes::install_github("mattyoreilly/Atlas",
# # ref = "feature/live-tally-steering")
# 2. API key (once, then restart R):
# usethis::edit_r_environ() # add: ANTHROPIC_API_KEY=sk-ant-...
library(atlas)
# 1. Load your data ------------------------------------------------------
csv_path <- "~/Desktop/Hastings/HastingsCredit/Data/app_approved_train.csv"
outcome <- "DEFAULTED" # <- edit me: the column to predict
data <- read.csv(csv_path, stringsAsFactors = TRUE)
str(data, list.len = 25)
# 2. Pre-flight ----------------------------------------------------------
# Which columns look like target leakage on their own?
atlas_leakage_screen(data, outcome)
# Columns that won't exist at prediction time in deployment (IDs,
# post-outcome fields, decline reasons...) - they are removed before the
# agent ever sees the data:
exclude <- c("default_rate", "Total_Loan_Amount", "PREDICTED_LOSS", "APR") # <- e.g. c("QUOTE_DECLINE_REASON")
# 3. Interactive build ----------------------------------------------------
# The agent explores, proposes a plan, and STOPS IN THE CONSOLE for your
# approval - answer "yes", or steer it ("only GLMs, no trees").
# Watch for the live tally lines as models and tweaks are scored:
# [tally #4 | gbm1: auc = 0.81 | best: glm2 = 0.79 | flat: 0/3 -> KEEP]
res <- atlas(
data,
outcome,
n_models = 1, # maximum candidates
goal = "prioritise interpretability",
exclude = exclude,
test_prop = 0.2, # held out; agent never sees these rows
max_steps = 10, # hard safety cap on code executions
dir = "~/Desktop/Code"
)
# 4. What you got back ----------------------------------------------------
res # leaderboards, tally summary, constraints, report, cost
res$tally # every attempt: KEEP / DISCARD, best-so-far
res$test_leaderboard # final ranking on the held-out rows (the one to trust)
res$models # fitted models: predict(res$models[[1]], newdata)
res$dir # run directory: report.md, code.R, tally.csv, plots
cat(res$code, sep = "\n\n") # the full script the agent wrote
# The session is still live - ask it anything:
res$session$add_budget(steps = 25)
res$session$tell("remove the worst predictor and re-evaluate")
res <- res$session$results()
res$models # now Logistic_Regression = v2, no LOAN_TERM
res$leaderboard # the v2 row
res$tally # full attempt history, including the DISCARD
# 5. Autonomous variant ----------------------------------------------------
# No approval gate; generous exploration; hard budgets. Run it, walk away.
# res <- atlas(
# data, outcome,
# autonomous = TRUE,
# n_models = 6,
# stopping_rounds = 5, # stop after 5 flat attempts in a row
# max_steps = 200,
# max_runtime = 1800, # 30 minutes, mechanically enforced
# test_prop = 0.2,
# exclude = exclude,
# dir = "~/atlas-runs/first-auto"
# )
#
# ...and steer it mid-run from ANOTHER R session or terminal:
# atlas::atlas_message("~/atlas-runs/first-auto",
# "focus on gradient boosting; stop engineering ratios")
# 6. Come back later -------------------------------------------------------
# s <- atlas_resume(res$dir)
# s$tell("add one more candidate that uses at most 5 predictors")