我正在使用 scikit learn 上可用的 LinearSVC() 將文本分類為最多 7 個標簽。所以,這是一個多標簽分類問題。我正在對少量資料進行培訓并對其進行測驗。現在,我想將更多資料(根據標準從池中檢索)添加到擬合模型并在同一測驗集上進行評估。如何才能做到這一點?
問題:
有必要將之前的資料集與新的資料集合并,對所有內容進行預處理,然后重新訓練,看看舊資料 新資料是否會提高性能?
到目前為止,我的代碼如下:
def preprocess(data, x, y):
global Xfeatures
global y_train
global labels
porter = PorterStemmer()
multilabel=MultiLabelBinarizer()
y_train=multilabel.fit_transform(data[y])
print("\nLabels are now binarized\n")
data[multilabel.classes_] = y_train
labels = multilabel.classes_
print(labels)
data[x].apply(lambda x:nt.TextFrame(x).noise_scan())
print("\English stop words were extracted\n")
data[x].apply(lambda x:nt.TextExtractor(x).extract_stopwords())
corpus = data[x].apply(nfx.remove_stopwords)
corpus = data[x].apply(lambda x: porter.stem(x))
tfidf = TfidfVectorizer()
Xfeatures = tfidf.fit_transform(corpus).toarray()
print('\nThe text is now vectorized\n')
return Xfeatures, y_train
Xfeatures, y_train = preprocess(df1, 'corpus', 'zero_level_name')
Xfeatures_train=Xfeatures[:300]
y_train_features = y_train[:300]
X_test=Xfeatures[300:400]
y_test=y_train[300:400]
X_pool=Xfeatures[400:]
y_pool=y_train[400:]
def model(modelo, tipo):
svc= modelo
clf = tipo(svc)
clf.fit(Xfeatures_train,y_train_features)
clf_predictions = clf.predict(X_test)
return clf_predictions
preds_pool = model(LinearSVC(class_weight='balanced'), OneVsRestClassifier)
uj5u.com熱心網友回復:
這取決于你以前的資料集是怎樣的。如果您之前的資料集很好地代表了您手頭的問題,那么添加更多資料不會大幅提高您的模型性能。因此,您可以使用新資料進行測驗。
但是,您的初始資料集也可能沒有足夠的代表性,因此隨著資料的增加,您的分類準確性會提高。因此,在這種情況下,最好包含所有資料并對其進行預處理。因為預處理通常包括在整個資料集上計算的引數。例如,我可以看到您有 TFIDF,或對手頭資料集敏感的均值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/508268.html
