我正在尝试使用早期停止和模型检查点来保存最佳模型,同时训练深度卷积神经网络.但是,我收到以下错误:
callback.set_model(model)
AttributeError: 'list' object has no attribute 'set_model'
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码是:
model = Sequential()
###First block
model.add(Conv2D(100,kernel_size = (3,3),activation = 'relu',padding = 'same',input_shape=(12,11,1)))
model.add(Conv2D(100,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.20))
###Second block
model.add(Conv2D(128,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(Conv2D(128,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.10))
model.add(Flatten())
#model.add(Dense(100,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(1000,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dropout(0.30))
model.add(Dense(500,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dropout(0.10))
#model.add(Dense(500,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
#model.add(Dropout(0.15))
model.add(Dense(5,activation = 'softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
earlystop = [EarlyStopping(monitor='val_acc', min_delta=0.001, patience=5, …
Run Code Online (Sandbox Code Playgroud) 我正在做套索逻辑回归。我使用 cv.glmnet 来获取非零系数。它似乎有效,即我确实得到了一些非零系数,其余系数为零。但是,当我使用 coef 函数打印所有系数时,它会给我一个所有系数的列表。有没有办法提取不为零的系数及其名称。我所做的代码是:
cv.lasso = cv.glmnet(x_train,y_train, alpha = 0.6, family = "binomial")
coef(cv.lasso, s=cv.lasso$lambda.1se)
Run Code Online (Sandbox Code Playgroud)
当我使用 coef 时,我得到以下输出:
4797 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) -1.845702
sampleid.10 .
sampleid.1008 .
Run Code Online (Sandbox Code Playgroud)
我想提取非零系数的名称和值。我怎样才能做到这一点?
我有一个列表列表,我想找到出现“ //”的索引。我知道如何使用嵌套循环,但是我想使用列表理解。我的清单是:
ex = [['foo', 'faa'], ['//', 'sd'], ['foo', 'kaa'], ['side', 'haha', 'blue'], ['//', 'sd']]
Run Code Online (Sandbox Code Playgroud)
如何在此处使用列表理解来查找出现“ //”的索引?到目前为止,我所做的是:
indices = [idx for idx, lst in enumerate(ex)]
Run Code Online (Sandbox Code Playgroud)
这给了我列表中列表的索引。但是我不知道如何使用这些来查找'//'
使用列表理解的索引。
对于上面的ex
示例,预期输出为
[1, 4]
Run Code Online (Sandbox Code Playgroud)
例如,对于含有嵌套列表的索引'//'
,这是ex[1]
和ex[4]
。