简体   繁体   English

在Orange Miner的Python脚本小部件中实现QQ图

[英]Implementing Q-Q plot within Orange Miner's Python script widget

I'm trying to create a QQ plot in Orange Miner's Python script. 我正在尝试在Orange Miner的Python脚本中创建QQ图。 I keep getting an error that I'm assuming relates to Orange's native data format, stating "AttributeError: 'Table' object has no attribute 'shape'" when trying to read in a single column to the sm.qqplot function. 我一直遇到与Orange的本机数据格式有关的错误,当尝试读取sm.qqplot函数的单个列时,指出“ AttributeError:'Table'对象没有属性'shape'”。

I've already used roughly this setup for other plots. 我已经将该设置大致用于其他地块。 I figured out how to convert the Orange table to a Pandas dataframe for doing correlation heatmaps like so: 我想出了如何将Orange表转换为Pandas数据框,以进行相关的热图,如下所示:

import numpy as np
from Orange.data import Table
import Orange
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns



data = in_data.copy()

# Converts to pandas!!!
frame = Orange.data.pandas_compat.table_to_frame(data)

# Get all columns
heatmap_sub = frame.corr(method = 'pearson')

sns.heatmap(heatmap_sub,
            xticklabels=heatmap_sub.columns.values,
            yticklabels=heatmap_sub.columns.values,
            center = 0,
            annot = True)
plt.title('Pearson correlation of Binder type = Acrylic')            
plt.show()

Here is the code that I am attempting to implement for the QQ plot though: 这是我尝试为QQ图执行的代码:

import numpy as np
from Orange.data import Table 
import statsmodels.api as sm
import pylab

data = in_data.copy()

sm.qqplot(data[:,1], line='45')
pylab.show()

I expect a plot to be output from the code to be a plot, but I keep getting this: 我期望从代码中输出的绘图是绘图,但是我一直在得到:

Running script:
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<string>", line 8, in <module>
  File "C:\Users\Doug\Anaconda3\lib\site-packages\statsmodels\graphics\gofplots.py", line 506, in qqplot
    fit=fit, a=a, loc=loc, scale=scale)
  File "C:\Users\Doug\Anaconda3\lib\site-packages\statsmodels\graphics\gofplots.py", line 130, in __init__
    self.nobs = data.shape[0]
AttributeError: 'Table' object has no attribute 'shape'

I'm sure this has something to do with the Orange table object, but I'm not sure how to go about "converting" it to a numpy array or something comparable. 我确定这与Orange表对象有关,但是我不确定如何将其“转换”为numpy数组或类似的东西。 the documentation simply says that data is a "1d data array". 该文档只是说数据是“一维数据数组”。 https://www.statsmodels.org/stable/generated/statsmodels.graphics.gofplots.qqplot.html https://www.statsmodels.org/stable/generation/statsmodels.graphics.gofplots.qqplot.html

Thanks for your help in advance! 谢谢您的帮助!

I figured it out if anyone else runs into this issue. 我弄清楚是否还有其他人遇到此问题。 Wrap the data you are trying to select with np.array() to convert, like so: 用np.array()包装要尝试选择的数据以进行转换,如下所示:

sm.qqplot(np.array(data[:,1]), line='45')
pylab.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM