0

where i am using label encoder to label the categorical column. However while transforming it back, i'm getting value error

I have used Label encoder from sklearn

Code:

    from sklearn.preprocessing import LabelEncoder
    enc = LabelEncoder()
    label_encoder = enc.fit(Final.iloc[:,3])
    print ("Categorical classes:", label_encoder.classes_)
    integer_classes = label_encoder.transform(label_encoder.classes_)
    print ("Integer classes:", integer_classes)
    t = label_encoder.transform(Final.iloc[:,3])
    Final.iloc[:, 3] = t

    data = Final.iloc[:,3:11]
    from sklearn.ensemble import IsolationForest
    import numpy as np


    clf=IsolationForest(n_estimators=100, max_samples='auto', contamination=float(.03))
    clf.fit(data)
    pred = clf.predict(data)

    Final['anomaly']=pred
    outliers=Final.loc[Final['anomaly']==-1]
    outlier_index=list(outliers.index)

    print(Final['anomaly'].value_counts())


    t = label_encoder.inverse_transform(Final.iloc[:,3])
    Final.iloc[:,3] = t

Error:

     ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
anagha s
  • 323
  • 1
  • 4
  • 15

0 Answers0