4회 기출 유형(작업형2)
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
왜 저는 원핫인코딩할떄 bool로나오죠? 이번 한번이 아니라 전에도 강의에서는 int로 나오던데 왜 저만 bool로나오는지 이해가안가더라구요
- python
- 머신러닝
- 빅데이터
- pandas
- 빅데이터분석기사
172만명의 커뮤니티!! 함께 토론해봐요.
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
왜 저는 원핫인코딩할떄 bool로나오죠? 이번 한번이 아니라 전에도 강의에서는 int로 나오던데 왜 저만 bool로나오는지 이해가안가더라구요
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! 질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요 먼저 유사한 질문이 있었는지 검색해보세요 안녕하세요, 기출(작업형2) 한 가지 방법으로 풀기 듣다가 기출 유형에는 결측치가 있는 경우가 없었어서 질문드립니다. 기출에서는 타겟이 범주형 자료일 때를 감안하여 전처리 전에 target =train.pop('타겟컬럼') 을 입력하고 이후 에 원-핫 인코딩 진행 하는걸 추천한다 하셨는데요, 만약 결측치가 존재하여 전처리 과정에 결측치 처리가 추가된다면 이때도 pop 함수를 먼저 사용한 후에 결측치 처리를 해야하나요?? pop 함수가 시험 환경의 train 데이터를 x_train ,y_ train 으로 나눠주는 것과 같은 기능을 하는 것으로 이해했는데 만약 train data 와 target column data 둘 다에 결측치가 있다면 먼저 결측치를 처리한다음에 pop 함수 처리를 하는게 맞지 않나요???
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
여기 문제들처럼 홀수행, 짝수행별로 값이 필요할때 사용할수 있는 함수는 따로 없을까요? unstack을 사용하거나 조건을 만들어 사용해서 구하는 방법밖엔 없을까요
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
안녕하세요 강사님! 작업형2유형 질문이 있어서 글 남깁니다. pd.get_dummies 함수를 사용하면 컬럼수가 10개인것이 200개, 300개로 증가하는 경우가 있습니다. 문제가 없는건지 궁금합니다! concat 함수 말고 test = test.reindex(columns = train.columns, fill_value =0) 으로 train컬럼수와 test 컬럼수를 일치시켜도되는걸까요? 그리고 전처리 후 학습 및 평가를 할때 강사님께서는 train 데이터를 두개로 분리해서 80%로만 학습시키고, 20%로 예측 후 평가하시는 걸로 알고 있습니다. 이후 test 데이터를 예측할 때는 train 데이터 80% 학습한 모델을 통해 예측하는 걸로 이해했습니다. 만약 train 데이터 분리와 평가과정을 건너뛴다면, train 데이터 전체로 학습하고 test 데이터를 예측하는건데, 이부분은 상관이 없는걸까요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
혹시 실제 시험문제가 다 이런식으로 세팅되어서 이에 맞게 풀라고 되어있나요? 오히려 처음부터 작성하면 괜찮은데 이런 세팅이 있으니까 너무 헷갈려서요..
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
concat해서 train과test를 나누는 경우는 어떤 경우인가요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
from sklearn.model_selection import train_test_split X_tr, X_val, y_tr, y_val = train_test_split(train.drop('output', axis=1), train['output'], test_size=0.15, random_state=2022) 이런식으로 안 하고 전처리 과정에서 y = train.pop으로 해도 되나요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
이렇게 오류가 나는데 rmsle는 사용이 안 되는데 어떻게 하나요 r2는 큰게 좋다고 하시고 나머지는 작아야 좋다고 했는데 이렇게 나오는 경우 어떻게 하나요? 3. linearRegresssion은 random_state가 불가능인가요? 제공해주신 노트에는 다 랜덤값이 고정되있지 않읃데 0으로 고정하는게 맞는 거죠?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
안녕하세요. 작업형2 검증 데이터 분리 부분에서 radom_state에 아무 값이나 넣어도 되는 것 맞나요? 예를 '작업형2모의문제2' 강의에서 선생님은 2022를 넣으셨고 저는 2025를 넣었는데 마지막 print(r2_score(y_test, pred)) 확인 부분에서 차이가 많이 나는 것 같아서요 (선생님 코드에서 결과: -0.03400981426239014 제가 실행한 결과: -0.013191699981689453)
미해결
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! 질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요 먼저 유사한 질문이 있었는지 검색해보세요
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
삭제할지 다른 값으로 채울지 어떻게 결정하나요? 보통 문자이고 수가 많으면 삭제하는 게 더 나을까요? 수는 웬만하면 삭제보단 채우는 게 나을까요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
CustomID를 삭제할 때 test 데이터에서도 완전히 삭제를 하는게 맞나요? train 데이터에서 삭제하는게 정석. 하지만 최종 파일 제출에 붙여야 하기 때문에 test 데이터에는 아래와 같이 pop함수를 를 써서 보관을 해둬야한다고 하셨던거 같아서요ㅜㅜ ex) test_id = test.pop('id')
미해결
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
predict_proba로 제출한 이유는 뭔가요?? roc_auc를 제외하곤 나머지 평가지표를 구할필요가 없지 않나요?
미해결
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
해당 코드를 실행하면 다음과 같이 데이터가 결합됩니다 ... ㅠㅠ
미해결
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
lightgbm을 사용하지 않는 이유는 뭔가요? random보다light가 더 높게 나오는데 둘 다 사용해버ㅏ야 하는 거 아닌가요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
# 결측치 처리(범주형) c_cols = ['Model', 'Series', 'Processor', 'Processor_Gen', 'Hard_Disk_Capacity', 'OS'] train[c_cols] = train[c_cols].fillna("X") test[c_cols] = test[c_cols].fillna("X") # 결측치 처리(수치형) n_cols = ['RAM'] train[n_cols] = train[n_cols].fillna(-1) test[n_cols] = test[n_cols].fillna(-1) 1. 결측치 처리를 문제에서 결측치 처리 하라는 말 없어도 그냥 하는건가요? 2. 범주형은 문자열 X로 하는건가요? 그냥 하는건지? 3. 수치형은 -1로 한건가요? 왜 -1로 한건가요? # 원핫인코딩 combined = pd.concat([train, test]) combined_dummies = pd.get_dummies(combined) n_train = len(train) train = combined_dummies[:n_train] test = combined_dummies[n_train:] 4. 합쳐서 인코딩한게.. 그 오브젝트 유니크 수가 트레인이랑, 테스트가 달라서 한거 맞을까요? 제가 코딩한 거는 target=train.pop('Price') c_cols=['Model','Series','Processor', 'Processor_Gen', 'Hard_Disk_Capacity','OS'] train[c_cols]=train[c_cols].fillna("X") test[c_cols]=test[c_cols].fillna("X") n_cols=['RAM'] train[n_cols]=train[n_cols].fillna(-1) test[n_cols]=test[n_cols].fillna(-1) print(train.isnull().sum().sum()) print(test.isnull().sum().sum()) df=pd.concat([train, test]) df=pd.get_dummies(df) train=train.iloc[:len(train)] test=test.iloc[len(train):] from sklearn.model_selection import train_test_split X_tr, X_val, y_tr, y_val = train_test_split(train, target, test_size=0.2, random_state=0) print(X_tr.shape, X_val.shape, y_tr.shape, y_val.shape) from sklearn.ensemble import RandomForestRegressor rf=RandomForestRegressor(random_state=0) rf.fit(X_tr, y_tr) pred=rf.predict(X_val) from sklearn.metrics import r2_score r2_score(y_val, pred) 이렇게했는데 ~~~~~~ (72, 9) (19, 9) (72,) (19,) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ ipython-input-2530691866.py in <cell line: 0>() 31 from sklearn.ensemble import RandomForestRegressor 32 rf=RandomForestRegressor(random_state=0) ---> 33 rf.fit (X_tr, y_tr) 34 pred=rf.predict(X_val) 35 6 frames /usr/local/lib/python3.12/dist-packages/pandas/core/ generic.py in array (self, dtype, copy) 2151 ) -> np.ndarray: 2152 values = self._values -> 2153 arr = np.asarray(values, dtype=dtype) 2154 if ( 2155 astype_is_view(values.dtype, arr.dtype) ValueError: could not convert string to float: 'Lenovo' 이렇게 오류가 납니다 그전까지는 뭔가 잘 실행됐는데 랜덤포레스트이후??오류가 납니다
미해결
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
이 문제에서 train과 test 합쳐서 원핫인코딩 combined = pd.concat([train, test]) combined_dummies = pd.get_dummies(combined) n_train = len(train) train = combined_dummies[:n_train] test = combined_dummies[n_train:] 한 이유가 city 컬럼에서 트레인 유니크 개수>테스트 유니크 개수라서 사용했다고 이해했는데,, 맞을까요? 2. 제가 코드 한거는 print(train.shape, test.shape) # print(train.isnull().sum()) # print(test.isnull().sum()) print( train.info ()) print( test.info ()) print(train.describe(include="O")) print(test.describe(include="O")) a=set(train['city']) b=set(test['city']) print(a-b) print(b-a) target=train.pop('target') df=pd.concat([train, test]) df=pd.get_dummies(df) train=train.iloc[:len(train)] test=test.iloc[len(train):] from sklearn.model_selection import train_test_split X_tr, X_val, y_tr, y_val = train_test_split(target, train, test_size=0.2, random_state=0) print(X_tr.shape, X_val.shape, y_tr.shape, y_val.shape) from sklearn.ensemble import RandomForestClassifier rf = RandomForestClassifier(random_state=0) rf.fit (X_tr, y_tr) pred = rf.predict_proba(X_val) 이렇게 하니까 ~~~~~~ (12260,) (3066,) (12260, 13) (3066, 13) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ ipython-input-1337250417.py in <cell line: 0>() 24 from sklearn.ensemble import RandomForestClassifier 25 rf = RandomForestClassifier(random_state=0) ---> 26 rf.fit (X_tr, y_tr) 27 pred = rf.predict_proba(X_val) 4 frames /usr/local/lib/python3.12/dist-packages/sklearn/utils/ validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_non_negative, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 1091 "if it contains a single sample." 1092 ) -> 1093 raise ValueError(msg) 1094 1095 if dtype_numeric and hasattr(array.dtype, "kind") and array.dtype.kind in "USV": ValueError: Expected a 2-dimensional container but got <class 'pandas.core.series.Series'> instead. Pass a DataFrame containing a single row (i.e. single sample) or a single column (i.e. single feature) instead. 이런 에러가 나옵니다ㅠ 분할까지는 했는데,, 랜덤포레스트부터 오류가 뜹니다
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! 질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요 먼저 유사한 질문이 있었는지 검색해보세요 안녕하세요 선생님 roc-auc 는 프레딕프로바를 사용하면 좋다고하셨는데요. 제가 왕초보에다가 기간이 얼마 안남아서 혹시 그냥 predict로 통일해서 사용해도 괜찮을까요? 즉 40점 만점을 목표로 predict로 통일해도 predict proba와 유의미한 차이가 있을까요?
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
df=pd.concat([train, test]) df=pd.get_dummies(df) train=train.iloc[:len(train)] test=test.iloc[len(train):] print(train.shape, test.shape) print로 컬럼 수 일치하는지 반드시 확인이라고 햇는데 어떤 컬럼수가 어떤거랑 일치해야하는거죠?? 아 그리고 이렇게 분리를 다시 했으면 train_test_split 이 코딩은 더 안해도되나요? 이것도 또 해야하나요? X_tr, X_val, y_tr, y_val 이요
해결됨
[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)
Section 3. 항공권 가격 예측 # 컬럼 삭제 train = train.drop('flight', axis=1) test = test.drop('flight', axis=1) 컬럼삭제한 이유는 무엇이죠? print(train.describe(include="O")) print(test.describe(include="O"))이걸 돌려봤는데 트레인에서 플라이트 유니트 1153 테스트에서 플라이트 유니크가 4502 이렇게 달라서 컬럼 삭제하는건가요? 어떨 때 컬럼 삭제해야하는지, 또 시험에 어떤 형식이 나올때 삭제해야하는지 궁금합니다 2.제가 코딩을 print(train.shape, test.shape) train=pd.get_dummies(train) test=pd.get_dummies(test) print(train.shape, test.shape) from sklearn.model_selection import train_test_split X_tr, X_val, y_tr, y_val = train_test_split(train, target, test_size=0.2, random_state=0) print(X_tr.shape, X_val.shape, y_tr.shape, y_val.shape) 이렇게 했는데 (10505, 11) (4502, 10) (4502, 9) (4502, 10) (4502, 37) (4502, 930) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ ipython-input-2712245612.py in <cell line: 0>() 20 print(train.shape, test.shape) 21 from sklearn.model_selection import train_test_split ---> 22 X_tr, X_val, y_tr, y_val = train_test_split(train, target, test_size=0.2, random_state=0) 23 print(X_tr.shape, X_val.shape, y_tr.shape, y_val.shape) 3 frames /usr/local/lib/python3.12/dist-packages/sklearn/utils/ validation.py in check_consistent_length(*arrays) 473 uniques = np.unique(lengths) 474 if len(uniques) > 1: --> 475 raise ValueError( 476 "Found input variables with inconsistent numbers of samples: %r" 477 % [int(l) for l in lengths] ValueError: Found input variables with inconsistent numbers of samples: [4502, 10505] 이렇게 오류가 뜹니다