Machine Learning Studio Issue

Harris, Toby 1 Reputation point
2021-07-25T22:51:05.317+00:00

Hey all,

I'm working on a project for school in the machine learning studio classic and when I try to execute the following python script I get errors.

def azureml_main(frame1):
import matplotlib
matplotlib.use('agg')

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt
import statsmodels.graphics.boxplots as sm

Azure = True

Create a series of bar plots for the various levels of the

string columns in the data frame by readmi_class.

names = list(frame1) 
num_cols = frame1.shape[1]
for indx in range(num_cols - 1): 
        if(frame1.ix[:, indx].dtype not in [np.int64, np.int32, np.float64]):
            temp1 = frame1.ix[frame1.readmi_class == 'YES', indx].value_counts()
            temp0 = frame1.ix[frame1.readmi_class == 'NO', indx].value_counts()  
            fig = plt.figure(figsize = (12,6)) 
            fig.clf()
            ax1 = fig.add_subplot(1, 2, 1) 
            ax0 = fig.add_subplot(1, 2, 2) 
            temp1.plot(kind = 'bar', ax = ax1)
            ax1.set_title('Values of ' + names[indx] + '\n for readmitted patients')
            temp0.plot(kind = 'bar', ax = ax0)
            ax0.set_title('Values of ' + names[indx] + '\n for patients not readmitted')

            if(Azure == True): fig.savefig('bar_' + names[indx] +'.png') 
                ## Now make some box plots of the columns with numerical values. 
for indx in range(num_cols):
        if(frame1.ix[:, indx].dtype in [np.int64, np.int32, np.float64]): 
            temp1 = frame1.ix[frame1.readmi_class == 'YES', indx] 
            temp0 = frame1.ix[frame1.readmi_class == 'NO', indx]

            fig = plt.figure(figsize = (12,6))             
            fig.clf()
            ax1 = fig.add_subplot(1, 2, 1)             
            ax0 = fig.add_subplot(1, 2, 2)        
            ax1.boxplot(temp1.as_matrix())
            ax1.set_title('Box plot of ' + names[indx] + '\n for readmitted patients')
            ax0.boxplot(temp0.as_matrix())
            ax0.set_title('Box plot of ' + names[indx] + '\n for patients not readmitted')

            if(Azure == True): fig.savefig('box_' + names[indx] +'.png')               
return frame1

The error I'm getting is:
Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
Caught exception while executing function: Traceback (most recent call last):
File "C:\server\invokepy.py", line 199, in batch
odfs = mod.azureml_main(*idfs)
File "C:\temp\1f7ee68aea7d4914a540db6181eb53c8.py", line 46, in azureml_main
temp1 = frame1.ix[frame1.readmi_class == 'YES', indx]
File "C:\pyhome\lib\site-packages\pandas\core\generic.py", line 2669, in getattr
return object.getattribute(self, name)
AttributeError: 'DataFrame' object has no attribute 'readmi_class'
Process returned with non-zero exit code 1

---------- End of error message from Python interpreter ----------
Start time: UTC 07/25/2021 22:45:40
End time: UTC 07/25/2021 22:46:03

Has anyone encountered this or know of a fix? I appreciate any help you can provide.

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,916 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 46,141 Reputation points Microsoft Employee
    2021-07-26T10:32:45.15+00:00

    @Harris, Toby I think the issue might be in what you have connected as input to the execute python script. Because, the input from dataframe1 or frame1 does not seem to contain the required attribute that is referenced. Are you following any documentation to review your entire experiment or could you cross check for any missed modules in your experiment?

    I would also recommend to try the reference this way in your current script at all occurrences:

    temp1 = frame1.ix[indx, frame1.readmi_class == 'YES']  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.