본문 바로가기
파이썬

파이썬 scikit learn의 전처리-단일 샘플-지원 중단 경고

by º기록 2020. 11. 10.
반응형

Ubuntu에서 Anaconda를 새로 설치할 때 ... Scikit-Learn을 사용하여 분류 작업을 수행하기 전에 다양한 방법으로 데이터를 사전 처리하고 있습니다.

from sklearn import preprocessing

scaler = preprocessing.MinMaxScaler().fit(train)
train = scaler.transform(train)    
test = scaler.transform(test)

이 모든 것이 잘 작동하지만 분류하려는 새 샘플 (아래 임시)이있는 경우 (따라서 동일한 방식으로 전처리하려면 다음을 얻습니다.

temp = [1,2,3,4,5,5,6,....................,7]
temp = scaler.transform(temp)

그런 다음 사용 중단 경고가 표시됩니다 ...

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 
and will raise ValueError in 0.19. Reshape your data either using 
X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1)
if it contains a single sample. 

그래서 질문은 이렇게 단일 샘플을 어떻게 다시 스케일링해야 하는가입니다.

나는 대안 (그다지 좋지 않은)이 ...라고 생각합니다.

temp = [temp, temp]
temp = scaler.transform(temp)
temp = temp[0]

하지만 더 나은 방법이 있다고 확신합니다.

 

해결 방법

 

경고가 알려주는 내용을 들어보십시오.

데이터에 단일 기능 / 열이있는 경우 X.reshape (-1, 1) 중 하나를 사용하여 데이터의 형태를 변경합니다. 단일 샘플을 포함하는 경우 X.reshape (1, -1).

예 유형의 경우 (두 개 이상의 기능 / 열이있는 경우) :

temp = temp.reshape(1,-1) 

하나의 기능 / 열 :

temp = temp.reshape(-1,1)

 

참조 페이지 https://stackoverflow.com/questions/35082140

 

 

반응형

댓글