zoukankan      html  css  js  c++  java
  • Seaborn数据探索可视化

    seaborn

    修改图片尺寸
    from matplotlib import pyplot as plt
    plt.figure(figsize=(100, 5))
    通过以上两行起作用
    sns.barplot(x=age_survived.index, y=age_survived['Survived'] + age_survived['Dead'], color='red')
    sns.barplot(x=age_survived.index, y=age_survived['Survived'], color='green')

    数据探索性分析

    区分boxplot, barplot

    barplot与boxplot画图效果不一致,barplot不能显示较高精度。boxplot可以显示均值范围以及异常值个数。

    数据离散程度以及异常值

    sns.pairplot(iris, hue='Name')
    单个变量离散程度
    sns.scatterplot(x=train.index, y=train.SibSp)

    数据范围

    由pandas提供boxplot方法
    iris.boxplot(by="Name", figsize=(12, 6))

    roc/auc

    y_test若不为二分类label,则需要指定pos_label, pos_labelz作为正例,其余class都作为反例
    fpr, tpr, threshold = roc_curve(y_test, svc.decision_function(X_test)[:, 1], pos_label=1)
    sns.lineplot(x=fpr, y=tpr)

    混淆矩阵

    sns.heatmap(confusion_matrix(y_test, svc.predict(X_test)), annot=True)

    grid search查找参数

    y轴为param_grid中第一个参数,x轴为param_grid中第二个参数,但不能设置xlable, ylabel
    sns.heatmap(scores, yticklabels=param_grid['C'], xticklabels=param_grid['gamma'],
    annot=True, )

    特征重要性

    设置orient,且交换x, y
    sns.barplot(x=sorted_feature_importances, y=sorted_feature_names, orient='h')
    sns.barplot(x=sorted_feature_names, y=sorted_feature_importances)

    keras model train_history

    构建一个DataFrame,x='epoches', y='acc'分别为DataFrame key
    sns.lineplot(x='epoches', y='acc', data=train_history_df, markers=True)

    由dict构建一个DataFrame
    history_dic = train_history.history
    epochs = np.shape(train_history.history['acc'])[0]
    history_dic['epoches'] = range(epochs)

    直方图

    ratings['rating']为pandas中Series结构
    sns.distplot(ratings['rating'])

    matploitlib直方图
    plt.hist(ratings['rating'])

    对离散变量,且取值个数较少情况

    用barplot或者catplot,可以引用hue属性,查看3个变量情况
    sns.barplot(x='SibSp', y='Survived', hue='Sex', data=train_ready)
    sns.catplot(x='SibSp', y='Survived', hue='Sex', data=train_ready, kind='bar')
    sns.catplot(x='SibSp', y='Survived', hue='Sex', data=train_ready, kind='box')

    对连续变量,且取值个数较多情况(如Age, Fare)

    不能用barplot,否则会由于bar过多而密集

    用distplot,不允许数据中有空值,需要先填充空值
    sns.distplot(a=train_ready['Age'])

    用FacetGrid,允许数据中有空值
    g = sns.FacetGrid(train_ready, col='Survived')
    g.map(sns.distplot, 'Age')

    柱状图叠加效果,计算总量及比率 (查找更简洁方法)

    sns.barplot(x=sex_survived.index, y=sex_survived['Survived']+sex_survived['Dead'], color='red')
    sns.barplot(x=sex_survived.index, y=sex_survived['Survived'], color='green')

  • 相关阅读:
    Vim+Vundle+YouCompleteMe 安装
    TortoiseSVN 的分支合并操作
    JSP数据交互一
    Jquery操作DOM
    Jquery
    JQuery选择器
    第五章初始JQuery
    JavaScript对象及初识面向对象
    JavaScript第三章操作DOM
    JavaScript第二章操作BOM
  • 原文地址:https://www.cnblogs.com/sunzhuli/p/9696644.html
Copyright © 2011-2022 走看看