我为用户提供了数据集,点击了一个在线网站的每个会话的模式。我想使用Markov chain& amp;它的概率。
Following is the my Code:
library(clickstream);
cls2<-readClickstreams(file.choose(),sep = ',',header = TRUE);
mc2<-fitMarkovChain(clickstreamList = cls2,order = 2,control = list(optimizer= "linear"));
pattern <- new("Pattern", sequence = c("/clsisGre/PersonalDetailForm.jsp","/clsisGre/PersonalDetail.jsp"), absorbingProbabilities = data.frame(NULL = 0.9, Success = 0.1));
> resultPattern <- predict(mc2, startPattern = pattern, dist = 1);
Error Message is :
Error in if (nextState %in% object@absorbingStates) { :
argument is of length zero
In addition: Warning message:
In max(cp, na.rm = T) : no non-missing arguments to max; returning -Inf
需要帮助来处理此错误/异常。 提前谢谢。
答案 0 :(得分:0)
对于迟到的更新感到抱歉,但我能够解决这个问题,所以我发布了可能对其他人有帮助的相同解决方案。 在代码中(a,b,c,d,e,f,g,h,l,m)是我想构建马尔可夫链的序列输入。下面的代码将有助于处理上面提到的错误。
pattern <- new("Pattern", sequence = c(a,b,c,d,e,f,g,h,l,m),
absorbingProbabilities = data.frame(NULL = 0.9, Success = 0.1));
possibleError <- tryCatch(
suppressWarnings( predict(mc2, startPattern = pattern, dist = 1)),
error=function(e) e
);
if(inherits(possibleError, "error")) next
resultPattern <- predict(mc2, startPattern = pattern, dist = 1);
aa<-attributes(resultPattern)$absorbingProbabilities;
success_mat10[i,2]<-aa$Success;
success_mat10[i,1]<-as.vector(url_mat10[i,1]);