0

我正在尝试根据文本描述('eng')预测更新次数('sys_mod_count')

如果 >=17 为 1,我已将“sys_mod_count”预定义为两个类;<17 为 0。

但我想删除这个条件,因为这个值在现实世界中的决策时不可用。

我正在考虑在决策树/随机森林方法中执行此操作,以在特征集上训练分类器。


def train_model(classifier, feature_vector_train, label, feature_vector_valid, is_neural_net=False):
    # fit the training dataset on the classifier
    classifier.fit(feature_vector_train, label)
    # predict the labels on validation dataset
    predictions = classifier.predict(feature_vector_valid)
    # return metrics.accuracy_score(predictions, valid_y)
    return predictions

import pandas as pd
from sklearn import model_selection, preprocessing, linear_model, naive_bayes, metrics, svm
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer

df_3 =pd.read_csv('processedData.csv', sep=";")
st_new = df_3[['sys_mod_count','eng','ger']]
st_new['updates_binary'] = st_new['sys_mod_count'].apply(lambda x: 1 if x >= 17 else 0)
st_org = st_new[['eng','updates_binary']]
st_org = st_org.dropna(axis=0, subset=['eng']) #Determine if column 'eng'contain missing values are removed
train_x, valid_x, train_y, valid_y = model_selection.train_test_split(st_org['eng'], st_org['updates_binary'],stratify=st_org['updates_binary'],test_size=0.20)
tfidf_vect = TfidfVectorizer(analyzer='word', token_pattern=r'\w{1,}', max_features=5000)
tfidf_vect.fit(st_org['eng'])
xtrain_tfidf =  tfidf_vect.transform(train_x)
xvalid_tfidf =  tfidf_vect.transform(valid_x)

# Naive Bayes on Word Level TF IDF Vectors
accuracy = train_model(naive_bayes.MultinomialNB(), xtrain_tfidf, train_y, xvalid_tfidf)
print ("NB, WordLevel TF-IDF: ", metrics.accuracy_score(accuracy, valid_y))


4

1 回答 1

0

这似乎是一个阈值设置问题——您想设置一个阈值,在该阈值上进行某种分类。没有监督分类器可以为您设置阈值,因为如果它没有任何二进制类的训练数据,那么您无法训练 cvlassifier,并且要创建训练数据,您需要设置阈值开始。这是一个先有鸡还是先有蛋的问题。

如果您有某种方法可以确定哪个二进制标签是正确的,那么您可以改变阈值并测量类似于此处建议的错误。然后,您可以根据阈值在二进制标签上运行分类器,也可以在回归器上运行sys_mod_count并根据识别的阈值转换为二进制。

如果您无法确定正确的二进制标签应该是什么,则上述方法不起作用。然后,您要解决的问题是根据sys_mod_count变量的值在点之间创建一些边界。这是无监督学习。因此,聚类等技术在这里会有所帮助。您可以根据点之间的距离将数据聚类为两个集群,然后标记每个集群,这将成为您的二进制标签。

于 2019-05-31T16:26:29.323 回答