Description Usage Arguments Value Author(s) Examples
View source: R/LinearRegression.R
Linaer Regression Algorithm for Comparison
1  | originalRidgeRegression(data, features = NULL, target, training_part = 0.8, seed = 200)
 | 
data | 
 
  | 
training_part | 
 
  | 
features | 
 
  | 
target | 
 
  | 
seed | 
 
  | 
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  | 
Li (Richard) Liu
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))
  }
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.