Questions tagged [predict]

Prediction of values based on model objects.

Predictive models are statistical or algorithmic models for use in prediction tasks. These tend to arise in data-intensive contexts, hence there is a strong association with statistics and machine learning.

Tag Usage

Questions on tag should be about implementation and programming problems, not about the statistical or theoretical properties of the technique. Consider whether your question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

1574 questions
116
votes
11 answers

Error in Python script "Expected 2D array, got 1D array instead:"?

I'm following this tutorial to make this ML prediction: import numpy as np import matplotlib.pyplot as plt from matplotlib import style style.use("ggplot") from sklearn import svm x = [1, 5, 1.5, 8, 1, 9] y = [2, 8, 1.8, 8, 0.6,…
JonTargaryen
  • 1,317
  • 3
  • 11
  • 18
69
votes
4 answers

Predict() - Maybe I'm not understanding it

I posted earlier today about an error I was getting with using the predict function. I was able to get that corrected, and thought I was on the right path. I have a number of observations (actuals) and I have a few data points that I want to…
mikebmassey
  • 8,354
  • 26
  • 70
  • 95
61
votes
1 answer

R: numeric 'envir' arg not of length one in predict()

I'm trying to predict a value in R using the predict() function, by passing along variables into the model. I am getting the following error: Error in eval(predvars, data, env) : numeric 'envir' arg not of length one Here is my data frame,…
mikebmassey
  • 8,354
  • 26
  • 70
  • 95
30
votes
5 answers

Error when I try to predict class probabilities in R - caret

I've build a model using caret. When the training was completed I got the following warning: Warning message: In train.default(x, y, weights = w, ...) : At least one of the class levels are not valid R variables names; This may cause errors if…
Stergios
  • 3,126
  • 6
  • 33
  • 55
26
votes
11 answers

2d game : fire at a moving target by predicting intersection of projectile and unit

Okay, this all takes place in a nice and simple 2D world... :) Suppose I have a static object A at position Apos, and a linearly moving object B at Bpos with bVelocity, and an ammo round with velocity Avelocity... How would I find out the angle that…
Led
  • 2,002
  • 4
  • 23
  • 31
24
votes
6 answers

predict method for felm from lfe package

Does anyone have a nice clean way to get predict behavior for felm models? library(lfe) model1 <- lm(data = iris, Sepal.Length ~ Sepal.Width + Species) predict(model1, newdata = data.frame(Sepal.Width = 3, Species = "virginica")) # Works model2 <-…
kennyB
  • 1,963
  • 3
  • 17
  • 22
23
votes
1 answer

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

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…
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
18
votes
6 answers

using predict with a list of lm() objects

I have data which I regularly run regressions on. Each "chunk" of data gets fit a different regression. Each state, for example, might have a different function that explains the dependent value. This seems like a typical "split-apply-combine" type…
JD Long
  • 59,675
  • 58
  • 202
  • 294
18
votes
4 answers

Multiclass Classification with LightGBM

I am trying to model a classifier for a multi-class Classification problem (3 Classes) using LightGBM in Python. I used the following parameters. params = {'task': 'train', 'boosting_type': 'gbdt', 'objective': 'multiclass', …
18
votes
2 answers

How to eliminate "NA/NaN/Inf in foreign function call (arg 7)" running predict with randomForest

I have researched this extensively without finding a solution. I have cleaned my data set as follows: library("raster") impute.mean <- function(x) replace(x, is.na(x) | is.nan(x) | is.infinite(x) , mean(x, na.rm = TRUE)) losses <- apply(losses, 2,…
Elliott
  • 303
  • 1
  • 3
  • 8
15
votes
1 answer

Getting predicted values at response scale using broom::augment function

I'm fitting glm model in R and can get predicted values at response scale using predict.glm(object=fm1, type="response") where fm1 is the fitted model. I wonder how to get predicted values at response scale using augment function from broom package.…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
13
votes
2 answers

Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)

I've fitted a logistic regression model that predicts the a binary outcome vs from mpg (mtcars dataset). The plot is shown below. How can I determine the mpg value for any particular vs value? For example, I'm interested in finding out what the mpg…
hsl
  • 670
  • 2
  • 10
  • 22
12
votes
1 answer

glmer logit - interaction effects on probability scale (replicating `effects` with `predict`)

I am running glmer logit models using the lme4 package. I am interested in various two and three way interaction effects and their interpretations. To simplify, I am only concerned with the fixed effects coefficients. I managed to come up with a…
Erdne Htábrob
  • 819
  • 11
  • 29
12
votes
2 answers

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

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) =…
David Dale
  • 10,958
  • 44
  • 73
12
votes
3 answers

Error when using predict() on a randomForest object trained with caret's train() using formula

Using R 3.2.0 with caret 6.0-41 and randomForest 4.6-10 on a 64-bit Linux machine. When trying to use the predict() method on a randomForest object trained with the train() function from the caret package using a formula, the function returns an…
Adrien Combaz
  • 123
  • 1
  • 1
  • 6
1
2 3
99 100