ValueError: Number of features of the model must match the input. Model n_features is 1 and input n_features is 2. Isolation Forest Method
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
from sklearn.ensemble import IsolationForest
from pyod.models.copod import COPOD
from pyod.models.hbos import HBOS
from pyod.models.cblof import CBLOF
from pyod.models.iforest import IForest
clf = COPOD()
xx, yy = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100))
clf = IForest(contamination=outliers_fraction, random_state=0)
clf.fit(df['Profit'].values.reshape(-1, 1))
y_pred = clf.predict(df['Profit'].values.reshape(-1, 1))
Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()]) * -1
Anyone knows how to fix this. I am trying to get the result from the decision_function.
ValueError: Number of features of the model must match the input. Model n_features is 1 and input n_features is 2.
Topic isolation-forest numpy scikit-learn
Category Data Science