| |
- SVMPredict(object=None, newdata=None, id_column=None, accumulate=None, output_prob=False, output_responses=None, model_type='Classification', **generic_arguments)
- DESCRIPTION:
The SVMPredict() function uses the model generated by the function SVM() to
predict target values (regression) and class labels (classification) on new
input data.
Notes:
* Standardize input features using ScaleFit() and ScaleTransform()
before using the function.
* The function takes only numeric features. The categorical features
must be converted to numeric values prior to prediction.
* Rows with missing (NULL) values are skipped by the function during prediction.
* For prediction results evaluation, user can use RegressionEvaluator(),
ClassificationEvaluator() or ROC() function as postprocessing step.
PARAMETERS:
object:
Required Argument.
Specifies the teradataml DataFrame containing the
model data generated by SVM() function or the instance
of SVM.
Types: teradataml DataFrame or SVM
newdata:
Required Argument.
Specifies the teradataml DataFrame containing the input data.
Types: teradataml DataFrame
id_column:
Required Argument.
Specifies the name of the column that uniquely identifies an
observation in the test data.
Types: str
accumulate:
Optional Argument.
Specifies the name(s) of input teradataml DataFrame column(s) to
copy to the output.
Types: str OR list of Strings (str)
output_prob:
Optional Argument.
Specifies whether the function should output the probability for each
response.
Note:
Only applicable when "model_type" is 'CLASSIFICATION'.
Default Value: False
Types: bool
output_responses:
Optional Argument.
Specifies the class labels to output probabilities. A label must be 0 or 1.
If not specified, the function outputs the probability of the predicted response.
Note:
Only applicable when "output_prob" is 'True'.
Types: str OR list of strs
model_type:
Optional Argument.
Specifies the type of the analysis.
Note:
* Required for Regression problem.
Permitted Values: 'Classification', 'Regression'
Default Value: 'Classification'
Types: str
**generic_arguments:
Specifies the generic keyword arguments SQLE functions accept. Below
are the generic keyword arguments:
persist:
Optional Argument.
Specifies whether to persist the results of the
function in table or not. When set to True,
results are persisted in table; otherwise,
results are garbage collected at the end of the
session.
Default Value: False
Types: bool
volatile:
Optional Argument.
Specifies whether to put the results of the
function in volatile table or not. When set to
True, results are stored in volatile table,
otherwise not.
Default Value: False
Types: bool
Function allows the user to partition, hash, order or local
order the input data. These generic arguments are available
for each argument that accepts teradataml DataFrame as
input and can be accessed as:
* "<input_data_arg_name>_partition_column" accepts str or
list of str (Strings)
* "<input_data_arg_name>_hash_column" accepts str or list
of str (Strings)
* "<input_data_arg_name>_order_column" accepts str or list
of str (Strings)
* "local_order_<input_data_arg_name>" accepts boolean
Note:
These generic arguments are supported by teradataml if
the underlying SQLE Engine function supports, else an
exception is raised.
RETURNS:
Instance of SVMPredict.
Output teradataml DataFrames can be accessed using attribute
references, such as SVMPredictObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException, TypeError, ValueError
EXAMPLES:
# Notes:
# 1. Get the connection to Vantage to execute the function.
# 2. One must import the required functions mentioned in
# the example from teradataml.
# 3. Function will raise error if not supported on the Vantage
# user is connected to.
# Load the example data.
load_example_data("teradataml", ["cal_housing_ex_raw"])
# Create teradataml DataFrame objects.
data_input = DataFrame.from_table("cal_housing_ex_raw")
# Check the list of available analytic functions.
display_analytic_functions()
# Scale "target_columns" with respect to 'STD' value of the column.
fit_obj = ScaleFit(data=data_input,
target_columns=['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
scale_method="STD")
# Transform the data.
transform_obj = ScaleTransform(data=data_input,
object=fit_obj.output,
accumulate=["id", "MedHouseVal"])
# Example 1 : Predict target values (Regression) for test data using an SVM model
# trained by SVM().
# Train the transformed data using SVM() where "model_type" is 'Regression'.
svm_obj1 = SVM(data=transform_obj.result,
input_columns=['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
response_column="MedHouseVal",
model_type="Regression"
)
# SVMPredict() predicts target values using regression model by SVM().
SVMPredict_out1 = SVMPredict(newdata=transform_obj.result,
object=svm_obj1.result,
id_column="id",
accumulate="MedHouseVal",
model_type="Regression"
)
# Print the result DataFrame.
print(SVMPredict_out1.result)
# Example 2 : Predict target values (Classification) for test data using an SVM model
# trained by SVM().
# Train the transformed data using SVM() where "model_type" is 'Classification'.
svm_obj2 = SVM(data=transform_obj.result,
input_columns=['MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'],
response_column="MedHouseVal",
model_type="Classification",
batch_size=12,
iter_max=301,
lambda1=0.1,
alpha=0.5,
iter_num_no_change=60,
tolerance=0.01,
intercept=False,
class_weights="0:1.0,1:0.5",
learning_rate="INVTIME",
initial_data=0.5,
decay_rate=0.5,
momentum=0.6,
nesterov_optimization=True,
local_sgd_iterations=1,
)
# SVMPredict() predicts target values using classification model by SVM() and
# instance of SVM passed to SVMPredict.
SVMPredict_out2 = SVMPredict(newdata=transform_obj.result,
object=svm_obj2,
id_column="id",
accumulate="MedHouseVal",
output_prob=True,
output_responses=["0", "1"]
)
# Print the result DataFrame.
print(SVMPredict_out2.result)
|