Skip to content

Commit 4473786

Browse files
simonpcouchtopepo
andauthored
refactor model specification printing (#739)
* add model printing helper * delete redundant model print methods note that the only changes needed to pass existing tests is 4 snapshot updates, where `"Model "` is added preceding `"Specification"` in the header. * delete old model spec printing tests * add new model spec printing tests * add `NEWS` entry * move print helpers and methods to new `R/print.R` file * re`document()` * add null model description * test fixes re: upstream merge Co-authored-by: Max Kuhn <[email protected]>
1 parent 9b4c0b8 commit 4473786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+264
-492
lines changed

NAMESPACE

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,10 @@ S3method(predict_raw,"_multnet")
4949
S3method(predict_raw,model_fit)
5050
S3method(predict_survival,model_fit)
5151
S3method(predict_time,model_fit)
52-
S3method(print,C5_rules)
53-
S3method(print,bag_mars)
54-
S3method(print,bag_tree)
55-
S3method(print,bart)
56-
S3method(print,boost_tree)
5752
S3method(print,control_parsnip)
58-
S3method(print,cubist_rules)
59-
S3method(print,decision_tree)
60-
S3method(print,discrim_flexible)
61-
S3method(print,discrim_linear)
62-
S3method(print,discrim_quad)
63-
S3method(print,discrim_regularized)
64-
S3method(print,gen_additive_mod)
65-
S3method(print,linear_reg)
66-
S3method(print,logistic_reg)
67-
S3method(print,mars)
68-
S3method(print,mlp)
6953
S3method(print,model_fit)
7054
S3method(print,model_spec)
71-
S3method(print,multinom_reg)
72-
S3method(print,naive_Bayes)
73-
S3method(print,nearest_neighbor)
7455
S3method(print,nullmodel)
75-
S3method(print,pls)
76-
S3method(print,poisson_reg)
77-
S3method(print,proportional_hazards)
78-
S3method(print,rand_forest)
79-
S3method(print,rule_fit)
80-
S3method(print,surv_reg)
81-
S3method(print,survival_reg)
82-
S3method(print,svm_linear)
83-
S3method(print,svm_poly)
84-
S3method(print,svm_rbf)
8556
S3method(req_pkgs,model_fit)
8657
S3method(req_pkgs,model_spec)
8758
S3method(required_pkgs,model_fit)
@@ -267,6 +238,7 @@ export(predict_survival.model_fit)
267238
export(predict_time)
268239
export(predict_time.model_fit)
269240
export(prepare_data)
241+
export(print_model_spec)
270242
export(proportional_hazards)
271243
export(rand_forest)
272244
export(repair_call)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
* Model type functions will now message informatively if a needed parsnip extension package is not loaded (#731).
2525

26+
* Refactored internals of model specification printing functions. These changes are non-breaking for extension packages, but the new `print_model_spec()` helper is exported for use in extensions if desired (#739).
27+
2628

2729
# parsnip 0.2.1
2830

R/bag_mars.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ bag_mars <-
4242
)
4343
}
4444

45-
#' @export
46-
print.bag_mars <- function(x, ...) {
47-
cat("Bagged MARS Model Specification (", x$mode, ")\n\n", sep = "")
48-
model_printer(x, ...)
49-
50-
if (is_printable_spec(x)) {
51-
cat("Model fit template:\n")
52-
print(show_call(x))
53-
}
54-
invisible(x)
55-
}
56-
5745
# ------------------------------------------------------------------------------
5846

5947
#' @method update bag_mars

R/bag_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ bag_tree <-
4646
)
4747
}
4848

49-
#' @export
50-
print.bag_tree <- function(x, ...) {
51-
cat("Bagged Decision Tree Model Specification (", x$mode, ")\n\n", sep = "")
52-
model_printer(x, ...)
53-
54-
if (is_printable_spec(x)) {
55-
cat("Model fit template:\n")
56-
print(show_call(x))
57-
}
58-
invisible(x)
59-
}
60-
6149
# ------------------------------------------------------------------------------
6250

6351
#' @method update bag_tree

R/bart.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ bart <-
9090
)
9191
}
9292

93-
#' @export
94-
print.bart <- function(x, ...) {
95-
cat("BART Model Specification (", x$mode, ")\n\n", sep = "")
96-
model_printer(x, ...)
97-
98-
if (is_printable_spec(x)) {
99-
cat("Model fit template:\n")
100-
print(show_call(x))
101-
}
102-
invisible(x)
103-
}
104-
10593
# ------------------------------------------------------------------------------
10694

10795
#' @method update bart

R/boost_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ boost_tree <-
8080
)
8181
}
8282

83-
#' @export
84-
print.boost_tree <- function(x, ...) {
85-
cat("Boosted Tree Model Specification (", x$mode, ")\n\n", sep = "")
86-
model_printer(x, ...)
87-
88-
if (is_printable_spec(x)) {
89-
cat("Model fit template:\n")
90-
print(show_call(x))
91-
}
92-
invisible(x)
93-
}
94-
9583
# ------------------------------------------------------------------------------
9684

9785
#' @method update boost_tree

R/c5_rules.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ C5_rules <-
6363
)
6464
}
6565

66-
#' @export
67-
print.C5_rules <- function(x, ...) {
68-
cat("C5.0 Model Specification (", x$mode, ")\n\n", sep = "")
69-
model_printer(x, ...)
70-
71-
if (is_printable_spec(x)) {
72-
cat("Model fit template:\n")
73-
print(show_call(x))
74-
}
75-
76-
invisible(x)
77-
}
78-
79-
8066
# ------------------------------------------------------------------------------
8167

8268
#' Updating a model specification

R/cubist_rules.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,6 @@ cubist_rules <-
8989
)
9090
}
9191

92-
#' @export
93-
print.cubist_rules <- function(x, ...) {
94-
cat("Cubist Model Specification (", x$mode, ")\n\n", sep = "")
95-
model_printer(x, ...)
96-
97-
if (is_printable_spec(x)) {
98-
cat("Model fit template:\n")
99-
print(show_call(x))
100-
}
101-
102-
invisible(x)
103-
}
104-
105-
10692
# ------------------------------------------------------------------------------
10793

10894
#' @param object A Cubist model specification.

R/decision_tree.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ decision_tree <-
5151
)
5252
}
5353

54-
#' @export
55-
print.decision_tree <- function(x, ...) {
56-
cat("Decision Tree Model Specification (", x$mode, ")\n\n", sep = "")
57-
model_printer(x, ...)
58-
59-
if (is_printable_spec(x)) {
60-
cat("Model fit template:\n")
61-
print(show_call(x))
62-
}
63-
invisible(x)
64-
}
65-
6654
# ------------------------------------------------------------------------------
6755

6856
#' @method update decision_tree

R/discrim_flexible.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ discrim_flexible <-
4545
)
4646
}
4747

48-
#' @export
49-
print.discrim_flexible <- function(x, ...) {
50-
cat("Flexible Discriminant Model Specification (", x$mode, ")\n\n", sep = "")
51-
model_printer(x, ...)
52-
53-
if (is_printable_spec(x)) {
54-
cat("Model fit template:\n")
55-
print(show_call(x))
56-
}
57-
58-
invisible(x)
59-
}
60-
6148
# ------------------------------------------------------------------------------
6249

6350
#' Update a model specification

R/discrim_linear.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,6 @@ discrim_linear <-
4747
)
4848
}
4949

50-
#' @export
51-
print.discrim_linear <- function(x, ...) {
52-
cat("Linear Discriminant Model Specification (", x$mode, ")\n\n", sep = "")
53-
model_printer(x, ...)
54-
55-
if (is_printable_spec(x)) {
56-
cat("Model fit template:\n")
57-
print(show_call(x))
58-
}
59-
60-
invisible(x)
61-
}
62-
6350
# ------------------------------------------------------------------------------
6451

6552
#' @method update discrim_linear

R/discrim_quad.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ discrim_quad <-
4141
)
4242
}
4343

44-
#' @export
45-
print.discrim_quad <- function(x, ...) {
46-
cat("Quadratic Discriminant Model Specification (", x$mode, ")\n\n", sep = "")
47-
model_printer(x, ...)
48-
49-
if (is_printable_spec(x)) {
50-
cat("Model fit template:\n")
51-
print(show_call(x))
52-
}
53-
54-
invisible(x)
55-
}
56-
5744
# ------------------------------------------------------------------------------
5845

5946
#' @method update discrim_quad

R/discrim_regularized.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ discrim_regularized <-
6262
)
6363
}
6464

65-
#' @export
66-
print.discrim_regularized <- function(x, ...) {
67-
cat("Regularized Discriminant Model Specification (", x$mode, ")\n\n", sep = "")
68-
model_printer(x, ...)
69-
70-
if (is_printable_spec(x)) {
71-
cat("Model fit template:\n")
72-
print(show_call(x))
73-
}
74-
75-
invisible(x)
76-
}
77-
7865
# ------------------------------------------------------------------------------
7966

8067
#' @method update discrim_regularized

R/gen_additive_mod.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ gen_additive_mod <- function(mode = "unknown",
5050

5151
}
5252

53-
#' @export
54-
print.gen_additive_mod <- function(x, ...) {
55-
cat("GAM Specification (", x$mode, ")\n\n", sep = "")
56-
model_printer(x, ...)
57-
58-
if (is_printable_spec(x)) {
59-
cat("Model fit template:\n")
60-
print(show_call(x))
61-
}
62-
63-
invisible(x)
64-
}
65-
6653
#' @export
6754
#' @rdname parsnip_update
6855
#' @inheritParams gen_additive_mod

R/linear_reg.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ linear_reg <-
5858
)
5959
}
6060

61-
#' @export
62-
print.linear_reg <- function(x, ...) {
63-
cat("Linear Regression Model Specification (", x$mode, ")\n\n", sep = "")
64-
model_printer(x, ...)
65-
66-
if (is_printable_spec(x)) {
67-
cat("Model fit template:\n")
68-
print(show_call(x))
69-
}
70-
71-
invisible(x)
72-
}
73-
74-
7561
#' @export
7662
translate.linear_reg <- function(x, engine = x$engine, ...) {
7763
x <- translate.default(x, engine, ...)

R/logistic_reg.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ logistic_reg <-
6565
)
6666
}
6767

68-
#' @export
69-
print.logistic_reg <- function(x, ...) {
70-
cat("Logistic Regression Model Specification (", x$mode, ")\n\n", sep = "")
71-
model_printer(x, ...)
72-
73-
if (is_printable_spec(x)) {
74-
cat("Model fit template:\n")
75-
print(show_call(x))
76-
}
77-
78-
invisible(x)
79-
}
80-
8168
#' @export
8269
translate.logistic_reg <- function(x, engine = x$engine, ...) {
8370
x <- translate.default(x, engine, ...)

R/mars.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ mars <-
4949
)
5050
}
5151

52-
#' @export
53-
print.mars <- function(x, ...) {
54-
cat("MARS Model Specification (", x$mode, ")\n\n", sep = "")
55-
model_printer(x, ...)
56-
57-
if (is_printable_spec(x)) {
58-
cat("Model fit template:\n")
59-
print(show_call(x))
60-
}
61-
invisible(x)
62-
}
63-
6452
# ------------------------------------------------------------------------------
6553

6654
#' @method update mars

0 commit comments

Comments
 (0)