0
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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

accuracy_score needs y_test not the x_test . You have passed x_test

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.