我想顯示我的目標變數的最高相關性結果。但是,它為我創建了這樣的矩陣,我希望這些結果在表格中從最大到最小顯示。最好添加一些情節。怎么做 ?我希望結果SalePrice僅限于,而不是下表
korelacja = train.corr()
sns.heatmap(korelacja, vmax=0.9, square=True,cmap='coolwarm')
a = korelacja[korelacja['SalePrice']>0.3]
a

uj5u.com熱心網友回復:
一個非常簡單的例子:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(-100, 100, (10000, 8)), columns=list("ABCDEFGH"))
df.corr()["H"].loc[df.columns != "H"].\
sort_values(ascending=False).plot(kind="bar")
這一切都在一條線上,而不是像你那樣被分開。分開:
# Correlation matrix
df1 = df.corr()
# Column H of the data frame, and remove row H (as this will obviously be 1, the highest)
df1 = df1["H"].loc[df1.columns != "H"]
# sort the values in descending order
df1.sort_value(ascending=False, inplace=True)
# plot a bar chart
df1.plot(kind="bar")
專門使用您的資料:
# correlation matrix
korelacja = train.corr()
# SalePrice column only
korelacja = korelacja["SalePrice"].loc[korelacja.columns != "SalePrice"]
# sort values
korelacja.sort_values(ascending=False, inplace=True)
# condition
korelacja = korelacja[korelacja > 0.3]
# plot bar chart
korelacja.plot(king="bar")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/479731.html
上一篇:熊貓每周計算重復值
下一篇:Pandas:每年生成兩個日期
