blob: 4943827e4978bbdf4ba128e337e895be6aeb346a [file]
#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------
D = read($1);
C = read($2);
# divide data into "train" and "test" subsets
numRows = nrow(D);
trainSize = numRows * 0.8;
trainData = D[1:trainSize,];
testData = D[(trainSize+1):numRows,];
C = C[1:trainSize,];
# calc "prior" and "conditionals" with naiveBayes build-in function
[prior, conditionals] = naiveBayes(D=trainData, C=C, laplace=$4, verbose=FALSE);
# compute predict
[YRaw,Y] = naiveBayesPredict(X=testData, P=prior, C=conditionals);
# write the results
write(YRaw, $5);
write(Y, $6);