график распределения значений функций - PullRequest
0 голосов
/ 14 марта 2019

Я сделал выборку объектов в моем фрейме данных на основе этого: https://towardsdatascience.com/feature-selection-using-random-forest-26d7b747597f

в части 7 для построения распределения важности предоставляет этот код:

pd.series(sel.estimator_,feature_importances_,.ravel()).hist()

, которыйЯ думаю, что это должно быть так, чтобы не иметь синтаксической ошибки:

pd.series(sel.estimator_,feature_importances_.ravel()).hist()

, и я получил эту ошибку:

AttributeError: модуль 'pandas' не имеет атрибута 'series'

и я думаю, что estimator_ и feature_importances_ тоже не определены.Есть ли способ отладки этой строки кода?enter image description here

1 Ответ

1 голос
/ 14 марта 2019
pd.Series(sel.estimator_.feature_importances_.ravel()).hist()

Это "серия", а не "серия"

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.hist.html

Важность функции черчения

importances = sel.estimator_.feature_importances_
indices = np.argsort(importances)[::-1]
# X is the train data used to fit the model 
plt.figure()
plt.title("Feature importances")
plt.bar(range(X.shape[1]), importances[indices],
       color="r", align="center")
plt.xticks(range(X.shape[1]), indices)
plt.xlim([-1, X.shape[1]])
plt.show()

Это должно отображать гистограмму, как показано нижегде ось X - это индексы объектов, а ось Y - важность объектов.Функции отсортированы в порядке важности.enter image description here

...