danyialKhan
danyialKhan

Reputation: 707

TypeError: fit_transform() missing 1 required positional argument: 'X'

I am trying to do Feature Scaling in a dataset, but I get an error and have no idea how to proceed:

    > Traceback (most recent call last):
    > 
    >   File "<ipython-input-10-71bea414b4d0>", line 22, in <module>
    >     x_train = sc_X.fit_transform(x_train)
    > 
    > TypeError: fit_transform() missing 1 required positional argument: 'X'

and here is my code:

import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
# Taking care of missing data
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values="NaN", strategy="mean", axis=0)
imputer = Imputer.fit(imputer,X[:,1:3])
X[:, 1:3] = Imputer.transform(imputer,X[:, 1:3])

#Spliting the dataset into Training set and Test Set
from sklearn.cross_validation import train_test_split

x_train, x_test, y_train, y_test = train_test_split(X, y, test_size= 0.2, random_state= 0)

#Feature Scalling

from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler
x_train = sc_X.fit_transform(x_train)
x_test = sc_X.transform(x_test)

Upvotes: 19

Views: 72713

Answers (4)

dxxxxxxxxxxxxx
dxxxxxxxxxxxxx

Reputation: 1

just keep brackets for StandardScaler function Ans:- StandardScaler()

Upvotes: 0

biddut
biddut

Reputation: 351

You need to create the class instance :

sc_X = StandardScaler() 

as fit_transform() is instance method not a class method

Upvotes: 0

Uku Loskit
Uku Loskit

Reputation: 42040

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,

sc_X = StandardScaler

should be:

sc_X = StandardScaler()

Upvotes: 48

Aakif Mairaj Mufti
Aakif Mairaj Mufti

Reputation: 1

imputer is a method and Imputer is a class

So, change the code as below, and other such occurrences in this code:

imputer = imputer.fit(imputer,X[:,1:3])

Upvotes: 0

Related Questions