gpt4 book ai didi

python - 深度学习: How to deal with missing label values

转载 作者:行者123 更新时间:2023-12-01 07:50:05 26 4
gpt4 key购买 nike

我需要使用深度学习将输入向量分为 10 个类别(数字从 0 到 9)。为此,我有两个训练数据集:一个已标记 (n=9000),另一个未标记 (n=21000)。

我应该使用标记的训练数据集来训练我的模型,还是使用它首先预测未标记的训练数据集的标签,然后使用所有训练数据训练模型?您建议采取哪些其他方法?可以使用自动编码器吗?

我已经尝试使用标记的训练数据来预测未标记数据的标签。但是,我还没有达到很好的准确性。我想知道这是由估算数据还是模型引起的。

###Load data
train_labeled = pd.read_hdf("train_labeled.h5", "train")
train_unlabeled = pd.read_hdf("train_unlabeled.h5", "train")
test = pd.read_hdf("test.h5", "test")

X_labeled = np.array(train_labeled.iloc[:,1:])
X_unlabeled = np.array(train_unlabeled)
y_labeled = np.array(train_labeled.iloc[:,0])

###Impute missing values
from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=5)
neigh.fit(X_labeled, y_labeled)
y_unlabeled = neigh.predict(X_unlabeled)

###Combine data
X = np.concatenate((X_labeled, X_unlabeled), axis=0)
y = np.concatenate((y_labeled, y_unlabeled), axis=0)

###Split train and test data
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size = 0.8)

###Create model
model = tf.keras.Sequential([
layers.BatchNormalization(),
layers.Dense(80, activation='relu', input_shape=(X_train.shape[1],)),
layers.Dense(80, activation=tf.nn.relu),
layers.Dense(10, activation=tf.nn.softmax)])

model.compile(optimizer=tf.train.AdamOptimizer(0.001),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

###Train model
model.fit(X_train, y_train, epochs=10, batch_size=20,
validation_data=(X_test, y_test))

最佳答案

处理数据情况(小标记+大未标记数据)的一种方法称为半监督学习。

直接使用在小型标记训练数据上训练的模型有其自身的问题。如果您的初始模型精度不够好或者您的标记训练数据有偏差,那么您将看到错误传播到生成的标签。

让半监督学习能够被接受是相当具有挑战性的,我建议查看阶梯网络、伪标签和度量学习论文,以尝试更有原则的方法。

关于python - 深度学习: How to deal with missing label values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56279496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com