Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type parameter of the predict() function

Tags:

What is the difference between type="class" and type="response" in the predict function?

For instance between:

predict(modelName, newdata=testData, type = "class") 

and

predict(modelName, newdata=testData, type = "response") 
like image 212
kuz Avatar asked Apr 15 '14 13:04

kuz


People also ask

What is type in predict function?

The predict() function can be used to predict the probability that the market will go up, given values of the predictors. The type="response" option tells R to output probabilities of the form P(Y = 1|X) , as opposed to other information such as the logit .

What is predict () in R?

The predict() function in R is used to predict the values based on the input data.

What is predict function in Python?

Python predict() function enables us to predict the labels of the data values on the basis of the trained model. Syntax: model.predict(data) The predict() function accepts only a single argument which is usually the data to be tested.

What is the use of predict function?

It covers every time frame, basically, it will consider historical data as well as current data and on the basis of it frame a model which will predict the data or you can say forecast the data.


1 Answers

Response gives you the numerical result while class gives you the label assigned to that value.

Response lets you to determine your threshold. For instance,

glm.fit = glm(Direction~., data=data, family = binomial, subset = train) glm.probs = predict(glm.fit, test, type = "response") 

In glm.probs we have some numerical values between 0 and 1. Now we can determine the threshold value, let's say 0.6. Direction has two possible outcomes, up or down.

glm.pred = rep("Down",length(test)) glm.pred[glm.probs>.6] = "Up" 
like image 98
boyaronur Avatar answered Sep 28 '22 09:09

boyaronur