model building with data mining process

lm(cal~. ,data=train)-> mod1
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

I don't know what's wrong with this and how do I get it fixed.

Hi @beingchiragsharma,
The error message hints that (at least one) of your input columns is a factor with only 1 level. You need to check the input data to find the culprit and exclude it from the regression.

# Works OK
data(mtcars)
lm(disp~. ,data=mtcars) -> mod1

# Create an additional factor with only one level
mtcars$non_var <- as.factor(c(5))
str(mtcars)
lm(disp~. ,data=mtcars) -> mod1

# Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
# contrasts can be applied only to factors with 2 or more levels

HTH

i found the culprit but now facing new error.

predict(mod1,test) -> result
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
factor source_facility_name_tpl has new levels 0163680d93754d7a, 0294c62cbbcc44a9, 036f91cdc298,

what do i do now? what is that mean?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

hi @davoww,
actually the data set is too big with 66 column and 1000 k rows so i am not able to find the culprit so could please help me to what could be a culprit in data?

your new data has factor levels that were not observed when the model was fit, so its unknown how to score them.