predict

how to solve predict.lm() error: variable 'affinity' was fitted with type “nmatrix.1” but type “numeric” was supplied

流过昼夜 提交于 2019-12-04 04:45:40
问题 I have a simple linear model: mylm = lm(formula = prodRate~affinity, mydf) where mydf is a dataframe which looks like: prodRate affinity 1 2643.5744 0.005164040 2 2347.6923 0.004439970 3 1783.6819 0.003322830 when I use predict.lm() an error came up: my_pred= predict(mylm,newdata=data.frame(affinity=seq(0,1,0.1)) ) Error: variable 'affinity' was fitted with type "nmatrix.1" but type "numeric" was supplied. Why is that? how to fix it? Thanks! 回答1: Thanks to the discussion with user20650 (see

Error in `contrasts' Error

本小妞迷上赌 提交于 2019-12-04 04:43:00
问题 I have trained a model and I am attempting to use the predict function but it returns the following error. Error in contrasts<- ( *tmp* , value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels There are several questions in SO and CrossValidated about this, and from what I interpret this error to be, is one factor in my model has only one level. This is a pretty simple model, with one continuous variable (driveTime) and one factor variable which has

Python ARIMA exogenous variable out of sample

早过忘川 提交于 2019-12-04 02:49:36
I am trying to predict a time series in python statsmodels ARIMA package with the inclusion of an exogenous variable, but cannot figure out the correct way to insert the exogenous variable in the predict step. See here for docs. import numpy as np from scipy import stats import pandas as pd import statsmodels.api as sm vals = np.random.rand(13) ts = pd.TimeSeries(vals) df = pd.DataFrame(ts, columns=["test"]) df.index = pd.Index(pd.date_range("2011/01/01", periods = len(vals), freq = 'Q')) fit1 = sm.tsa.ARIMA(df, (1,0,0)).fit() #this works fine: pred1 = fit1.predict(start=12, end = 16) print

R explain on Lime - Feature names stored in `object` and `newdata` are different

◇◆丶佛笑我妖孽 提交于 2019-12-04 01:57:10
问题 Hi I was working on using R explain on the LIME model. All is fine when I run this portion. # Library library(tm) library(SnowballC) library(caTools) library(RWeka) library(caret) library(text2vec) library(lime) # Importing the dataset dataset_original = read.delim('Restaurant_Reviews.tsv', quote = '', stringsAsFactors = FALSE) dataset_original$Liked = as.factor(dataset_original$Liked) # Splitting the dataset into the Training set and Test set set.seed(123) split = sample.split(dataset

How to predict on a new dataset using caretEnsemble package in R?

徘徊边缘 提交于 2019-12-03 21:22:48
I am currently using caretEnsemble package in R for combining multiple models trained in caret. I have got the list of final trained models (say model_list ) using caretList function from the same package as follows. model_list <- caretList( x = input_predictors, y = input_labels, metric = 'Accuracy', tuneList = list( randomForestModel = caretModelSpec(method='rf', tuneLength=1, preProcess=c('BoxCox', 'center', 'scale')), ldaModel = caretModelSpec(method='lda', tuneLength=1, preProcess=c('BoxCox', 'center', 'scale')), logisticRegressionModel = caretModelSpec(method='glm', tuneLength=1,

glmer - predict with binomial data (cbind count data)

感情迁移 提交于 2019-12-03 15:03:23
I am trying to predict values over time (Days in x axis) for a glmer model that was run on my binomial data. Total Alive and Total Dead are count data. This is my model, and the corresponding steps below. full.model.dredge<-glmer(cbind(Total.Alive,Total.Dead)~(CO2.Treatment+Lime.Treatment+Day)^3+(Day|Container)+(1|index), data=Survival.data,family="binomial") We have accounted for overdispersion as you can see in the code (1:index). We then use the dredge command to determine the best fitted models with the main effects (CO2.Treatment, Lime.Treatment, Day) and their corresponding interactions.

How to deal with NA in a panel data regression?

我的未来我决定 提交于 2019-12-03 09:47:55
问题 I am trying to predict fitted values over data containing NA s, and based on a model generated by plm . Here's some sample code: require(plm) test.data <- data.frame(id=c(1,1,2,2,3), time=c(1,2,1,2,1), y=c(1,3,5,10,8), x=c(1, NA, 3,4,5)) model <- plm(y ~ x, data=test.data, index=c("id", "time"), model="pooling", na.action=na.exclude) yhat <- predict(model, test.data, na.action=na.pass) test.data$yhat <- yhat When I run the last line I get an error stating that the replacement has 4 rows while

How to predict x values from a linear model (lm)

人盡茶涼 提交于 2019-12-03 06:21:31
I have this data set: x <- c(0, 40, 80, 120, 160, 200) y <- c(6.52, 5.10, 4.43, 3.99, 3.75, 3.60) I calculated a linear model using lm() : model <- lm(y ~ x) I want know the predicted values of x if I have new y values, e.g. ynew <- c(5.5, 4.5, 3.5) , but if I use the predict() function, it calculates only new y values. How can I predict new x values if I have new y values? Since this is a typical problem in chemistry (predict values from a calibration), package chemCal provides inverse.predict . However, this function is limited to "univariate model object[s] of class lm or rlm with model

Using randomForest package in R, how to get probabilities from classification model?

风流意气都作罢 提交于 2019-12-03 04:20:50
问题 TL;DR : Is there something I can flag in the original randomForest call to avoid having to re-run the predict function to get predicted categorical probabilities, instead of just the likely category? Details: I am using the randomForest package. I have a model something like: model <- randomForest(x=out.data[train.rows, feature.cols], y=out.data[train.rows, response.col], xtest=out.data[test.rows, feature.cols], ytest=out.data[test.rows, response.col], importance= TRUE) where out.data is a

How to deal with NA in a panel data regression?

[亡魂溺海] 提交于 2019-12-03 00:21:44
I am trying to predict fitted values over data containing NA s, and based on a model generated by plm . Here's some sample code: require(plm) test.data <- data.frame(id=c(1,1,2,2,3), time=c(1,2,1,2,1), y=c(1,3,5,10,8), x=c(1, NA, 3,4,5)) model <- plm(y ~ x, data=test.data, index=c("id", "time"), model="pooling", na.action=na.exclude) yhat <- predict(model, test.data, na.action=na.pass) test.data$yhat <- yhat When I run the last line I get an error stating that the replacement has 4 rows while data has 5 rows. I have no idea how to get predict return a vector of length 5... If instead of