【发布时间】:2021-05-13 17:59:09
【问题描述】:
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import GridSearchCV
import seaborn as sns
import matplotlib.pyplot as plt`enter code here`
data = pd.read_csv('task_d.csv')
data.head()
输出
x y z x*x 2*y 2*z+3*x*x w target
0 -0.581066 0.841837 -1.012978 -0.604025 0.841837 -0.665927 -0.536277 0
1 -0.894309 -0.207835 -1.012978 -0.883052 -0.207835 -0.917054 -0.522364 0
2 -1.207552 0.212034 -1.082312 -1.150918 0.212034 -1.166507 0.205738 0
3 -1.364174 0.002099 -0.943643 -1.280666 0.002099 -1.266540 -0.665720 0
4 -0.737687 1.051772 -1.012978 -0.744934 1.051772 -0.792746 -0.735054 0
X = data.drop(['target'], axis=1).values
Y = data['target'].values
做扰动测试来检查共线性的存在 任务:1 个逻辑回归¶
data.corr()['target']
输出
x 0.728290
y -0.690684
z 0.969990
x*x 0.719570
2*y -0.690684
2*z+3*x*x 0.764729
w 0.641750
target 1.000000
Name: target, dtype: float64
corr = X.corr()
ax = sns.heatmap(corr,vmin=-1, vmax=1, center=0,cmap=sns.diverging_palette(20, 220, n=200),square=True)
ax.set_xticklabels(ax.get_xticklabels(),rotation=45,horizontalalignment='right');
输出
AttributeError Traceback (most recent call last)
<ipython-input-42-749cdea8ad1a> in <module>
1 ##correlation matrix using seaborn heatmap##https://towardsdatascience.com/better-heatmapscorr = X.corr()
----> 2 corr = X.corr()
3 ax = sns.heatmap(corr,vmin=-1, vmax=1, center=0,cmap=sns.diverging_palette(20, 220, n=200),square=True)
4 ax.set_xticklabels(ax.get_xticklabels(),rotation=45,horizontalalignment='right');
AttributeError: 'numpy.ndarray' object has no attribute 'corr'
我该如何解决这个问题?
【问题讨论】:
-
您好,您的问题得到解答了吗?如果是这样,您能否接受并投票赞成答案?如果不是,可以澄清什么?
标签: python pandas machine-learning scikit-learn