predict

How to handle errors in predict function of R?

无人久伴 提交于 2019-12-10 14:58:13
问题 I have a dataframe df, I am building an machine learning model (C5.0 decision tree) to predict the class of a column (loan_approved): Structure (not real data): id occupation income loan_approved 1 business 4214214 yes 2 business 32134 yes 3 business 43255 no 4 sailor 5642 yes 5 teacher 53335 no 6 teacher 6342 no Process: I randomly split the data frame into test and train, learned on train dataset (rows 1,2,3,5,6 train and row 4 as test) In order to account for new categorical levels in one

Inconsistent predictions from predict.gbm()

一笑奈何 提交于 2019-12-10 12:46:56
问题 UPDATE: I have tried running the code on https://rdrr.io/snippets/ and it works fine. Therefore, I suspect a problem with my R installation, but it is extremely worrying that this can happen without errors or warnings. What are the best steps to investigate this ? I am running R 3.4.4 on Ubuntu 18.04 and gbm 2.1.4 I am fitting a boosted model to a dataset and have noticed some strange predictions. Here is a minimal working example. Please note that this is just a small sample of the dataset I

How to use predict with multinom() with intercept in R?

喜欢而已 提交于 2019-12-10 10:39:14
问题 I have run the multinom() function in R, but when I try to predict on a new sample, it keeps giving an error. this is the code: library(nnet) dta=data.frame(replicate(10,runif(10))) names(dta)=c('y',paste0('x',1:9)) res4 <- multinom(y ~ as.matrix(dta[2:10]) , data=dta) #make new data to predict nd<-0.1*dta[1,2:10] pred<-predict(res4, newdata=nd) and this is the error: Error in predict.multinom(res4, newdata = nd) : NAs are not allowed in subscripted assignments I think it has to do with the

Use a keras model in a custom keras loss

自作多情 提交于 2019-12-10 10:36:16
问题 I have a regular keras model called e and I would like to compare its output for both y_pred and y_true in my custom loss function. from keras import backend as K def custom_loss(y_true, y_pred): return K.mean(K.square(e.predict(y_pred)-e.predict(y_true)), axis=-1) I am getting the error: AttributeError: 'Tensor' object has no attribute 'ndim' This is because y_true and y_pred are both tensor object and keras.model.predict expects to be passed a numpy.array . Any idea how I may succeed in

Python ARIMA exogenous variable out of sample

邮差的信 提交于 2019-12-09 16:19:55
问题 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'))

What does predict.glm(, type=“terms”) actually do?

走远了吗. 提交于 2019-12-09 06:07:49
问题 I am confused with the way predict.glm function in R works. According to the help, The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale. Thus, if my model has form f(y) = X*beta, then command predict(model, X, type='terms') is expected to produce the same matrix X, multiplied by beta element-wise. For example, if I train the following model test.data = data.frame(y = c(0,0,0,1,1,1,1,1,1), x=c(1,2,3,1,2,2,3,3,3)) model =

How to reproduce predict.svm in R? [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 01:02:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . I want to train an SVM classifier in R and be able to use it in other software by exporting the relevant parameters. To do so, I first want to be able to reproduce the behavior of predict.svm() in R (using the e1071 package). I trained the model based on the iris data. data(iris) # simplify the data by removing

How to predict terms of merMod objects (lme4)?

元气小坏坏 提交于 2019-12-08 16:37:53
问题 For simple glm objects, I can use predict(fit, type = "terms") to retrieve a matrix with fitted values for each term. What is the equivalent for lmer resp. glmer fitted models? As far as I can see, the predict.merMod function does not support type = terms . 回答1: What is the equivalent for lmer resp. glmer fitted models? I do not think there is one. Though, you can easily make one as follows ##### # fit model with one terms which is a matrix library(lme4) fit <- lmer(Reaction ~ cbind(Days,

predict and multiplicative variables / interaction terms in probit regressions

笑着哭i 提交于 2019-12-08 08:02:06
问题 I want to determine the marginal effects of each dependent variable in a probit regression as follows: predict the (base) probability with the mean of each variable for each variable, predict the change in probability compared to the base probability if the variable takes the value of mean + 1x standard deviation of the variable In one of my regressions, I have a multiplicative variable, as follows: my_probit <- glm(a ~ b + c + I(b*c), family = binomial(link = "probit"), data=data) Two

Predicting via Lowess in R (OR reconciling Loess & Lowess)

假装没事ソ 提交于 2019-12-08 04:11:18
问题 I'm trying to interpolate/locally extrapolate some salary data to fill out a data set. Here's the data set and a plot of the available data: experience salary 1: 1 21878.67 2: 2 23401.33 3: 3 23705.00 4: 4 24260.00 5: 5 25758.60 6: 6 26763.40 7: 7 27920.00 8: 8 28600.00 9: 9 28820.00 10: 10 32600.00 11: 12 30650.00 12: 14 32600.00 13: 15 32600.00 14: 16 37700.00 15: 17 33380.00 16: 20 36784.33 17: 23 35600.00 18: 25 33590.00 19: 30 32600.00 20: 31 33920.00 21: 35 32600.00 Given the clear