I'm interested in exporting a correlation matrix to csv. I've tried using the to.csv functionality, but my matrix is obtained from a function and I get an "object has no attribute 'to_csv'" error. I appreciate any guidance. Code is below.
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm as cm
def correlation_matrix(df):
fig = plt.figure()
ax1 = fig.add_subplot(111)
cmap = cm.get_cmap('jet', 30)
cax = ax1.imshow(df.corr(), interpolation="nearest", cmap=cmap)
ax1.grid(True)
plt.title('Feature Correlation')
labels = None
# Add colorbar, and make sure to specify tick locations to match desired ticklabels.
cbar = fig.colorbar(cax, ticks=[-1.1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6,.8,1])
plt.show()
correlation_matrix(pd.DataFrame(np.c_[Xs,Y]))