Seaborn에 대한 시각화 자료 작성

기계 학습을 위한 여러 가지 방법을 사용할 수 있습니다. Seaborn es una librería para Visualización en Python que contiene una granvariadad de gráficos con mucha Personalización.

기본 낙서



상관 관계의 낙서:

import seaborn as sns
sns.regplot(x='1st_feature', y='2nd_feature', data=df)


Grafico de datos 잔차:

sns.residplot(df['features'], df['target'])


Boxplot(o subplot), para ver outlier:

sns.boxplot(x='1st_feature', y='2nd_feature', data=df)


그래픽 데 덴시다드:

plt.figure(figsize = (14,6))
plt.title('Plot Title')
sns.set_color_codes("pastel")
sns.distplot(df['1st_feature'], kde=True, bins=200, color="blue")
plt.show()


목표 달성을 위한 낙서:

class_0 = df.loc[df['target_feature'] == 0]["1st_feature"]
class_1 = df.loc[df['target_feature'] == 1]["2nd_feature"]
plt.figure(figsize = (14,6))
plt.title('Plot Title')
sns.set_color_codes("pastel")
sns.distplot(class_0, kde=True, bins=200, color="green", label='1st feature')
sns.distplot(class_1, kde=True, bins=200, color="red", label='2nd feature')
plt.legend()
plt.show()


다양한 속성에 대한 그래픽:

# 1st_feature= x, 2nd_feature = y, 3rd_feature = labels
def boxplot_variation(1st_feature, 2nd_feature, 3rd_feature, width=16):
    fig, ax1 = plt.subplots(ncols=1, figsize=(width,6))
    s = sns.boxplot(ax = ax1, x=1st_feature, y=2nd_feature, hue=3rd_feature,
                data=df, palette="PRGn",showfliers=False)
    s.set_xticklabels(s.get_xticklabels(),rotation=90)
    plt.show();


중요한 Graficando 속성:

tmp = pd.DataFrame({'Feature': x_train, 'Feature importance': clf.feature_importances_})
tmp = tmp.sort_values(by='Feature importance', ascending=False)
plt.figure(figsize = (7,4))
plt.title('Features importance', fontsize=14)
s = sns.barplot(x=x_train, y='Feature importance', data=tmp)
s.set_xticklabels(s.get_xticklabels(), rotation=90)
plt.show()   


Mapa de calor de la matriz de correlación en forma de triángulo:

# corr_matrix son las correlaciones a graficar usando .corr()
mask = np.triu(np.ones_like(corr_matrix, dtype=np.bool))
f, ax = plt.subplots(figsize=(11, 9))
cmap = sns.diverging_palette(220, 10, as_cmap=True)
sns.heatmap(corr_matrix, mask=mask, cmap=cmap, vmax=.3, center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5})


쌍도



쌍 그림 기본:

sns.pairplot(df)


선택 사항:

sns.pairplot(df, vars=["1st_feature", "2nd_feature"])


다른 속성 en filas y columnas:

sns.pairplot(df,
                 x_vars=["1st_feature", "2nd_feature"],
                 y_vars=["3rd_feature", "4th_feature"])


Graficando solo el triángulo lower y ajustando un modelo lineal:

sns.pairplot(df, kind='reg', corner=True)


결론



Esto es todo por ahora,quisa en el futuro haga una segunda parte con mas tipos de gráficos.

¡Muchas gracias por llegar hasta aqui!

좋은 웹페이지 즐겨찾기