Create a regression model using tisthemachinelearner

regressor(x, y, model_name, calibration = FALSE, seed = 42, ...)

Arguments

x

Feature matrix

y

Target vector

model_name

Name of the sklearn model to use

calibration

Logical flag to indicate if calibration of residuals should be used

seed

Seed for the random number generator

...

Additional parameters passed to the sklearn model

Value

A regressor object

Examples

# Split features and target
X <- as.matrix(mtcars[, -1])  # all columns except mpg
y <- mtcars[, 1]              # mpg column

# Create train/test split
set.seed(42)
train_idx <- sample(nrow(mtcars), size = floor(0.8 * nrow(mtcars)))
X_train <- X[train_idx, ]
X_test <- X[-train_idx, ]
y_train <- y[train_idx]
y_test <- y[-train_idx]

# Fit linear regression model
reg_linear <- regressor(X_train, y_train, "LinearRegression")

# Make predictions
predictions <- predict(reg_linear, X_test)

# Calculate RMSE
(rmse <- sqrt(mean((predictions - y_test)^2)))
#> [1] 4.876167