홈>
이것은 원래 로지스틱 회귀 coefs_ 및 관련 열 레이블에서 목록을 생성 한 방법입니다.
#Create lists
column_labels = X.columns.tolist()
coef = logreg.coef_.squeeze().tolist()
# Zip together
labels_coef = list(zip(column_labels, coef))
#Sort them and present them as a list
sorted_labels = sorted(labels_coef, key=lambda x: x[1])
#Plotted the bar chart
plt.barh(*zip(* sorted(sorted_labels[:5] +sorted_labels[-5:],key=lambda x: x[1] )))
#or
#plt.barh(*zip(* (sorted_labels[:5] +sorted_labels[-5:])))
#Show plot
plt.show()
그러나 두 그래프를 같은 그래프에 값의 오름차순으로 인쇄하는 방법은 무엇입니까?
분명히, 이것은 속임수를 쓰지 않습니다
-
답변 # 1
-
답변 # 2
알겠습니다. 며칠간의 작업 끝에 정렬하여 줄거리를 만들었습니다. @AndreyF 답변에 대한 사전 단계가 있는데, 연산자의 itemgetter를 키로 사용합니다. 코드는 다음과 같습니다.
df = pd.DataFrame(list(zip(labels,values))).set_index(1)
df.plot.barh()
처음 5 개와 마지막 5 개를 추가하고 함께 플롯 할 수 있습니다.
수정 : 이 질문에서 분류 문제가 발생했습니다.
Y- 값을 자동으로 정렬하는 Pylot
두 가지 제안 된 해결책은 다음과 같습니다. <올>
데이터를 숫자로 표시하고 y_labels 추가 :
와이즈 비즈 와이즈 비즈