我用一组数据 (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) 我对新手问题表示歉意,但我是 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) 当我使用我的模型进行一些预测时遇到问题,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) 我有一个名为定期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_true和y_pred都是张量对象,keras.model.predict希望传递给numpy.array。
知道如何keras.model在自定义损失函数中成功使用我的方法吗?
如果需要,我愿意获取指定层的输出,也可以将其转换keras.model为tf.estimator对象(或其他任何对象)。
我正在进行手动网格搜索以找到 keras 模型的最佳参数。对于每个参数组合,我检查其验证精度是否优于先前训练的模型而不是克隆该模型,以便在检查所有参数组合后,可以使用具有最佳验证精度的模型在测试集上进行预测。问题是:为什么预测函数对于克隆模型的行为不同:'
我运行 Model.fit (...)
比 Model.predict (X_test) -- 它给我标签编码输出并且:当我像这样克隆这个模型时:
BestModel = keras.models.clone_model(model.model)
BestModel.predict (X_test) 给出概率。
ps:我的目标类首先是标签编码,然后是一个热编码形式。
如果我们使用“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) 嗨,我正在研究在 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) 我想要做的就是下载 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) 我正在使用 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 包相关的问题吗?
我有一个包含 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)
我究竟做错了什么?
predict ×10
r ×4
keras ×3
python ×2
tensorflow ×2
xgboost ×2
glmmtmb ×1
lme4 ×1
lmer ×1
model ×1
nls ×1
pandas ×1
python-3.x ×1
regression ×1
sequential ×1