LinearRegression: Fast Linear Regression

Description Usage Arguments Value Author(s) Examples

View source: R/LinearRegression.R

Description

This function will do a linear regression like a machine learning taste, which means it will split the dataset into training set (with the ratio training_part) and test set and return the predicted result and the RMSE of the test set.

Usage

1
LinearRegression(data, training_part = 0.8, features = NULL, target, 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
##---- 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, training_part = 0.8, features = NULL, target,
    seed = 200)
{
    set.seed(seed)
    res = dataPreprocess(data, features, target, training_part)
    X_train = res$X_train
    X_test = res$X_test
    Y_train = res$Y_train
    Y_test = res$Y_test
    Y_train = as.matrix(Y_train)
    Y_test = as.matrix(Y_test)
    res = fastRidgeRegression(X_train, Y_train, X_test, Y_test,
        training_part)
    beta = res$beta
    pred = res$pred
    RMSE = res$RMSE
    return(list(pred = pred, RMSE = RMSE))
  }

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