Im having a little trouble with a confusion matrix. Has anyone had this issue before? I checked the observations and they are the same
library(e1071) # Please install the package first before running library syntax
Svm_Model = svm(t.total_hbat ~ t.inbound_calls_tied +
t.hbat_on_tickets_closed_by_agent +
t.inb_customer_hold_time,
Test_Data,
kernel="linear",
cost=.1,
Scale=F)
Svm_Prediction = predict(Svm_Model,Test_Data,type="class")
View(as.data.frame(Svm_Prediction))
data_final<-cbind(Test_Data,Svm_Prediction)
confusionMatrix(table(Test_Data$t.total_hbat,Svm_Model))
Console:
confusionMatrix(table(Training_Data$t.total_hbat,Svm_Model))
Error in table(Training_Data$t.total_hbat, Svm_Model) :
all arguments must have the same length
Related
It seems a bit silly to post this as a question, but I haven't been able to find an answer for this.
I want to use the glmmTMB package for modelling data with zero-inflation, but when I try to fit the model I want, the function glmmTMB() returns the following error:
Error in glmmTMB(y ~ x + (1 | z), data = df, ziformula = x) : object 'x' not found
This only happens after I introduce the term for ziformula. The model without that term works just fine. For some reason, it seems that the ziformula overrides the data command in the function.
My glmmTMB package version is 1.1.3 and my R version is 4.1.1.
Here's a little sample data to reproduce the problem:
df <- data.frame(y=c(2,2,5,7,3,8,3,2,4,6),
x = c(23,21.7,22.5,18,20,19.9,21,20.3,20,20.5),
z = c(rep("a",5),rep("b",5)))
glmmTMB(y ~ x + (1|z), data = df, ziformula = x)
If anyone has had any similar issue, I would be grateful for any tips on how to solve it!
I am trying to implement ordinal logistic regression on my dataset in r. I use the function 'polr' for this, but cannot seem to find a lot of information regarding its implementation.
The following errors are the ones I'm stuck on:
> dat.polr <- polr(as.factor(relevance)~allterms+idf.title, data=dat.one)
Warning message:
In polr(as.factor(relevance) ~ allterms + idf.title + idf.desc + :
design appears to be rank-deficient, so dropping some coefs
> dat.pred <- predict(dat.polr,dat.test,type="class")
Error in X %*% object$coefficients : non-conformable arguments
I want to train my model to guess the relevance of a new dataset. dat.one is the dataset I'm using to train the data, dat.test is the dataset I'm using to test the data. I believe that the predict variable's error is caused by the warning in polr. However, I have no clue how to resolve this. Any help would be appreciated :)
I'm new to R and started using it to implement a gam model. I've been following this tutorial examples and R keeps throwing an error when I try to use by. I really have no idea what's wrong and would appreciate it if anybody can suggest something.
Thanks a lot in advance.
>require(mgcv)
>set.seed(10)
## simulate date from y = f(x2)*x1 + error
>dat <- gamSim(3,n=400)
Continuous `by' variable example
>b<-gam(y ~ s(x2,by=x1),data=dat)
Error in s(x2, by = x1) : unused argument (by = x1)
Additional information: R version = 3.3.1 (2013-06-21)
OS = Windows 10
Code
require(mgcv)
set.seed(10)
## simulate date from y = f(x2)*x1 + error
dat <- gamSim(3,n=400)
b <- gam(y ~ s(x2,by=x1),data=dat)
b
Result
Continuous `by' variable example
Family: gaussian Link function: identity
Formula: y ~ s(x2, by = x1)
Estimated degrees of freedom:
9.2 total = 10.2
GCV score: 4.518245
Please start a fresh R session and see if you get the same error. Also, please check your version of mgcv and make sure it's up to date.
I'm trying to use the gamsel R package to fit a sparse generalized additive model, and I can't seem to get it to work on real data. When I run on synthetic data as described in the package documentation, everything works well:
library(gamsel)
data=gendata(n=500,p=12,k.lin=3,k.nonlin=3,deg=8,sigma=0.5)
attach(data)
bases=pseudo.bases(X,degree=10,df=6)
gamsel.out=gamsel(X,y,bases=bases)
But when I run on real data, I get the following error:
library(gamsel)
X = as.matrix(read.csv("X.csv"),header=FALSE)
y = as.matrix(read.csv("y.csv"),header=FALSE)
gam_fit = gamsel(X,y)
Error in if (abs((df - current.df)/df) < 1e-04 | iterations == 1)
return(list(lambda = lambda, : missing value where TRUE/FALSE
needed
You can access sample data files that will reproduce this result here. Any thoughts about how to fix this error?
I'm trying to run a mixed effects model that includes three fixed effects with interaction and a random intercept and slope. The model I'm trying to specify in glmmadmb is:
> fit_zipoiss_ambig<-glmmadmb(AmbigCount~Posn.c*mood.c*Valence.c + offset(InputAmbig) + (1+Valence.c|mood.c/Chain), data = Data, zeroInflation = TRUE, family="poisson")
First I received this error message:
Error in Droplevels(eval(parse(text = x), data)) :
all grouping variables in random effects must be factors
So I used (as an example) fPosn.c=as.factor(Data$Posn.c)to convert all my predictors to factors. Then I ran this model:
> fit_zipoiss_ambig<-glmmadmb(AmbigCount~fPosn.c*fmood.c*fValence.c + offset(InputAmbig) + (1+fValence.c|fmood.c/Chain), data = Data, zeroInflation = TRUE, family="poisson")
Then I got this error:
Error in glmmadmb(AmbigCount ~ fPosn.c * fmood.c * fValence.c + offset(InputAmbig) + :
The function maximizer failed (couldn't find STD file) Troubleshooting steps include (1) run with 'save.dir' set and inspect output files; (2) change run parameters: see '?admbControl'
In addition: Warning message:
running command 'C:\Windows\system32\cmd.exe /c "C:/Program Files/R/R-3.2.2/library/glmmADMB/bin/windows64/glmmadmb.exe" -maxfn 500 -maxph 5 -noinit -shess' had status 1
I tried to follow the troubleshooting advice so included , admb.opts=admbControl(shess=FALSE,noinit=FALSE)) at the end of my model. Now I am receiving this error:
Error in glmmadmb(AmbigCount ~ fPosn.c * fmood.c * fValence.c + offset(InputAmbig) + :
rank of X = 106 < ncol(X) = 107
I have no idea what this error means. I'm hoping someone can help me work out how to specify my model in glmmadmb or failing that, some other package that will allow me to test a poisson or negative binomial distribution.
Without being able to run it myself, what jumps out at me is:
As far as your first error message, it is saying that the variables in your nested random-effects formula need to be factors.
Then, in your code: fPosn.c=as.factor(Data$Posn.c)
you are not creating "fPosn.c" within your data frame. To do that you need to run:
Data$fPosn.c = as.factor(Data$Posn.c)