rmahesh
rmahesh

Reputation: 749

Error code with Preprocessor Scaling?

Using KNN and I wanted to experiment with different normalizers (Normalizer(), MinMaxScaler(), StandardScaler() etc).

I have loaded the data into a variable called X:

X = pd.read_csv('C:/Users/rmahesh/documents/parkinson.csv')

After doing some data wrangling, I try and run this code:

from sklearn import preprocessing
from sklearn.decomposition import PCA

T = preprocessing.Normalizer().fit(X)

from sklearn.cross_validation import train_test_split
T_train, T_test, y_train, y_test = train_test_split(T, y, test_size = 0.3, random_state = 7)
from sklearn.svm import SVC
model = SVC()
model = model.fit(T_train, y_train)
score = model.score(T_test, y_test)
print(score)

The specific error code I am getting is this:

TypeError: Singleton array array(Normalizer(copy=True, norm='l2'), dtype=object) cannot be considered a valid collection.

The code in which the error is appearing is this line:

 T_train, T_test, y_train, y_test = train_test_split(T, y,
 test_size = 0.3, random_state = 7)

Any help would be greatly appreciated!

Upvotes: 0

Views: 46

Answers (1)

pdowling
pdowling

Reputation: 500

You're fitting your normalizer and then treating it as an array directly. Replace

T = preprocessing.Normalizer().fit(X)

With

T = preprocessing.Normalizer().fit_transform(X)

So that the actual output of the normalization is used instead. .fit() returns the Normalizer object itself.

Upvotes: 1

Related Questions