我不明白Keras的嵌入层.虽然有很多文章解释它但我仍然感到困惑.例如,下面的代码来自imdb情感分析
top_words = 5000
max_review_length = 500
embedding_vecor_length = 32
model = Sequential()
model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))
model.add(LSTM(100))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X_train, y_train, nb_epoch=3, batch_size=64)
Run Code Online (Sandbox Code Playgroud)
在这段代码中,嵌入层究竟是做什么的,嵌入层的输出是什么,如果有人可以用一些例子解释它,那将是很好的!!
假设我有一个如下的数据框.我想要的是,如果列a,b,c之间的数字出现最多,那么它应输出该数字,或者如果所有三个数字不同,则取a的数字.例如,在第一行中,1出现在1和5中最多,然后d中的输出为1.但在第二行中,列a,b,c的所有三个数字11,2,7都不同,输出是列的值a(11),因此d中的输出为11
list a b c
1 1 5 1
11 11 2 7
0 0 0 0
9 5 9 5
8 8 2 7
Run Code Online (Sandbox Code Playgroud)
预期产出
list a b c d
1 1 5 1 1
11 11 2 7 11
0 0 0 0 0
9 5 9 5 5
8 8 2 7 8
Run Code Online (Sandbox Code Playgroud) 我与用户和学期有以下关联。我创建了以学期ID作为外键的用户表。因此,如果不存在学期ID,则不会创建用户。但是在注册表格中,学期ID是可选的。
class User < ApplicationRecord
belongs_to :semester
end
class Semester < ApplicationRecord
has_many :users
end
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :email
t.references :semester, foreign_key: true
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
那么,如何创建另一个迁移来删除外键约束呢?因此,在用户表中,我应该有两列email和semester_id,但semester_id不应具有外键约束,因为它是一个可选字段。
我有这个代码适用于二进制分类.我已经为keras imdb数据集测试了它.
model = Sequential()
model.add(Embedding(5000, 32, input_length=500))
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X_train, y_train, epochs=3, batch_size=64)
# Final evaluation of the model
scores = model.evaluate(X_test, y_test, verbose=0)
Run Code Online (Sandbox Code Playgroud)
我需要将上面的代码转换为多类别分类,总共有7个类别.在阅读了几篇文章以转换上面的代码之后,我理解了什么,我必须改变
model.add(Dense(7, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
显然,改变两行以上是行不通的.我还需要做些什么来使代码适用于多类分类.另外我认为我必须将类更改为一个热编码但不知道如何在keras中.
我需要在heroku上安装这个包
apt-get install python3-tk
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何安装它吗?我试过上面的命令,但我收到这条消息
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python3-tk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
W: Not using locking for read only lock file /var/lib/dpkg/lock
E: Package 'python3-tk' has no installation candidate
Run Code Online (Sandbox Code Playgroud) 假设我有一个如下数据帧
a b c
1 1 45
0 2 74
2 2 54
1 4 44
Run Code Online (Sandbox Code Playgroud)
现在我想要列a和b不相同的行.所以预期的输出是
a b c
0 2 74
1 4 44
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
当我第一次安装 eclipse 时,我发现它有一个很好的功能。将文件添加到 git 并提交更改后,对该文件的任何新更改都将在 Eclipse 中以灰色显示。我可以将鼠标悬停在更改的行的左侧,并且 Eclipse 会向我显示我在那里所做的更改。我发现它非常有用并且经常使用它。更重要的是我可以一目了然地看到文件中的所有更改。在进行一些随机设置更改后,突然此功能从 Eclipse 中消失了。现在我无法再次打开该功能。如果有人知道如何恢复该功能,那就太好了。