j143 commented on a change in pull request #936: URL: https://github.com/apache/systemml/pull/936#discussion_r435073548
########## File path: dev/docs/builtins-reference.md ########## @@ -415,3 +415,64 @@ y = X %*% rand(rows=ncol(X), cols=1) y = normalize(X = X) ``` + +## `msvm`-Function + +The `msvm`-function implements builtin multiclass SVM with squared slack variables +It learns one-against-the-rest binary-class classifiers by making a function call to l2SVM + +### Usage +--- +msvm(X,Y, icpt=False, num_classes=10, epsilon=0.001, lamda=1.0, maxiter=100, verbose=False); + +--- + +### Arguments +| Name | Type | Default | Description | +| :------ | :------------- | -------- | :---------- | +| X | Double | --- | Matrix X of feature vectors.| +| Y | Double | --- | Matrix Y of class labels. | +| intercept | Boolean | False | No Intercept ( If set to TRUE then a constant bias column is added to X)| +| num_classes | Integer | 10 | Number of classes.| +| epsilon | Double | 0.001 | Procedure terminates early if the reduction in objective function value is less than epsilon (tolerance) times the initial objective function value.| +| lamda | Double | 1.0 | Regularization parameter (lambda) for L2 regularization| +| maxIterations | Interger | 100 | Maximum number of conjugate gradient iterations| +| verbose | Boolean | False | Set to true to print while training.| + + +### Returns +| Name | Type | Default | Description | +| :------ | :------------- | -------- | :---------- | +| model | Double | --- | Model matrix. | + + +### Example +``` +m_msvm = function(Matrix[Double] X, Matrix[Double] Y, Boolean intercept = FALSE, + Double epsilon = 0.001, Double lambda = 1.0, Integer maxIterations = 100, Boolean verbose = FALSE) + return(Matrix[Double] model) +{ + if(min(Y) < 0) + stop("MSVM: Invalid Y input, containing negative values") + if(verbose) + print("Running Multiclass-SVM") + num_rows_in_w = ncol(X) + if(intercept) { + num_rows_in_w = num_rows_in_w + 1 + } + if(ncol(Y) > 1) + Y = rowMaxs(Y * t(seq(1,ncol(Y)))) + # Assuming number of classes to be max contained in Y + w = matrix(0, rows=num_rows_in_w, cols=max(Y)) + parfor(class in 1:max(Y)) { + Y_local = 2 * (Y == class) - 1 + w[,class] = l2svm(X=X, Y=Y_local, intercept=intercept, + epsilon=epsilon, lambda=lambda, maxIterations=maxIterations, + verbose= verbose, columnId=class) + } + + model = w +} +``` Review comment: Can we remove these lines?. 😺 We will work with the `Example` as a different task. because We got to do some small experiment with `Example`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org