【问题标题】:decision tree algorithm on feature set特征集上的决策树算法
【发布时间】:2019-10-16 14:28:29
【问题描述】:

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

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

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

我正在考虑用决策树/随机森林方法来训练分类器的特征集。


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))


【问题讨论】:

  • 不清楚你的问题是什么。
  • @AbhineetGupta 我想让分类器用决策树或随机森林方法决定'updates_Binary'值,而不是像上面那样在朴素拜仁方法中预先定义这个值。

标签: python random-forest decision-tree tf-idf naivebayes


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-05-15
    • 2017-10-11
    • 2018-08-16
    • 1970-01-01
    • 2016-07-29
    • 2021-07-25
    • 2019-12-11
    • 2020-02-02
    • 2017-07-11
    相关资源
    最近更新 更多