predict

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

你。 提交于 2019-12-02 18:15:37
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 data frame, with feature.cols a mixture of numeric and categorical features, while response.col is a TRUE

SVM predict on dataframe with different factor levels

懵懂的女人 提交于 2019-12-02 16:29:26
问题 I have a dataframe I want to make predictions on from an SVM, but the dataframe doesn't have all of the levels that the original training dataframe did. Is there an easy way around this? Here's a quick example library(e1071) df = data.frame(y = c(rep(1:3, each = 3)), x = rep(c("A", "B", "C"), each = 3)) m1 = svm(y ~ x, df) df2 = data.frame(x = "B") predict(m1, df2) Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more

predict lm function in R (multiple linear regression)

只谈情不闲聊 提交于 2019-12-02 16:18:21
问题 I did a multiple linear regression in R using the function lm and I want to use it to predict several values. So I'm trying to use the function predict() . Here is my code: new=data.frame(t=c(10, 20, 30)) v=1/t LinReg<-lm(p ~ log(t) + v) Pred=predict(LinReg, new, interval="confidence") So I would like to predict the values of p when t=c(10,20,30...) . However, this is not working and I don't see why. The error message I get is: "Error in model.frame.default(Terms, newdata, na.action = na

predict lm function in R (multiple linear regression)

亡梦爱人 提交于 2019-12-02 08:35:48
I did a multiple linear regression in R using the function lm and I want to use it to predict several values. So I'm trying to use the function predict() . Here is my code: new=data.frame(t=c(10, 20, 30)) v=1/t LinReg<-lm(p ~ log(t) + v) Pred=predict(LinReg, new, interval="confidence") So I would like to predict the values of p when t=c(10,20,30...) . However, this is not working and I don't see why. The error message I get is: "Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable lengths differ (found for 'vart') In addition: Warning message:

Coxph predictions don't match the coefficients

社会主义新天地 提交于 2019-12-02 08:03:34
问题 Good afternoon, I could post reproducible code and certainly will if everyone agrees that something is wrong, but right now I think my question is quite simple and someone will point me the right path. I am working in a data set like this: created_as_free_user t c <fctr> <int> <int> 1 true 36 0 2 true 36 0 3 true 0 1 4 true 28 0 5 true 9 0 6 true 0 1 7 true 13 0 8 true 19 0 9 true 9 0 10 true 16 0 I fitted a Cox Regression model like this: fit_train = coxph(Surv(time = t,event = c) ~ created

Error with predict and glm.predict in R

狂风中的少年 提交于 2019-12-02 04:41:03
问题 The Problem I trained a linear regression in R to predict this.target from city , variables in data frame data . This trainig is done on a subset of the data, which is specified by train.index . model = glm('data[, this.target] ~ data$city', data = data, subset = train.index) I am trying to test this model on the held out data, which is specified by test.index . predictions = predict(model, data[test.index, ]) For whatever reason, this second step creates an error and a warning. Error in

Coxph predictions don't match the coefficients

早过忘川 提交于 2019-12-02 04:04:12
Good afternoon, I could post reproducible code and certainly will if everyone agrees that something is wrong, but right now I think my question is quite simple and someone will point me the right path. I am working in a data set like this: created_as_free_user t c <fctr> <int> <int> 1 true 36 0 2 true 36 0 3 true 0 1 4 true 28 0 5 true 9 0 6 true 0 1 7 true 13 0 8 true 19 0 9 true 9 0 10 true 16 0 I fitted a Cox Regression model like this: fit_train = coxph(Surv(time = t,event = c) ~ created_as_free_user ,data = teste) summary(fit_train) And received: Call: coxph(formula = Surv(time = t, event

predict with Keras fails due to faulty environment setup

旧街凉风 提交于 2019-12-02 03:53:45
问题 I can't get Keras to predict anything. Not even in this minimalistic model: from keras.models import Sequential from keras.layers import Dense import numpy as np inDim = 3 outDim = 1 model = Sequential() model.add(Dense(5, input_dim=inDim, activation='relu')) model.add(Dense(outDim, activation='sigmoid')) model.compile(loss='mse', optimizer='adam', metrics=['accuracy']) test_input = np.zeros((1,inDim)) test_output = np.zeros((1,outDim)) model.fit(test_input, test_output) prediction = model

Error with predict and glm.predict in R

一曲冷凌霜 提交于 2019-12-02 02:13:45
The Problem I trained a linear regression in R to predict this.target from city , variables in data frame data . This trainig is done on a subset of the data, which is specified by train.index . model = glm('data[, this.target] ~ data$city', data = data, subset = train.index) I am trying to test this model on the held out data, which is specified by test.index . predictions = predict(model, data[test.index, ]) For whatever reason, this second step creates an error and a warning. Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : invalid type (NULL) for

Predict y value for a given x in R

懵懂的女人 提交于 2019-12-02 01:37:33
I have a linear model: mod=lm(weight~age, data=f2) I would like to input an age value and have returned the corresponding weight from this model. This is probably simple, but I have not found a simple way to do this. If your purposes are related to just one prediction you can just grab your coefficient with coef(mod) Or you can just build a simple equation like this. coef(mod)[1] + "Your_Value"*coef(mod)[2] Its usually more robust to use the predict method of lm : f2<-data.frame(age=c(10,20,30),weight=c(100,200,300)) f3<-data.frame(age=c(15,25)) mod<-lm(weight~age,data=f2) pred3<-predict(mod