代码拉取完成,页面将自动刷新
#!/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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。