sql - Perform linear regression in R with data from SAP HANA database -
i trying import dataset r apply linear regression model, skeptical of code new r. dataset follows 5000+ rows of data:
power consumption
cputi
dbsu
as column names , followings integers values in above column:
132
25
654
the sql code call r function wrote
create column table "predictive analysis" "anagappan.power_consumption" no data; select power_app, power_db,cputi,dbti,dbsu "anagappan.power_consumption"; drop procedure use_lm; create procedure use_lm( in train "anagappan.power_consumption", out result "predictive analysis") language rlang begin library(lm) model_app <- lm( power_app ~ cputi + dbti + dbsu + kbytes_transferred, data = train ) colnames(datout) <- c("power_app", "cputi", "dbti", "dbsu", "dbsu") predictive analysis <- as.data.frame( lm(model_app)) end;
the result obtain says procedure created unable call linear model on data, how initiate linear model?
although i'm not familiar sap products, have stab @ r code assume between begin
, end;
.
library(lm)
is incorrect, mentioned @olli. access r's linear model capabilities, have call - nothing. it's loaded default through stats
package (this may not true if r called in --vanilla
mode.
model_app <- lm( power_app ~ cputi + dbti + dbsu + kbytes_transferred, data = train )
appears ok, @ least syntax's point of view.
for
colnames(datout) <- c("power_app", "cputi", "dbti", "dbsu", "dbsu")
i can't see define datout
. if variable not created database, not exist , r should complain along lines of
error in colnames(notexist) <- "x" : object 'notexist' not found
i assume want predict (means) based on model. line
predictive analysis <- as.data.frame( lm(model_app))
will not work because r's variables should not have spaces, as.data.frame
not work on lm
object , model_app
doesn't exist (notice case). think should along lines of
# based on http://help.sap.com/hana/sap_hana_r_integration_guide_en.pdf # have specify variable result exported database result <- as.data.frame(predict(model_app))
you can try out.
x <- 1:10 y <- rnorm(10) mdl <- lm(y ~ x) as.data.frame(predict(mdl)) predict(mdl) 1 0.47866685 2 0.34418219 3 0.20969753 4 0.07521287 5 -0.05927180 6 -0.19375646 7 -0.32824112 8 -0.46272579 9 -0.59721045 10 -0.73169511
Comments
Post a Comment