高斯混合模型抛出错误:'(slice(None, None, None), 0)'是无效键



我试图找出一种方法来绘制前 10 个"重要性"。 如何仅筛选出前 10 名?

我正在测试此代码。

# Import matplotlib for plotting and use magic command for Jupyter Notebooks
import matplotlib.pyplot as plt
# %matplotlib inline
# Set the style
plt.style.use('fivethirtyeight')
# list of x locations for plotting
x_values = list(range(len(importances)))
# Make a bar chart
plt.bar(x_values, importances, orientation = 'vertical')
# Tick labels for x axis
plt.xticks(x_values, feature_list, rotation='vertical')
# Axis labels and title
plt.ylabel('Importance'); plt.xlabel('Variable'); plt.title('Variable Importances')

例如,我认为它会像这样工作:

importances.nlargest(10)

当然,这行不通。

无论如何,如果我打印"重要性",我就会得到这个。

[0.014491770647044457,
0.00019361234623574235,
3.1654130115528675e-05,
2.2282968409838985e-09,
3.2692807408152015e-09,
4.384096695290309e-10,
0.00042439694271008773,
5.237777494120531e-07,
0.001811981822169592,
8.763153025774294e-05,
0.0006285414711295239,
0.0019943872516235126,
0.008064958626964689,
1.5713284855142127e-09,
3.4880330238871455e-07,
9.569576607849658e-08,
4.905092782324521e-07,
3.04975913750217e-08,
0.0007710174613522453,
0.010110214591790158,
2.218810309666371e-06,
0.06635437174813848,
7.094141851738553e-09,
0.09692579151784199,
6.266476641239394e-07,
0.0005677407074106191,
4.33439485665928e-09,
6.729704013292786e-09,
5.448251307127653e-09,
0.07222976995890511,
4.177476454941959e-09,
0.06379521041327217,
4.143632970341204e-08,
0.0,
0.0,
1.6852849006394362e-07,
3.444763728488421e-05,
0.00027783757981549023,
0.00026552081342128665,
0.0027951966216271645,
1.756238666420933e-08,
5.36418731927759e-07,
1.8587336907357295e-08,
1.724316065593696e-06,
4.8075445998997775e-09,
5.0946253981707984e-09,
2.4109672351066337e-09,
6.122816335970093e-07,
2.98653718456776e-08,
1.440685077013712e-08,
3.4814858022082307e-07,
4.9143061686861475e-09,
5.560563276141058e-09,
2.100160313340503e-07,
1.858585731919769e-07,
2.9302956455099447e-10,
1.0676724849696455e-07,
9.205202160096533e-08,
3.238590336881132e-09,
2.9359031523272006e-09,
3.7106613254445946e-08,
0.0,
7.50949849787628e-09,
4.31454496750231e-07,
2.864722788138877e-09,
0.00029555925564843296,
0.018288095727344335,
2.3235414188992915e-05,
1.4724817163996177e-06,
1.83332179664834e-10,
6.5835933557009485e-09,
3.4995919613648777e-08,
1.5791218246276666e-09,
8.543955452925974e-10,
0.0020876600982017773,
1.3271736183875074e-06,
7.097092415371366e-09,
1.1362350498921358e-06,
2.596444953750965e-07,
3.136898750550819e-06,
0.006061284819096849,
1.5073623701901606e-08,
0.0,
3.310508863330544e-10,
4.012406143727027e-07,
3.88598894478961e-10,
7.25246298208171e-09,
2.8319415813159036e-07,
2.7331184262991413e-08,
3.833752596597012e-09,
8.11433296197117e-09,
4.724264918239267e-09,
2.8950794365442764e-10,
3.507963799042248e-09,
1.5810463846782645e-06,
3.1443812975880694e-08,
2.2369371106304586e-08,
5.175362771499234e-10,
1.2536062933757747e-07,
1.7255185496828274e-08,
3.530020584895972e-10,
0.0,
6.824913713173602e-06,
6.614160172490679e-09,
5.8441361773804216e-09,
3.107053566891105e-08,
1.1887553210153202e-08,
1.2147831771421017e-07,
3.847667195219461e-07,
2.0541139213845712e-07,
6.367649972302635e-09,
0.0,
8.713550587152909e-09,
3.348791245078586e-09,
1.249743894834997e-07,
5.024591836321825e-09,
1.1549722525405656e-08,
1.5720375103778552e-09,
1.2061111951654133e-08,
2.204145040115562e-08,
2.6538371008326488e-08,
0.006065658473388039,
1.1261253606401625e-06,
5.3923623114030854e-08,
2.7369694426362433e-08,
2.2715623613698112e-09,
3.267124083622971e-10,
1.3555578552793559e-07,
0.22123522867842335,
1.6121802470302185e-07,
1.0320822141246487e-07,
0.0,
0.00035559600865403307,
5.69666004152515e-09,
8.823972002649428e-09,
1.2623398120425045e-09,
0.1203515135510421,
9.257687093715026e-09,
0.07956702616209582,
6.049395726141352e-08,
0.13345147135296895,
0.06792857593399991,
4.0075569777901097e-07,
0.0003016270514924225,
0.000212157530509232,
4.872071522305804e-07,
0.0018899382796283444,
1.8345580575407573e-08]

这个概念来自这个链接。

https://towardsdatascience.com/random-forest-in-python-24d0893d51c0

试试这个:

sorted(importances,reverse=True)[:10]

最新更新