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


sklearn.metrics.accuracy_score(y_true, y_pred....)

accuracy_score needs y_test not the x_test . You have passed x_test

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.