加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hic_visualizations.py 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
席理加 提交于 2020-06-12 16:50 . 提交数据集和代码
#!/usr/bin/env python
# coding: utf-8
from hic import load_hic
import matplotlib.pyplot as plt
import pylab as mpl
import seaborn as sns
import plotly_express as px
import pandas as pd
import numpy as np
dataset = load_hic()
df = dataset.all
def scatter_matrix():
fig = px.scatter_matrix(df, dimensions=["age", "charges", "bmi"],
color = "sex")
fig.show()
fig = px.scatter_matrix(df, dimensions=["age", "charges", "bmi"],
color = "region")
fig.show()
fig = px.scatter_matrix(df, dimensions=["age", "charges", "bmi"],
color = "smoker")
fig.show()
fig = px.scatter_matrix(df, dimensions=["age", "charges", "bmi"],
color = "children")
fig.show()
def swarmplot():
# swarm plot
plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = (15, 8)
sns.swarmplot(x='region', y='bmi', data=df, palette = 'copper')
plt.title('Region vs BMI', fontsize = 20)
plt.show()
sns.swarmplot(x='sex', y='bmi', data=df, palette = 'copper')
plt.title('Sex vs BMI', fontsize = 20)
plt.show()
sns.swarmplot(x='smoker', y='bmi', data=df, palette = 'copper')
plt.title('Smoker vs BMI', fontsize = 20)
plt.show()
sns.swarmplot(x='region', y='charges', data=df, palette = 'copper')
plt.title('Region vs Charges', fontsize = 20)
plt.show()
sns.swarmplot(x='sex', y='charges', data=df, palette = 'copper')
plt.title('Sex vs Charges', fontsize = 20)
plt.show()
sns.swarmplot(x='smoker', y='charges', data=df, palette = 'copper')
plt.title('Smoker vs Charges', fontsize = 20)
plt.show()
from sklearn.preprocessing import LabelEncoder
def relview():
def labelencoder(X, features):
le = LabelEncoder()
names = X.columns
print(names, names.dtype)
for feature in features:
le.fit(X[feature])
tfFeature = le.transform(X[feature])
X = X.drop(feature, axis=1)
X = pd.concat([X, pd.Series(tfFeature, index=X.index, name=feature)], axis=1)
# print(X.head())
return X
categorical_features = ["sex", "region", "smoker"]
# df1 = labelencoder(df, categorical_features)
_ = sns.pairplot(df, kind='reg', diag_kind='kde')
plt.show()
relview()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化