精华内容
下载资源
问答
  • scatter_matrix
    2021-07-28 16:29:35

    pd.plotting.scatter_matrix(frame, alpha=0.5, c,figsize=None, ax=None, diagonal=‘hist’, marker=’.’, density_kwds=None,hist_kwds=None, range_padding=0.05, **kwds)
    1、frame,pandas dataframe对象
    2、alpha, 图像透明度,一般取(0,1]
    3、figsize,以英寸为单位的图像大小,一般以元组 (width, height) 形式设置
    4、ax,可选一般为none

    更多相关内容
  • pd.plotting.scatter_matrix(frame, alpha=0.5, c,figsize=None, ax=None, diagonal='hist', marker='.', density_kwds=None,hist_kwds=None, range_padding=0.05, **kwds) 1、frame,pandas dataframe对象 2、alpha...
  • pandas scatter_matrix使用

    2020-09-15 15:03:50
    02 grr = pd.plotting.scatter_matrix(iris_dataFrame, c=y_train, figsize=(15, 15), marker=‘o’, hist_kwds={‘bins’: 20}, s=60, alpha=.8, cmap=mglearn.cm3) 貌似2019年以后,pandas中的pd.scatter_matrix...

    示例来自《Phython机器学习基础教程》
    (Introduction to Machine Learning with Python)
    [德] Andreas C.Müller [美] Sarah Guido 著 张亮(hysic)译

    书上示例代码

    import pandas as pd
    import mglearn 

    在这里插入图片描述

    然而在copy下来在pycharm里运行时发现了各种错误

    01

    首先是在进行import mglearn时出现的future warning

    \anaconda\lib\site-packages\sklearn\externals\six.py:31: FutureWarning: The module is deprecated in version 0.21 and will be removed in version 0.23 since we've dropped support for Python 2.7. Please rely on the official version of six (https://pypi.org/project/six/).
      "(https://pypi.org/project/six/).", FutureWarning)
    \anaconda\lib\site-packages\sklearn\externals\joblib\__init__.py:15: FutureWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.
      warnings.warn(msg, category=FutureWarning)
    

    反正大意是说“版本将会有变动你这个代码可能在新版本python下搞不好啦”之类的,忽视就行。

    02

    grr = pd.plotting.scatter_matrix(iris_dataFrame, c=y_train, figsize=(15, 15), marker=‘o’,
    hist_kwds={‘bins’: 20}, s=60, alpha=.8, cmap=mglearn.cm3)

    貌似2019年以后,pandas中的pd.scatter_matrix()调用不可行,变成了pd.plotting.scatter_matrix()来调用

    03

    如何显示??
    为啥我什么都搞好了就是没有图呢?

    最后发现需要一个plt.show()
    plt又是什么?

    需要导入一个包import matplotlib as plt

    完整代码

    # 文件名 test.py
    # 导入包
    import pandas as pd
    import matplotlib.pyplot as plt
    import mglearn
    # 随机分割数据集、分为训练集和测试集的函数
    from sklearn.model_selection import train_test_split
    # sklearn自带的数据集
    from sklearn.datasets import load_iris
    
    # 载入数据集
    iris_dataset = load_iris()
    
    # 随机分割数据集【因为数据集原本是按照target顺序排列的】
    '''
    Target:
     [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
     0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
     1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
     2 2]
    '''
    
    X_train, X_test, y_train, y_test = train_test_split(
        iris_dataset['data'],iris_dataset['target'], random_state=0
    )
    
    # 将numpy数组转换成pandas dataFrame类型
    iris_dataFrame = pd.DataFrame(X_train, columns=iris_dataset.feature_names)
    display(iris_dataFrame)
    
    # 此处可以打印查看一下,记得要 `from IPython.display import display`
    # display(iris_dataFrame)
    
    # 调用函数 scatter_matrix,绘制散点图矩阵
    grr = pd.plotting.scatter_matrix(iris_dataFrame, c=y_train, figsize=(15, 15), marker='o',
                            hist_kwds={'bins': 20}, s=60, alpha=.8, cmap=mglearn.cm3)
    plt.show()
    
    
    # KNN算法对未知分类的花分类
    from sklearn.neighbors import KNeighborsClassifier
    # 只考虑一位邻居 ——如果多位邻居,把参数n_neighors改掉就行
    knn = KNeighborsClassifier(n_neighbors=1)
    
    # 训练模型
    knn.fit(X_train,y_train)
    
    # 尝试预测新的种类
    
    import numpy as np
    X_new = np.array([[5, 2.9, 1, 0.2]])
    print("X_new.shape: {}".format(X_new.shape))  
    '''X_new.shape: (1, 4) '''	
    # shape必须符合X_test
    # 例如
    # shape of data: (150, 4)
    # 因此一个元组的shape为(1, 4)
    
    
    # 尝试调用 knn 对象的 predict 方法来进行预测
    prediction = knn.predict(X_new)
    print("Prediction: \n{}".format(prediction))
    print("Prediction target name :\n {}".format(iris_dataset['target_names'][prediction]))
    '''
    Prediction: 
    [0]
    Prediction target name :
     ['setosa']
     
     # 预测值为0 ,对应种类为setosa
     '''
    
    
    # 评估模型
    y_pre = knn.predict(X_test)
    corr_rate = np.mean(y_pre == y_test)
    print("Test set score : {:.2f}".format(corr_rate))
    
    '''
    Test set score : 0.97
    '''
    
    展开全文
  • pandas中scatter_matrix函数

    千次阅读 2021-01-21 18:14:55
    pandas中scatter_matrix函数 from pandas.plotting import scatter_matrix attributes = ["median_house_value", "median_income", "total_rooms", "housing_median_age"] scatter_matrix(housing[attributes], ...

    pandas中scatter_matrix函数

    from pandas.plotting import scatter_matrix
    
    attributes = ["median_house_value", "median_income", "total_rooms", "housing_median_age"]
    scatter_matrix(housing[attributes], figsize=(12, 8))
    plt.show()
    

    在这里插入图片描述
    pandas中scatter_matrix函数,它会绘制出每个数值属性相对于其他数值属性的相关值。如果pandas将每个变量都与自身相对,那么主对角线将全都是直线,这样毫无意义,所以取而代之的方法是,Pandas在这几个图中显示了每个属性的直方图。
    scatter_matrix(frame, alpha=0.5, c,figsize=None, ax=None, diagonal='hist', marker='.', density_kwds=None,hist_kwds=None, range_padding=0.05, **kwds)

    1. frame:(DataFrame),DataFrame对象
    2. alpha:(float, 可选), 图像透明度,一般取(0,1]
    3. figsize: ((float,float), 可选),以英寸为单位的图像大小,一般以元组 (width, height) 形式设置
    4. ax:(Matplotlib axis object, 可选),一般取None
    5. diagonal:({‘hist’, ‘kde’}),必须且只能在{‘hist’, ‘kde’}中选择1个,’hist’表示直方图(Histogram plot),’kde’表示核密度估计(Kernel Density Estimation);该参数是scatter_matrix函数的关键参数,下文将做进一步介绍
    6. marker:(str, 可选), Matplotlib可用的标记类型,如’.’,’,’,’o’等
    7. density_kwds:(other plotting keyword arguments,可选),与kde相关的字典参数
    8. hist_kwds:(other plotting keyword arguments,可选),与hist相关的字典参数
    9. range_padding:(float, 可选),图像在x轴、y轴原点附近的留白(padding),该值越大,留白距离越大,图像远离坐标原点
    10. kwds:(other plotting keyword arguments,可选),与scatter_matrix函数本身相关的字典参数
    展开全文
  • pd.plotting.scatter_matrix()

    2021-05-04 12:51:09
    pd.plotting.scatter_matrix() Signature: pd.plotting.scatter_matrix( frame, alpha=0.5, figsize=None, ax=None, grid=False, diagonal='hist', marker='.', density_kwds=None, hist_kwds=None, ...

    pd.plotting.scatter_matrix()


    Signature:
    pd.plotting.scatter_matrix(
        frame,
        alpha=0.5,
        figsize=None,
        ax=None,
        grid=False,
        diagonal='hist',
        marker='.',
        density_kwds=None,
        hist_kwds=None,
        range_padding=0.05,
        **kwargs,
    )
    Docstring:
    Draw a matrix of scatter plots.
    
    Parameters
    ----------
    frame : DataFrame
    alpha : float, optional
        Amount of transparency applied.
    figsize : (float,float), optional
        A tuple (width, height) in inches.
    ax : Matplotlib axis object, optional
    grid : bool, optional
        Setting this to True will show the grid.
    diagonal : {'hist', 'kde'}
        Pick between 'kde' and 'hist' for either Kernel Density Estimation or
        Histogram plot in the diagonal.
    marker : str, optional
        Matplotlib marker type, default '.'.
    density_kwds : keywords
        Keyword arguments to be passed to kernel density estimate plot.
    hist_kwds : keywords
        Keyword arguments to be passed to hist function.
    range_padding : float, default 0.05
        Relative extension of axis range in x and y with respect to
        (x_max - x_min) or (y_max - y_min).
    **kwargs
        Keyword arguments to be passed to scatter function.
    
    Returns
    -------
    numpy.ndarray
        A matrix of scatter plots.
    
    Examples
    --------
    
    .. plot::
        :context: close-figs
    
        >>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
        >>> pd.plotting.scatter_matrix(df, alpha=0.2)
    File:      d:\programdata\anaconda3\lib\site-packages\pandas\plotting\_misc.py
    Type:      function
    展开全文
  • import pandas as pd print(pd.__version__) 我的pandas版本是1.0.5,所以语句scatter_matrix函数在plotting里边 pd.plotting.scatter_matrix
  • 现在的pandas的scatter_matrix用法已经发生变化了,变成了pandas.plotting.scatter_matrix
  • plt.scatter() 参数 ​​​​​​ #plt.scatter() 散点图 #plt.scatter(x,y,s=20,c = None,marker = 'o',cmap = none,norm = none,vmin = none,vmax = none,alpha = none,linewidths = none,verts = none,edgecolors...
  • 当使用pd.scatter_matrix报错: 后查文档知pd.scatter_matrix这种用法已经被弃用了,现在应该使用pd.plotting.scatter_matrix
  • pandas.plotting.scatter_matrix 参数

    千次阅读 2020-02-27 10:51:15
    文档链接: ... pandas.plotting.scatter_matrix(frame, alpha=0.5, figsize=...
  • module 'pandas' has no attribute 'scatter_matrix'

    万次阅读 多人点赞 2019-05-11 17:17:46
    运行pandas.scatter_matrix两两散点图的时候报错 奇怪,大家明明都是这么用pd.scatter_matrix,后来通过查找pandas文档,发现现在的pandas的scatter_matrix用法已经发生变化了,变成了pandas.plotting.scatter_matrix ...
  • ‘module ‘pandas‘ has no attribute ‘scatter_matrix

    千次阅读 多人点赞 2020-02-27 14:40:44
    今天在写python画散点图做相关性分析时遇到’module ‘pandas’ has no attribute ‘scatter_matrix’'这个问题 原代码: data=pd.DataFrame(np.random.randn(200,4)*100,columns=['A','B','C','D']) pd.scatter_...
  • pd.plotting.scatter_matrix(features, alpha = 0.3, figsize = (14,8), diagonal = 'kde'); 对角线部分表示第i个特征的分布,x轴为该特征的值,y轴为该特征的值出现的次数,也就是说这个图表示第i个特征的密度...
  • 从 pd.scatter_matrix 改为 pd.plotting.scatter_matrix
  • 5.散点图矩阵 pd.plotting.scatter_matrix

    千次阅读 2019-01-30 17:14:18
    pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15,15), marker=‘0’, hist_kwds={‘bins’:50},s=60,alpha=.8, cmap=mglearn.cm3) 结果: pd.scatter_matrix若不可用。 用pd.plotting....
  • ![图片说明](https://img-ask.csdn.net/upload/201805/14/1526311476_879156.png) ![图片说明]... 刚开始学习机器学习 在画散布图的时候 出现了这个问题 该怎么解决呢?
  • https://blog.csdn.net/wangxingfan316/article/details/80033557
  • 对于给定数据集,Pandas的scatter_matrix函数能够显示各特征的密度函数曲线,能大致显示各特征之间的相关关系,Numpy的corrcoef函数能够准确计算各特征之间的相关系数,且能借助Matplotlib库以图形形式直观表达。...
  • 源代码是这样的: 但是现在的pandas的scatter_matrix用法已经发生变化了,变成了pandas.plotting.scatter_matrix 这样就生成成功
  • from pandas.plotting import scatter_matrix attributes = ["median_house_value", "median_income", "total_rooms", "housing_median_age"] scatter_matrix(housing[attributes], figsize=(12, 8)) plt.show() ...
  • 官方文档 参考博客 corr_matrix=housing.corr() print(corr_matrix) ...print(corr_matrix["median_house_value"...pandas.plotting.scatter_matrix官方文档 from pandas.tools.plotting ...
  • pandas的scatter_matrix散布矩阵图的理解

    千次阅读 2018-09-16 11:44:15
    Q:  如何理解问题3中给出的图?如何分析关联性、变量分布? A: 这张图分为两部分:对角线部分和非对角线部分。 对角线部分: 核密度估计图(Kernel Density Estimation),就是用来看某 一个 变量分布情况,横轴...
  • Q: 如何理解问题3中给出的图?如何分析关联性、变量分布?A: 这张图分为两部分:对角线部分和非对角线部分。 对角线部分: 核密度估计图(Kernel Density Estimation),就是用来看某 一个 变量分布情况,横轴对应...
  • 运行pandas.scatter_matrix()散点图函数时报错, 原因是该函数在新版本用法发生了变化: pandas.plotting.scatter_matrix 完整用法:pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15,15), ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 16,103
精华内容 6,441
关键字:

scatter_matrix