1
$\begingroup$

I am getting this error for the mentioned code. Please help me with this as I am a beginner and learning machine learning

# Polynomial Regression

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Position_Salaries.csv')
x = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

#Feature scaling
from sklearn.preprocessing import StandardScaler
sc_x=StandardScaler()
sc_y=StandardScaler()
x=sc_x.fit(x)
x=sc_x.fit(y)

#Fitiing SVR to the dataset
from sklearn.svm import SVR
regressor = SVR(kernel = 'rbf')
regressor.fit(x,y)

#Predict the results
regressor.predict(np.array([6.5]).reshape(1, 1))

#Visualizing the results
plt.scatter(x,y,color = 'red')
plt.plot(x,regressor.predict(x))
plt.label("Positon Level")
plt.label("Salary")
plt.show()
$\endgroup$
1
  • $\begingroup$ Hi. You should also provide your error. $\endgroup$
    – ebrahimi
    Apr 12, 2020 at 16:15

2 Answers 2

1
$\begingroup$

.fit method returns the standard scalar object. You are using that to train the model. please use fit_transfor or transform after the fit. like below

sc_x.fit(x)
x = sc_x.transform(x)

or

x = sc_x.fit_transform(x)
$\endgroup$
0
$\begingroup$

sc.fit(x) doesn't transform x it only trains sc. You should use sc.transform(x) of a trained sc to do what you want. Change

sc_x = StandardScaler()
sc_y = StandardScaler()
x = sc_x.fit(x)
x = sc_x.fit(y)

to

sc_x = StandardScaler()
sc_y = StandardScaler()
x = sc_x.fit_transform(x)
y = sc_y.transform(y)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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