, लेकिन मैं की तरह महसूस:
import pandas.rpy.common as com
import seaborn as sns
%matplotlib inline
# load the R package ISLR
infert = com.importr("ISLR")
# load the Auto dataset
auto_df = com.load_data('Auto')
# calculate the correlation matrix
corr = auto_df.corr()
# plot the heatmap
sns.heatmap(corr,
xticklabels=corr.columns,
yticklabels=corr.columns)
आप और भी अधिक फैंसी होना चाहते थे, तो आप Pandas Style उदाहरण के लिए उपयोग कर सकते हैं, यह घोषणा करने के बाद मैंने जो कुछ रखा, उसका योगदान करना कि बकाया समुद्री शैवाल को तोड़ना था। निम्नलिखित स्निपेट समुद्र तट गर्मी के आधार पर एक समान सहसंबंध साजिश बनाता है। आप रंग सीमा भी निर्दिष्ट कर सकते हैं और डुप्लिकेट सहसंबंधों को छोड़ना चुन सकते हैं या नहीं। ध्यान दें कि मैंने आपके समान संख्याओं का उपयोग किया है, लेकिन मैंने उन्हें एक पांडा डेटाफ्रेम में रखा है। रंगों की पसंद के संबंध में आप sns.diverging_palette के दस्तावेज़ों पर एक नज़र डाल सकते हैं।
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# A list with your data slightly edited
l = [1.0,0.00279981,0.95173379,0.02486161,-0.00324926,-0.00432099,
0.00279981,1.0,0.17728303,0.64425774,0.30735071,0.37379443,
0.95173379,0.17728303,1.0,0.27072266,0.02549031,0.03324756,
0.02486161,0.64425774,0.27072266,1.0,0.18336236,0.18913512,
-0.00324926,0.30735071,0.02549031,0.18336236,1.0,0.77678274,
-0.00432099,0.37379443,0.03324756,0.18913512,0.77678274,1.00]
# Split list
n = 6
data = [l[i:i + n] for i in range(0, len(l), n)]
# A dataframe
df = pd.DataFrame(data)
def CorrMtx(df, dropDuplicates = True):
# Your dataset is already a correlation matrix.
# If you have a dateset where you need to include the calculation
# of a correlation matrix, just uncomment the line below:
# df = df.corr()
# Exclude duplicate correlations by masking uper right values
if dropDuplicates:
mask = np.zeros_like(df, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Set background color/chart style
sns.set_style(style = 'white')
# Set up matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
# Add diverging colormap from red to blue
cmap = sns.diverging_palette(250, 10, as_cmap=True)
# Draw correlation plot with or without duplicates
if dropDuplicates:
sns.heatmap(df, mask=mask, cmap=cmap,
square=True,
linewidth=.5, cbar_kws={"shrink": .5}, ax=ax)
else:
sns.heatmap(df, cmap=cmap,
square=True,
linewidth=.5, cbar_kws={"shrink": .5}, ax=ax)
CorrMtx(df, dropDuplicates = False)
यहाँ जिसके परिणामस्वरूप साजिश है:
आप नीले के लिए कहा, लेकिन वह अपने नमूना डेटा में सीमा से बाहर हो जाता है। 0.95173379 से -0 बदलें।दोनों टिप्पणियों के लिए 95173379 और आप इस मिल जाएगा:
मैं तो आप जाँच कर सकते हैं सवाल संपादित किया है। – Marko