我试图根据文本描述(‘eng’)预测no.of更新(‘sys_mod_count’)
我已经将“sys_mod_count”预定义为两个类,如果>=17为1;<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 predictionsimport 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))发布于 2019-05-31 16:26:29
这似乎是一个阈值设置问题-您想要设置一个阈值,在此进行某种分类。没有监督分类器可以为您设置阈值,因为如果它没有任何带有二进制类的培训数据,那么您就不能训练cvlassifier,要创建培训数据,首先需要设置阈值。这是鸡和蛋的问题。
如果您有某种方法来识别哪个二进制标签是正确的,那么您可以改变阈值并度量类似于建议的这里的错误。然后,您可以根据阈值在二进制标签上运行分类器,也可以在sys_mod_count上运行Regressor,然后根据识别的阈值将其转换为二进制。
如果您无法识别正确的二进制标签,上述方法将无法工作。然后,您要解决的问题是根据sys_mod_count变量的值在点之间创建一些边界。这是无监督的学习。因此,像集群这样的技术在这里是有帮助的。您可以根据各点之间的距离将数据聚为两个集群,然后标记每个集群,这将成为您的二进制标记。
https://stackoverflow.com/questions/56386608
复制相似问题