Calculating accuracy score of isolation forest model returning error
My code is as follows:
import joblib as jl
_data = pd.read_csv('ifile.csv')
contamination = input(:)
labelEncoder(_data)
model = IsolationForest(contamination=float(contamination), n_estimators=1000, verbose=1)
model.fit(_data)
jl.dump(model, 'file.joblib')
this trains the model and dumps it to joblib file. After that i use the joblib to test data further as follows:
_data = pd.read_csv(ifile.csv)
model = jl.load('file.joblib')
predictions = model.predict(_data)
_data[anomaly] = pd.Series(model.predict(_data))
predictions = np.where(predictions == 1, 0, 1) #Mapping 1-0 and -1-1
acc = accuracy_score(_data, predictions)
This however return the following error:
raise ValueError(Classification metrics can't handle a mix of {0}
ValueError: Classification metrics can't handle a mix of continuous-multioutput and binary targets
Can someone tell me what am i doing wrong? I have tried converting both _data and predictions to numpy arrays, but it still returns the same error.
Thank you
Topic isolation-forest numpy python-3.x accuracy pandas
Category Data Science