标签: predict

R语言,非线性模型公式预测

我用一组数据 (x, y) 拟合指数公式。然后我想根据公式计算 y 值,其中 x 值超出实际数据集。它不起作用,总是打印实际 x 值的 y 值。这是代码。我做错了什么?我的 R 语言任务的解决方案是什么:

data <- data.frame(x=seq(1,69), y=othertable[1:69, 2])
nlsxypw <- nls(data$y ~ a*data$x^b, col2_60, start=list(a=2200000, b=0))
predict(nlsxypw)
#here I want to calculate the y values for x = 70-80
xnew <- seq(70, 80, 1)
predict(nlsxypw, xnew)

#it doesn't print these values, still the actual values for x=1~69.
Run Code Online (Sandbox Code Playgroud)

r nls predict

2
推荐指数
1
解决办法
864
查看次数

使用 lme4 建模根据固定效应值进行预测

我对新手问题表示歉意,但我是 lme4 的新手。我正在使用 lme4 对三年内由不同类型的土地利用组成的六个地点中蜂群的生存进行建模,并在使用 REML 消除其他竞争模型后生成了以下模型:

land1=lmer(asin(sqrt(prop_survival))~log(area_forage_uncult) + (1|site) + (1|year))
Run Code Online (Sandbox Code Playgroud)

并制作了摘要:

Linear mixed model fit by REML ['lmerMod']
Formula: asin(sqrt(prop_survival)) ~ log(area_forage_uncult) + (1 | site)+ (1 | year))

REML criterion at convergence: -32.7

Scaled residuals: 
Min      1Q  Median      3Q     Max 
-1.4914 -0.5867 -0.0323  0.4945  1.7873 

Random effects:
 Groups   Name        Variance Std.Dev.
 site     (Intercept) 0.001080 0.03287 
 year     (Intercept) 0.000000 0.00000 
 Residual             0.004983 0.07059 
Number of obs: 18, groups:  site, 6; year, 3

Fixed effects:
                    Estimate Std. Error t …
Run Code Online (Sandbox Code Playgroud)

predict lme4 lmer

2
推荐指数
1
解决办法
3152
查看次数

如何解决我的线性模型上的“秩亏拟合可能是误导性错误”?

当我使用我的模型进行一些预测时遇到问题,R 显示此消息Warning message prediction from a rank-deficient fit may be misleading,我该如何解决?我认为我的模型是正确的是预测失败,我不知道为什么。

在这里你可以一步一步看到我在做什么以及模型的总结:

myModel <- lm(margin~.,data = dataClean[train,c(target,numeric,categoric)])

Call:
lm(formula = margin ~ ., data = dataClean[train, c(target, numeric, categoric)])

Residuals:
  Min        1Q    Median        3Q       Max 
-0.220407 -0.035272 -0.003415  0.028227  0.276727 

Coefficients: (2 not defined because of singularities)
                                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)                          6.061e-01  2.260e-02  26.817  < 2e-16 ***
price                                1.042e-05  8.970e-06   1.162 0.245610    
shipping                             1.355e-03  2.741e-04   4.943 9.25e-07 ***
categoryofficeSupplies              -7.721e-02  2.295e-02  -3.364 0.000802 ***
categorytechnology …
Run Code Online (Sandbox Code Playgroud)

model r predict

2
推荐指数
1
解决办法
2万
查看次数

在定制的keras损失中使用keras模型

我有一个名为定期keras模型e,我想它的输出比较两者y_pred,并y_true在我的自定义损失函数。

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)
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:AttributeError: 'Tensor' object has no attribute 'ndim' 这是因为y_truey_pred都是张量对象,keras.model.predict希望传递给numpy.array

知道如何keras.model在自定义损失函数中成功使用我的方法吗?

如果需要,我愿意获取指定层的输出,也可以将其转换keras.modeltf.estimator对象(或其他任何对象)。

predict keras tensorflow loss-function

2
推荐指数
1
解决办法
761
查看次数

克隆前和克隆后的 keras 模型表现不同

我正在进行手动网格搜索以找到 keras 模型的最佳参数。对于每个参数组合,我检查其验证精度是否优于先前训练的模型而不是克隆该模型,以便在检查所有参数组合后,可以使用具有最佳验证精度的模型在测试集上进行预测。问题是:为什么预测函数对于克隆模型的行为不同:'

  1. 我运行 Model.fit (...)

  2. 比 Model.predict (X_test) -- 它给我标签编码输出并且:当我像这样克隆这个模型时:

  3. BestModel = keras.models.clone_model(model.model)

  4. BestModel.predict (X_test) 给出概率。

ps:我的目标类首先是标签编码,然后是一个热编码形式。

predict neural-network sequential python-3.x keras

2
推荐指数
1
解决办法
3352
查看次数

需要 xgboost.train 概率输出

如果我们使用“predict_proba”方法,XGBClassifier 会输出概率,但是,当我使用 xgboost.train 训练模型时,我无法弄清楚如何获得概率作为输出。这是我的一段代码:

dtrain=xgb.DMatrix(X_train, label=y)
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic'}
modelXG=xgb.train(param,dtrain,xgb_model='xgbmodel')
Run Code Online (Sandbox Code Playgroud)

predict xgboost

2
推荐指数
1
解决办法
3113
查看次数

R 在 Lime 上的解释 - 存储在“object”和“newdata”中的功能名称不同

嗨,我正在研究在 LIME 模型上使用 R 解释。当我运行这部分时一切都很好。

# 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_original$Liked, SplitRatio = 0.8)
training_set = subset(dataset_original, split == TRUE)
test_set = subset(dataset_original, split == FALSE)

#Create & clean corpus
#clean corpus function
clean_text <- function(text) {
  corpus = VCorpus(VectorSource(text))
  corpus = tm_map(corpus, content_transformer(tolower))
  corpus = …
Run Code Online (Sandbox Code Playgroud)

r predict

2
推荐指数
1
解决办法
6100
查看次数

在 tensorflow 模型中关闭 softmax

我想要做的就是下载 tensorflow 的内置模型之一(通过 keras),关闭输出层的 softmax(即用线性激活函数替换它),以便我的输出特征是输出层之前的激活应用了 softmax。

所以,我把 VGG16 作为模型,并称之为 base_model

from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.applications.vgg16 import preprocess_input
base_model = VGG16()
Run Code Online (Sandbox Code Playgroud)

我看看最后一层是这样的:

base_model.get_layer('predictions').get_config()
Run Code Online (Sandbox Code Playgroud)

并得到:

{'name': 'predictions',
 'trainable': True,
 'dtype': 'float32',
 'units': 1000,
 'activation': 'softmax',
 'use_bias': True,
 'kernel_initializer': {'class_name': 'GlorotUniform',
  'config': {'seed': None, 'dtype': 'float32'}},
 'bias_initializer': {'class_name': 'Zeros', 'config': {'dtype': 'float32'}},
 'kernel_regularizer': None,
 'bias_regularizer': None,
 'activity_regularizer': None,
 'kernel_constraint': None,
 'bias_constraint': None}
Run Code Online (Sandbox Code Playgroud)

然后,我这样做是为了切换激活功能:

base_model.get_layer('predictions').activation=tf.compat.v1.keras.activations.linear
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

base_model.get_layer('predictions').get_config()
Run Code Online (Sandbox Code Playgroud)

给出:

{'name': 'predictions',
 'trainable': True,
 'dtype': 'float32',
 'units': 1000,
 'activation': 'linear',
 'use_bias': True,
 'kernel_initializer': …
Run Code Online (Sandbox Code Playgroud)

python predict keras tensorflow transfer-learning

2
推荐指数
1
解决办法
732
查看次数

如何使用 glmmTMB 的预测函数拟合置信区间

我正在使用 glmmTMB 包运行混合模型,并使用预测函数使用以下代码计算预测平均值:

运行模型

model_1 <- glmmTMB(Step.rate ~ Treatment*Week + 
    (1|Treatment.Group/Lamb.ID) +  (1|Plot),
     data = data.df, family = nbinom1) 
Run Code Online (Sandbox Code Playgroud)

创建新的数据框

new.dat <- data.frame(Treatment = data.df$Treatment,
                      Week = data.df$Week, Plot = data.df$Plot, 
                      Treatment.Group = data.df$Treatment.Group,
                      Lamb.ID = data.df$Lamb.ID) 
Run Code Online (Sandbox Code Playgroud)

预测平均值

new.dat$prediction <- predict(model_1, new.data = new.dat, 
       type = "response", re.form = NA) 
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,但是当我添加Interval =“confidence”来计算置信区间时,它似乎不起作用。R 忽略代码的最后部分,仅计算预测平均值。

new.dat$prediction <- predict(model_1, new.data = new.dat, 
     type = "response", re.form = NA, intervals = "confidence")
Run Code Online (Sandbox Code Playgroud)

为什么间隔=“置信度”不起作用?这可能是与 glmmTMB 包相关的问题吗?

r predict confidence-interval glmmtmb

2
推荐指数
1
解决办法
3107
查看次数

使用 Xgboost 进行非线性回归

我有一个包含 36540 行的数据框。目标是预测y HITS_DAY

#数据

https://github.com/soufMiashs/Predict_Hits

在此输入图像描述

我正在尝试训练非线性回归模型,但模型似乎并没有学到太多东西。

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.20, random_state=42)
data_dmatrix = xgb.DMatrix(data=x,label=y)

xg_reg = xgb.XGBRegressor(learning_rate = 0.1, objectif='reg:linear', max_depth=5,
                          n_estimators = 1000)

xg_reg.fit(X_train,y_train)
preds = xg_reg.predict(X_test)
df=pd.DataFrame({'ACTUAL':y_test, 'PREDICTED':preds})
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

python regression predict pandas xgboost

2
推荐指数
1
解决办法
3335
查看次数