【问题标题】:What does this scale means?这个比例是什么意思?
【发布时间】:2021-09-15 21:13:22
【问题描述】:

我试图通过使用我找到的代码来查看数据集中最有贡献的特征。代码如下

def f_importances(coef, names):
    imp = coef
    imp,names = zip(*sorted(zip(imp,names)))
    plt.barh(range(len(names)), imp, align='center')
    plt.yticks(range(len(names)), names)
    plt.show()

features_names = ['text', 'jumlah kata', 'jam']

n_classes = 3
n_features = len(features_names)

clf_coef_ = np.random.randint(1, 30, size=(int(0.5*n_classes*(n_classes-1)), n_features))

f_importances(clf_coef_.sum(axis=0), features_names)

从该代码中,我得到了以下结果

我的问题是

  1. X 平面上的数字是什么意思?有 10、20、30 等等。我无法询问上传者。
  2. 这似乎是随机的。如何让它不随机?例如我想使用所有的数据

【问题讨论】:

    标签: python matplotlib machine-learning svm


    【解决方案1】:

    第一个问题:

    features_names = ['text', 'jumlah kata', 'jam']
    
    n_classes = 3
    n_features = len(features_names)
    
    clf_coef_ = np.random.randint(1, 30, size=(int(0.5*n_classes*(n_classes-1)), n_features))
    
    # clf_coef_ is a 3*3 random matrix
    # each of its value is in range(1,30)
    # for example
    # [[22  4 22]
    #  [15 18  8]
    #  [23 22 13]]
    
    f_importances(clf_coef_.sum(axis=0), features_names)
    # clf_coef_.sum(axis=0)
    # summary on columns
    #
    # [22+15+23,  4+18+22,   22+8+13]
    # then it will become [60, 44, 43]
    
    # f_importances finally will take arguments:
    # [60,44,43] & ['text', 'jumlah kata', 'jam']
    # sequence is corresponded
    # sorted by values (this may differ with your codes, due to random values)
    # jam  --> 43
    # jumlah kata  --> 44
    # text --> 60
    # then plot will be got
    

    要回答您的第二个问题,您可以将clf_coef_ 不定义为随机数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 2018-10-29
      • 1970-01-01
      • 2017-05-25
      • 2010-10-03
      • 2013-02-21
      • 2015-01-09
      相关资源
      最近更新 更多