Ad

Implementing Q-Q Plot Within Orange Miner's Python Script Widget

- 1 answer

I'm trying to create a QQ plot in Orange Miner's Python script. 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.

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:

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 Q-Q plot though:

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. the documentation simply says that data is a "1d data array". https://www.statsmodels.org/stable/generated/statsmodels.graphics.gofplots.qqplot.html

Thanks for your help in advance!

Ad

Answer

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:

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