predict.ssr: Predictions from a fitted ssr object

Description Usage Arguments Value Examples

View source: R/algorithms.R

Description

Returns a vector of predicted responses from the fitted ssr object.

Usage

1
2
## S3 method for class 'ssr'
predict(object, newdata, ...)

Arguments

object

fitted object of class ssr.

newdata

data frame with the input variables from which the response variable is to be predicted.

...

additional arguments (not used)

Value

A numeric vector with the predictions for each row of the input data frame.

Examples

 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
dataset <- friedman1 # Load friedman1 dataset.

set.seed(1234)

# Split the dataset into 70% for training and 30% for testing.
split1 <- split_train_test(dataset, pctTrain = 70)

# Choose 5% of the train set as the labeled set L and the remaining will be the unlabeled set U.
split2 <- split_train_test(split1$trainset, pctTrain = 5)

L <- split2$trainset

U <- split2$testset[, -11] # Remove the labels.

testset <- split1$testset

regressors <- list(knn = caret::knnreg)

model <- ssr("Ytrue ~ .", L, U, regressors = regressors, testdata = testset, maxits = 10)

# Plot RMSE.
plot(model)

# Get the predictions on the testset.
predictions <- predict(model, testset)

# Calculate RMSE on the test set.
sqrt(mean((predictions - testset$Ytrue)^2))

ssr documentation built on Sept. 2, 2019, 5:06 p.m.