inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)

작업형2 모의문제1

작업형2 모의문제1 질문

해결된 질문

460

김태범

작성한 질문수 15

1

 

  1. 작업형2 문제마다 어떤문제들은 n_train, c_train, n_test, c_test로 나누는 문제들이 있고 그렇지 않은 문제들이 있어서 헷갈리는데요. 수치형변수를 스케일링하는 과정을 거치려면 n_train, c_train, n_test, c_test로 나눠야 하고,

    스케일링 과정을 생략하고 범주형 변수 인코딩 과정만을 진행할때는 나눌필요가 없는게 맞나요?

 

  1. 작업형 모의문제 1을 혼자 풀어보는 와중 MinMaxScaler로 스케일링을 해보는중인데

     

    from sklearn.preprocessing import MinMaxScaler
    cols = ['CLIENTNUM', 'Customer_Age','Dependent_count', 'Months_on_book', 'Total_Relationship_Count',	'Months_Inactive_12_mon',	'Contacts_Count_12_mon',	'Credit_Limit',	'Total_Revolving_Bal',	'Avg_Open_To_Buy',	'Total_Amt_Chng_Q4_Q1',	'Total_Trans_Amt',	'Total_Trans_Ct',	'Total_Ct_Chng_Q4_Q1',	'Avg_Utilization_Ratio']
    
    scaler = MinMaxScaler()
    for col in cols:
        n_train[col] = scaler.fit_transform(n_train[col])
        n_test[col] = scaler.transform(n_test[col])

ValueError Traceback (most recent call last)

<ipython-input-38-b70edfd82bf0> in <cell line: 5>() 4 scaler = MinMaxScaler() 5 for col in cols: ----> 6 n_train[col] = scaler.fit_transform(n_train[col]) 7 n_test[col] = scaler.transform(n_test[col]) 8


5 frames


/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 900 # If input is 1D raise error 901 if array.ndim == 1: --> 902 raise ValueError( 903 "Expected 2D array, got 1D array instead:\narray={}.\n" 904 "Reshape your data either using array.reshape(-1, 1) if "

ValueError: Expected 2D array, got 1D array instead: array=[0.58522152 0.08465774 0.60121236 ... 0.06531669 0.06194963 0.52375209]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

 

위와 같은 오류가 발생합니다. 혹시 어떤 부분이 잘못된걸까요?

  1. 반면에 아래와 같이 실행할 경우 오류가 발생하지않습니다. 강의에서는 cols안에 컬럼값이 여러개이므로 반복문을 써야한다고 배웠는데 제가 잘못알고있는걸까요?

from sklearn.preprocessing import MinMaxScaler cols = ['CLIENTNUM', 'Customer_Age','Dependent_count', 'Months_on_book', 'Total_Relationship_Count',	'Months_Inactive_12_mon',	'Contacts_Count_12_mon',	'Credit_Limit',	'Total_Revolving_Bal',	'Avg_Open_To_Buy',	'Total_Amt_Chng_Q4_Q1',	'Total_Trans_Amt',	'Total_Trans_Ct',	'Total_Ct_Chng_Q4_Q1',	'Avg_Utilization_Ratio']  

scaler = MinMaxScaler() 
n_train[cols] = scaler.fit_transform(n_train[cols]) 
n_test[cols] = scaler.transform(n_test[cols])     

 

python 머신러닝 빅데이터 pandas 빅데이터분석기사

답변 1

1

퇴근후딴짓

2-3번 정리해드리면

라벨인코딩을 할때는 컬럼 하나하나 fit이 필요해요! 반복문 필요함

스케일링을 할때는 3번과 같이 한번에 적용 가능합니다 :)

1번

나눠서 깔끔하게 살펴볼 수 있어서 입니다.
다양한 방법을 보여주려고 했는데, 다소 혼란스러웠다면 죄송합니다.
어떤 방식이던 본인이 마음에 드는 방식으로 진행해주시면 될 것 같아요!
나누지 않고 컬럼만 선택해서 불러와도 됩니다.

또는 판다스에서 제공하는 원한잇코딩(겟더미)를 활용할 경우 자동으로 알아서 object값만 원핫인코딩 해요!!

뒤로가기 버튼 같은 것이 있나요?

0

19

1

강의 연장 문의

0

17

1

출력값 질문

0

26

2

수업노트가 어디에 있나요?

0

27

1

실기시험 제출관련

0

158

2

6.20 작업형 2 과적합

0

164

3

코딩팡 장업형2 베이스 라인 인코딩 종류 질문

0

51

2

로지스틱회귀, 회귀

0

51

2

회귀 문제를 풀때 질문입니다.

0

58

1

불균형 처리 후 성능이 더 낮아졌다면,

0

64

2

실기 체험 제2유형 에러 문의

0

64

1

LIGHTGBM 으로 하면 pred값이 소수점 6자리까지 나오는게 맞나요

0

51

2

3번문제 등분산 가정

0

49

2

작업형3 target 형 변환 질문

0

36

2

[작업형1] 연습문제 섹션1 ~ 10 의 section4

0

39

3

원핫인코딩과 레이블 인코딩에서 concat

0

60

2

제2유형 질문입니다.

0

48

2

C()

0

44

2

작업형 2에서 strafity 적용 유무

0

52

2

수강 기간 연장 가능 여부 문의드립니다.

0

61

1

ols

0

44

2

2유형 작성관련 질문(일반 심화)

0

40

2

2유형 작성관련 질문

0

41

2

2유형 object컬럼 개수 다르면

0

48

2