| #------------------------------------------------------------- |
| # |
| # 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. |
| # |
| #------------------------------------------------------------- |
| |
| ratio = as.double($1) |
| X = rand(rows=20, cols=4, min=1, max =100, seed=1) |
| Y = rbind(matrix(1, rows=15, cols=1), matrix(2, rows=5, cols=1)) |
| classesUnBalanced = table(Y[, ncol(Y)], 1) |
| # # # randomize the data |
| IX = sample(nrow(X), nrow(X)) |
| P = table(seq(1,nrow(IX)), IX, nrow(IX), nrow(X)); |
| X = P %*% X |
| Y = P %*% Y |
| |
| [balancedX, balancedY] = underSampling(X, Y, ratio) |
| classesBalanced = table(balancedY, 1) |
| out = as.scalar(classesUnBalanced[1] - classesBalanced[1]) >= (floor(15.0*ratio) - 1) & |
| as.scalar(classesUnBalanced[1] - classesBalanced[1]) <= (floor(15.0*ratio) + 1) |
| print(out) |
| |
| |