# 数据集中的分类变量之间的相关性

• 对于两个变量，我从Cramers V中获得了1.0，但是，当我使用TheilU方法时，我只有0.2，我不确定如何解释两个变量之间的关系吗？
• 同样对于有经验的人，如果我得到0.73的2个变量的相关性，是否应该为预测模型删除一个变量？

``````import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt
#%matplotlib inline
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder

from sklearn.metrics import classification_report, confusion_matrix, precision_recall_curve, auc, roc_curve
from sklearn.tree import DecisionTreeClassifier, export_graphviz
import graphviz

df.columns

# The data is categorial so I convert it with LabelEncoder to transfer to ordinal.

labelencoder=LabelEncoder()
for column in df.columns:
df[column] = labelencoder.fit_transform(df[column])

#df.describe()

#df=df.drop(["veil-type"],axis=1)

#df_div = pd.melt(df, "class", var_name="Characteristics")
#fig, ax = plt.subplots(figsize=(10,5))
#p = sns.violinplot(ax = ax, x="Characteristics", y="value", hue="class", split = True, data=df_div, inner = 'quartile', palette = 'Set1')
#df_no_class = df.drop(["class"],axis = 1)
#p.set_xticklabels(rotation = 90, labels = list(df_no_class.columns));

#plt.figure()
#pd.Series(df['class']).value_counts().sort_index().plot(kind = 'bar')
#plt.ylabel("Count")
#plt.xlabel("class")
#plt.title('Number of poisonous/edible mushrooms (0=edible, 1=poisonous)');

plt.figure(figsize=(14,12))
sns.heatmap(df.corr(),linewidths=.1,cmap="YlGnBu", annot=True)
plt.yticks(rotation=0);
``````

``````dfDummies = pd.get_dummies(df)

plt.figure(figsize=(14,12))
sns.heatmap(dfDummies.corr(),linewidths=.1,cmap="YlGnBu", annot=True)
plt.yticks(rotation=0);
``````

http://queirozf.com/entries/one-hot-encoding-a-feature-on-a-pandas-dataframe-an-example

https://www.kaggle.com/haimfeld87/analysis-and-classification-of-mushrooms/data

0条评论