| #------------------------------------------------------------- |
| # |
| # 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. |
| # |
| #------------------------------------------------------------- |
| |
| # Prepare the data |
| X = read($1, data_type="frame", format="csv", header=TRUE, naStrings= ["20"]); |
| X = cbind(as.matrix(X[,4:5]), as.matrix(X[,7])) |
| |
| mask = is.nan(X) |
| |
| #Perform the KNN imputation |
| result = imputeByKNN(X = X, method = $2) |
| result2 = imputeByKNN(X = X, method = $3) |
| result3 = imputeByKNN(X = X, method = $4, seed = $5, sample_frac = $6) |
| |
| #Get the imputed value |
| I = (mask[,2] == 1); |
| value = removeEmpty(target = result, margin = "rows", select = I) |
| value2 = removeEmpty(target = result2, margin = "rows", select = I) |
| value3 = removeEmpty(target = result3, margin = "rows", select = I) |
| |
| #Get the sum of the imputed value |
| value = colSums(value[,2]) |
| value2 = colSums(value2[,2]) |
| value3 = colSums(value3[,2]) |
| |
| write(value, $7) |
| write(value2, $8) |
| write(value3, $9) |