| reg_lm | R Documentation |
Linear regression using stats::lm.
reg_lm(formula = NULL, attribute = NULL, features = NULL)
formula |
optional regression formula (e.g., y ~ x1 + x2). |
attribute |
target attribute name (used when formula is NULL) |
features |
optional vector of feature names (used when formula is NULL) |
returns a reg_lm object
if (requireNamespace("MASS", quietly = TRUE)) {
data(Boston, package = "MASS")
# Simple linear regression
model_simple <- reg_lm(formula = medv ~ lstat)
model_simple <- fit(model_simple, Boston)
pred_simple <- predict(model_simple, Boston)
head(pred_simple)
# Polynomial regression (degree 2)
model_poly <- reg_lm(formula = medv ~ poly(lstat, 2, raw = TRUE))
model_poly <- fit(model_poly, Boston)
pred_poly <- predict(model_poly, Boston)
head(pred_poly)
# Multiple regression
model_multi <- reg_lm(formula = medv ~ lstat + rm + ptratio)
model_multi <- fit(model_multi, Boston)
pred_multi <- predict(model_multi, Boston)
head(pred_multi)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.