如何在散点图中的点之间添加连接线

时间:2019-11-06 19:09:29

标签: python scatter-plot

我做了一个散点图,以显示每种机器学习模型中变量的重要性。我想添加连接线,以显示不同模型之间功能重要性的趋势。例如,在这种情况下,WS始终是所有方法中最重要的功能,因此我希望有一条线连接最高的红点。其他功能的连接线可能会向上或向下。有谁知道如何做到这一点?非常感谢!

当前图的代码为:

img

KNN = [10,  7,  0,  9,  2,  4,  1,  8,  6, 11, 12,  3,  5, 13]
SVM = [ 8, 10,  4, 12,  3,  0,  2,  5, 11,  6,  9,  1,  7, 13]
NN = [ 6, 10,  1, 12,  4,  8,  7,  3,  5,  9, 11,  0,  2, 13]
RF = [ 0,  9,  3, 10,  1,  6,  4,  8,  7, 12, 11,  2,  5, 13]
Adaboost = [ 6,  9,  7, 10,  0,  2,  5,  4,  3, 12, 11,  8,  1, 13]
GBM = [ 9, 11,  7, 10,  1,  0,  4,  6,  5, 12,  8,  3,  2, 13]

VI = pd.DataFrame(
    {'KNN': KNN,
     'SVM':SVM,
     'NN':NN,
     'RF':RF,
     'Adaboost': Adaboost,
     'GBM':GBM
    }, columns=['KNN', 'SVM', 'NN', 'RF', 'Adaboost', 'GBM'])

VI['features'] = features.columns

VI = pd.melt(VI, id_vars=['features'], value_vars=['KNN', 'SVM', 'NN', 'RF', 'Adaboost', 'GBM'])

from sklearn.preprocessing import LabelEncoder
number = LabelEncoder()

VI['features_code'] = number.fit_transform(VI['features'])
VI['variable_code'] = number.fit_transform(VI['variable'])

VI['order'] = [x for x in range(13,-1,-1)]*6

plt.figure(figsize=(10,8))
cmap = sns.color_palette("husl", 14)
ax = sns.scatterplot(x="variable", y="value",
                     hue="features", size="value",
                     palette=cmap, sizes=(50, 1000),
                     data=VI)
ax.set(xticks=range(6), xtickla[enter image description here][1]bels=VI['variable'].unique())
ax.set(yticks=range(14), yticklabels = features.columns[index])
ax.legend(loc='center right', bbox_to_anchor=(1.25, 0.5), ncol=1);
ax.set(xlabel='models', ylabel='features');

0 个答案:

没有答案