I am trying to do Feature Scaling in a dataset, but I get an error and have no idea how to proceed:
JavaScript
x
7
1
> Traceback (most recent call last):
2
>
3
> File "<ipython-input-10-71bea414b4d0>", line 22, in <module>
4
> x_train = sc_X.fit_transform(x_train)
5
>
6
> TypeError: fit_transform() missing 1 required positional argument: 'X'
7
and here is my code:
JavaScript
1
24
24
1
import pandas as pd
2
3
# Importing the dataset
4
dataset = pd.read_csv('Data.csv')
5
X = dataset.iloc[:, :-1].values
6
y = dataset.iloc[:, 3].values
7
# Taking care of missing data
8
from sklearn.preprocessing import Imputer
9
imputer = Imputer(missing_values="NaN", strategy="mean", axis=0)
10
imputer = Imputer.fit(imputer,X[:,1:3])
11
X[:, 1:3] = Imputer.transform(imputer,X[:, 1:3])
12
13
#Spliting the dataset into Training set and Test Set
14
from sklearn.cross_validation import train_test_split
15
16
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size= 0.2, random_state= 0)
17
18
#Feature Scalling
19
20
from sklearn.preprocessing import StandardScaler
21
sc_X = StandardScaler
22
x_train = sc_X.fit_transform(x_train)
23
x_test = sc_X.transform(x_test)
24
Advertisement
Answer
You are assigning sc_X
a reference to the StandardScaler
class.
but fit_transform()
is is not a class method, but an instance method.
This means that you have to create an instance of the class.
So,
JavaScript
1
2
1
sc_X = StandardScaler
2
should be:
JavaScript
1
2
1
sc_X = StandardScaler()
2