lm(Month~Country+Region+City+AvgTemperature,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 does not work and I cleaned up the RAM;
For this model, take Country, Region, City, and AvgTemperature as the independent variable and Month as the dependent variable.
What is the code for this model, the code that I sent you earlier does not work. It says:Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Please could you help me?
sample.split(temperature2$Month,SplitRatio = 0.65)-> split_model
Error in sample.split(temperature2$Month, SplitRatio = 0.65) :
could not find function "sample.split"
> str(train)
'data.frame': 681573 obs. of 8 variables:
$ Region : chr "Africa" "Africa" "Africa" "Africa" ...
$ Country : chr "Algeria" "Algeria" "Algeria" "Algeria" ...
$ State : chr NA NA NA NA ...
$ City : chr "Algiers" "Algiers" "Algiers" "Algiers" ...
$ Month : chr "1" "1" "1" "1" ...
$ Day : chr "1" "2" "3" "5" ...
$ Year : chr "1995" "1995" "1995" "1995" ...
$ AvgTemperature: chr "64.2" "49.4" "48.8" "47.9" ...
sample.split is only available to you when you have run library(caTools)
From your str it shows that Month is a character and there is not a principled way for lm() to regress / fit a model to predict that directly. you could potentially (As a purely practical matter) convert to an integer, although I am dubious as to the statistical validity of such an approach. Can you give us some more information about the context that brought you to this analysis, and tell a bit of what your goal is ?
factors are numbered from 1 on up internally, which you should be aware of if you want to manually convert to a numeric represenation (which is not usually necessary).