blob: 2263d77944f713a08e73a3c378c0865e184b5dec [file] [log] [blame]
#-------------------------------------------------------------
#
# 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.
#
#-------------------------------------------------------------
accuracy = function(Matrix[Double] X, Matrix[Double] y, Matrix[Double] B) return (Matrix[Double] err) {
[M,yhat,acc] = multiLogRegPredict(X=X, B=B, Y=y, verbose=FALSE);
err = as.matrix(1-(acc/100));
}
X = rand(rows=300, cols=20, sparsity=1.0, seed=1);
y = rand(rows=300, cols=1, min=1, max=3, sparsity=1.0, seed=1);
y = floor(y);
N = 200;
Xtrain = X[1:N,];
ytrain = y[1:N,];
Xtest = X[(N+1):nrow(X),];
ytest = y[(N+1):nrow(X),];
params = list("icpt", "reg", "maxii");
paramRanges = list(seq(0,2),10^seq(1,-6), 10^seq(1,3));
trainArgs = list(X=Xtrain, Y=ytrain, icpt=-1, reg=-1, tol=1e-9, maxi=100, maxii=-1, verbose=FALSE);
[B1,opt] = gridSearch(X=Xtrain, y=ytrain, train="multiLogReg", predict="accuracy", numB=ncol(X)+1,
params=params, paramValues=paramRanges, trainArgs=trainArgs, verbose=FALSE);
[M,yhat,acc] = multiLogRegPredict(X=Xtest, B=B1, Y=ytest, verbose=FALSE);
write(yhat, $1, format="text");