originalRidgeRegression: Linaer Regression Algorithm for Comparison

Description Usage Arguments Value Author(s) Examples

View source: R/LinearRegression.R

Description

Linaer Regression Algorithm for Comparison

Usage

1
originalRidgeRegression(data, features = NULL, target, training_part = 0.8, seed = 200)

Arguments

data

data is a data.frame.

training_part

training_part is the ratio for training data.

features

features is a vector with the names of the features you want to use as predictors.

target

target is a string with the name of the target. We only allow uni-label predicting in this package.

seed

seed is the seed you want to specify, this ensures the reproducibility of the data.

Value

pred

The prediction for the test set the algorithm automatically splitted

RMSE

The RMSE between the prediction and true target result for the test set

Author(s)

Li (Richard) Liu

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, features = NULL, target, training_part = 0.8,
    seed = 200)
{
    flag = require("glmnet")
    if (flag == FALSE) {
        install.packages("glmnet")
        library(glmnet)
    }
    set.seed(seed)
    index = sample(1:nrow(data), training_part * nrow(data))
    data_train = data[index, ]
    data_test = data[-index, ]
    X_train = data.matrix(data_train[, features])
    Y_train = data_train[, target]
    X_test = data.matrix(data_test[, features])
    Y_test = data_test[, target]
    model = glmnet(X_train, Y_train, alpha = 0, lambda = 0, family = "gaussian")
    pred = predict(model, X_test)
    pred = as.vector(pred)
    RMSE = eval_metrics(Y_test, as.vector(pred))
    pred = as.matrix(pred)
    return(list(pred = pred, RMSE = RMSE))
  }

WeakCha/BIOSTAT625_HW4 documentation built on Dec. 18, 2021, 7:16 p.m.