Teradata R Package Function Reference - 16.20 - tdplyr: predict - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

Generic predict function for performing predictions using results of model fitting functions, such as td_glm_mle(), td_glml1l2_mle(), td_decision_forest_mle(), td_decision_tree_mle(), td_naivebayes_mle(), td_naivebayes_textclassifier_mle(), td_svm_sparse_mle(), td_arima_mle(), td_xgboost_mle(), td_knn_recommender_mle(), td_lin_reg_mle(). This function invokes respective predict methods, based on the class of the the model (first argument).

Usage

  predict(object, ...)

Arguments

object

Required Argument.
Model object can be one of the following class:

  1. td_glm_mle

  2. td_glml1l2_mle

  3. td_decision_forest_mle

  4. td_decision_tree_mle

  5. td_naivebayes_mle

  6. td_naivebayes_textclassifier_mle

  7. td_svm_sparse_mle

  8. td_svm_dense_mle

  9. td_arima_mle

  10. td_lar_mle

  11. td_xgboost_mle

  12. td_knn_recommender_mle

  13. td_lin_reg_mle

It is usually created using the following methods:

  1. td_glm_mle

  2. td_glml1l2_mle

  3. td_decision_forest_mle

  4. td_decision_tree_mle

  5. td_naivebayes_mle

  6. td_naivebayes_textclassifier_mle

  7. td_svm_sparse_mle

  8. td_svm_dense_mle

  9. td_arima_mle

  10. td_lar_mle

  11. td_xgboost_mle

  12. td_knn_recommender_mle

  13. td_lin_reg_mle

...

Additional arguments useful for predictions.

Value

Return value from predict depends on the class of the object.

Examples

    # Please visit indivdual predict in line documentation for more examples.
    # help(predict.td_glm_mle)
    # help(predict.td_glml1l2_mle)
    # help(predict.td_decision_forest_mle)
    # help(predict.td_decision_tree_mle)
    # help(predict.td_naivebayes_mle)
    # help(predict.td_naivebayes_textclassifier_mle)
    # help(predict.td_svm_sparse_mle)
    # help(predict.td_svm_dense_mle)
    # help(predict.td_arima_mle)

    
    #### GLM Predict Example ####
    # Get the current context/connection.
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("glm_example", "admissions_train")
    loadExampleData("glmpredict_example", "admissions_test")
    
    # Create remote tibble objects.
    admissions_test <- tbl(con, "admissions_test")
    admissions_train <- tbl(con, "admissions_train")
    
    # Example 1 -
    # First train the data, i.e., create a GLM Model
    td_glm_out <- td_glm_mle(formula = (admitted ~ stats + masters + gpa + programming),
                         family = "LOGISTIC",
                         linkfunction = "LOGIT",
                         data = admissions_train,
                         weights = "1",
                         threshold = 0.01,
                         maxit = 25,
                         step = FALSE,
                         intercept = TRUE
    )
    
    # Run predict on the output of GLM.
    glm_predict_out <- predict(td_glm_out,
                             newdata = admissions_test,
                             terms = c("id","masters","gpa","stats","programming","admitted"),
                             family = "LOGISTIC",
                             linkfunction = "LOGIT"
    )