-2

I am facing the following error in my interface PYQT5

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

The code where the error appears is

x = data.drop('DrainStatnumout',axis='columns')
                y = data['DrainStatnumout']

                data.Failuer = data.Failuer.astype(int)

                #xx = data.drop(['Assembly1_Availability','Assembly2_Availability',
                                #'LaserCutting_Availability','Failuer','DrainStatnumout'],axis='columns')
                #print(xx)

                X=pd.DataFrame(x)

                Y=pd.DataFrame(y)

                X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.20)


plt.figure()
            ax1 = sns.distplot(Y_predict)
            ax2 = sns.distplot(Y_test)
            plt.axvline(np.mean(Y_predict), color='b', linestyle='dashed', linewidth=5)
            plt.axvline(np.mean(Y_test), color='orange', linestyle='dashed', linewidth=5)

            #plt.savefig('dist1.png',dpi=200,orientation='portrait')
            plt.savefig('DecisionTreeClassifier2.png')


    ValueError                                Traceback (most recent call last)
    <ipython-input-1-e0a00ff7678b> in pushButton_2_handler(self)
        588         ax2 = sns.distplot(Y_test)
        589         plt.axvline(np.mean(Y_predict), color='b', linestyle='dashed', linewidth=5)
    --> 590         plt.axvline(np.mean(Y_test), color='orange', linestyle='dashed', linewidth=5)
        591         #plt.savefig('dist1.png',dpi=200,orientation='portrait')
        592         plt.savefig('DecisionTreeClassifier2.png')

Any input appreciated

Dean
  • 199
  • 2
  • 4
  • 14
  • If you search with the error message, You should get enough results to give you an idea of what the problem might be. Include a minimal example of `Y_test` - but I don't see how that line could produce the error. - please provide a [mcve]. – wwii Dec 19 '19 at 21:03
  • Check out more about error here: https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o?rq=1. Try just do np.mean(Y_test) and see if error there. – MjH Dec 19 '19 at 21:03
  • MjH The np.mean(Y_test) working fine and gives the wright output value. seriously I am puzzled with this error. It does work fine outside the interface. – Dean Dec 19 '19 at 21:30
  • first you could check what you have in variables - `print( np.mean(Y_predict) )` and `print( np.mean(Y_test) )`.This error mostly means: `"I expect one value but you give me many values. I don't know what to do with this. Use a.empty, a.bool(), a.item(), a.any() or a.all() to give me one value."` – furas Dec 19 '19 at 22:07
  • I have print( np.mean(Y_test) ) and print( np.mean(Y_predict) ) within pyqt5. The np.mean(Y_predict) gives me a value 43.110236220472444 but the np.mean(Y_test) gives me DrainStatnumout 42.551181. dtype: float64. Strangly is working fine with python. – Dean Dec 19 '19 at 23:08
  • is it somthing to do with these lines: x = data.drop('DrainStatnumout',axis='columns') y = data['DrainStatnumout'] data.Failuer = data.Failuer.astype(int) X=pd.DataFrame(x) Y=pd.DataFrame(y) X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.20) – Dean Dec 19 '19 at 23:12

1 Answers1

0

I have taken pd.data frame out and problem solved.

X = data.drop('DrainStatnumout',axis='columns')

Y = data['DrainStatnumout']
data.Failuer = data.Failuer.astype(int)




                X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.20)


plt.figure()
            ax1 = sns.distplot(Y_predict)
            ax2 = sns.distplot(Y_test)
            plt.axvline(np.mean(Y_predict), color='b', linestyle='dashed', linewidth=5)
            plt.axvline(np.mean(Y_test), color='orange', linestyle='dashed', linewidth=5)

            #plt.savefig('dist1.png',dpi=200,orientation='portrait')
            plt.savefig('DecisionTreeClassifier2.png')
Dean
  • 199
  • 2
  • 4
  • 14