NotFittedError says this StandardScaler instance is not fitted yet while using inverse_transform()
I have a dataset and i have used Support Vector Regression.So i needed to use StandardScaler module from sklearn.preprocessing fro Feature Scaling. After training my model when i came to predict it was giving a prediction which was Feature scaled.That's why i used inverse_transformfrom StandardScaler() and getting a error saying
NotFittedError: This StandardScaler instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
I have tried several solutions but it's getting the same error. What can i do now?
Here is my code :
import numpy as np
import pandas as pd
import seaborn as sbn
import matplotlib.pyplot as plt
df = pd.read_csv('Position_Salaries.csv')
x = df.iloc[:,1:2].values
y = df.iloc[:,2:].values
from sklearn.preprocessing import StandardScaler
x = StandardScaler().fit_transform(x)
y = StandardScaler().fit_transform(y)
from sklearn.svm import SVR
regressor = SVR(kernel = 'rbf')
regressor.fit(x,y)
y_pred = regressor.predict(StandardScaler().fit_transform(np.array([[6.5]])))
y_pred = StandardScaler().inverse_transform(y_pred)
Topic svr feature-scaling scikit-learn svm python
Category Data Science