Skip to Content

Guide: SAP Predictive Analysis - Adding further data mining algorithms & visualizations.

SAP Predictive Analysis allows users to leverage the further algorithms and visualizations with the use of R.

In this video I will demonstrate how to use algorithms based on the language R.

Update 10th september: on request I have added the R code used in the video - see the end of this text.

There is just a few steps needed to enhance SAP Predictive Analysis with new R algorithms.

With the use of R in SAP PA you can: 

  • Extend the data mining capabilities with many new algorithms
  • Enhance with even further charts / visualization capabilities.

  

Example of visualization:

Pre-requisites – installed software:

SAP Predictive Analysis version 1.0.11 & R 2.15 with the necessary libraries with r algorithms.

With this step-by-step approach you will be able to enhance SAP Predictive Analysis with even further statistical algorithms and charts / visualizations.

Best regards,

Kurt Holst

Appendix:

kmeansfunction<-function(dataFrame,ind,ClusterNumber,Iterations){

  attach(dataFrame)

  dataFrame

  dataFrame<- data.frame(dataFrame,check.names = FALSE)

  set.seed(4321)

  kmeans_model<-kmeans(data.frame(dataFrame[,ind]),centers=ClusterNumber,iter.max=Iterations,nstart=1)

  output<- cbind(dataFrame, kmeans_model$cluster);

 

  ##Setting the number of charts to display

  par(mfrow=c(4,4))

 

 

 

 

  ## Plot the raw iris data

  plot(iris$Petal.Length, iris$Petal.Width, main="Edgar Anderson's Iris Data")

  plot(iris$Petal.Length, iris$Petal.Width, pch=c(23,24,25)[unclass(iris$Species)], main="Edgar Anderson's Iris Data with individual chart points")

  plot(iris$Petal.Length, iris$Petal.Width, pch=21, bg=c("red","green3","blue")[unclass(iris$Species)], main="Edgar Anderson's Iris Data with individual colors")

  plot(iris$Petal.Length, iris$Petal.Width, pch=21, bg=c("red","green3","blue")[unclass(iris$Species)], main="Edgar Anderson's Iris Data with abline", xlab="Petal length", ylab="Petal width")

  abline(lsfit(iris$Petal.Length, iris$Petal.Width)$coefficients, col="black")

 

 

 

 

  ## Linear Regression

  plot(iris$Sepal.Width, iris$Sepal.Length, pch=21, bg=c("red","green3","blue")[unclass(iris$Species)], main="Edgar Anderson's Iris Data with linear regression lines", xlab="Petal length", ylab="Sepal length")

  abline(lm(Sepal.Length ~ Sepal.Width, data=iris)$coefficients, col="black")

  abline(lm(Sepal.Length ~ Sepal.Width, data=iris[which(iris$Species=="setosa"),])$coefficients, col="red")

  abline(lm(Sepal.Length ~ Sepal.Width, data=iris[which(iris$Species=="versicolor"),])$coefficients, col="green3")

  abline(lm(Sepal.Length ~ Sepal.Width, data=iris[which(iris$Species=="virginica"),])$coefficients, col="blue")

 

 

 

 

  ## Plot the kmeans cluster results

  plot(kmeans_model$cluster, main="Edgar Anderson's Iris plot kmeans cluster");

  barplot(kmeans_model$cluster, main="Edgar Anderson's Iris barplot kmeans cluster");

 

 

 

 

  ## plot cluster centers

  plot(iris[c("Sepal.Length", "Sepal.Width")], col = kmeans_model$cluster, main="Edgar Anderson's Iris kmeans cluster centers");

  points(kmeans_model$centers[,c("Sepal.Length", "Sepal.Width")], col = 1:3, pch = 8, cex=2);

 

 

 

 

  ## plot 3d

  library(scatterplot3d)

  scatterplot3d(iris$Petal.Width, iris$Sepal.Length, iris$Sepal.Width)

 

 

  ## plot lattrice

  library(lattice)

  levelplot(Petal.Width~Sepal.Length*Sepal.Width, iris, cuts=9, col.regions=grey.colors(10)[10:1])

  parallelplot(~iris[1:4] | Species, data=iris)

 

  ## plot ggplot2

  library(ggplot2)

  qplot(Sepal.Length, Sepal.Width, data=iris, facets=Species ~.)

 

  return (list(out=output,modelkmeans=kmeans_model));

}

Tags:
Former Member