1-3. date_added가 2018년 1월 이면서 country가 United Kingdom 단독 제작인 데이터의 갯수 에서 제가 df['date_added']=pd.to_datetime(df['date_added']) cond1 = df['date_added'].dt.year ==2018 cond2 = df['date_added'].dt.month ==1 cond3 = df['country']=='United Kindom' print(len(df[cond1&cond2&cond3])) 했는데 저는 0이 나옵니다ㅠ 답은 6이 나와야하는 것 같은데 뭐가 잘못된 것일까요 감사합니다
안녕하세요 선생님, 800대로 나와야 될 RMSE 값이 1100대로 나오는데, 차이가 좀 커서 문제가 있는것 같아요. 혹시 제 코드좀 봐주실 수 있을까요? import pandas as pd train = pd.read_csv("data/customer_train.csv") test = pd.read_csv("data/customer_test.csv") cols = test.select_dtypes('object').columns # ## 전처리1. 컬럼삭제 # train = train.drop(cols, axis=1) # test = test.drop(cols, axis=1) ## 전처리2. 레이블인코딩 from sklearn.preprocessing import LabelEncoder le = LabelEncoder() for col in cols : train[col] = le.fit_transform(train[col]) test[col] = le.transform(test[col]) # 검증-테스트 데이터 분리 from sklearn.model_selection import train_test_split X_tr, X_val, y_tr, y_val = train_test_split( train.drop('총구매액', axis=1), train['총구매액'], test_size=0.2, random_state=1 ) # 랜덤포레스트 from sklearn.ensemble import RandomForestRegressor model = RandomForestRegressor(random_state=1) model.fit(X_tr, y_tr) pred = model.predict(X_val) # 평가 from sklearn.metrics import root_mean_squared_error print(root_mean_squared_error(y_val, pred)) ## 컬럼삭제 : 1135.0196199 ## 레이블인코딩: 1136.88945667
문제 1-3에서 ' 문제1-2에서 적합한 회귀모형을 이용하여 test데이터에서 design값을 산출한 후 ...라고 되어있습니다. model = ols ( "design ~ c1+c2+c4" , data=test ) .fit () 문제 1-2에서 이렇게 적합된 모델을 먼저 불러오고 test [ 'pred_design' ] =model.predict ( test ) 테스트 예측값 산출 식 작성하면 안되나요~? 문제에서 1-2에서 적합한 모형 이용이라는 문구가 있어서 헷갈립니다~! ㅠㅠ 이렇게 풀었을때는 8.17이 정답으로 나옵니당..
안녕하세요 강사님! 좋은 강의에 감사드립니다. 다름이 아니라 코랩에서는 가끔 df로 받는 연산함수같은 경우, 다시 한번 눌렀을 때 결과가 계속 달라지는 경우가 있더라구요. (예시) df = len(df) * 0.7 등 하면 점점 df가 줄어든다던지.. 그래서 코랩에서는 다시 클릭하기보다, 다음 +코드로 넘어가서 작성을 하는데요. 시험 환경에서는 무조건 첫줄부터 새로 시작인가요? 중간 과정 확인하다가 연산이 두번 되어서 값이 바뀔까봐 염려되네요 ㅠㅠ
안녕하세요 강사님! 좋은 강의에 감사드립니다. 다름이 아니라, 3회 기출문제(작업형2)에서 아래와 같이 robust scaler를 사용하실 때 train과 test를 각각 스케일링하는 거랑 data = pd.concat[train, test]로 합치는 것과 실전에서 영향이 없을까요? train 범위 표본을 가지고 fit 한 경우와 concat한 큰 data를 가지고 fit 한 경우가 스케일링 결과가 다른 경우가 있을까요? n_train[cols] = scaler.fit_transform(n_train[cols]) n_test[cols] = scaler.transform(n_test[cols])
4회 기출 작업형2에서 해설처럼 # test데이터 ID 복사 test_ID = test.pop('ID') test_ID test_ID를 따로 분리하지 않고 아래처럼 test['ID'] 이렇게 작성해도 같은 결과값이 나올까요? pred = model.predict(test) result = pd.DataFrame({'ID' : test['ID'] , 'Segmentation' : pred }) result.to_csv('result.csv', index = False) print(pd.read_csv('result.csv'))
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! 질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요 먼저 유사한 질문이 있었는지 검색해보세요 작업형2번 문제 전처리 부분을 원핫인코딩한다면 어떤 코딩으로 써야하나요? 답변부탁드립니다. 원핫으로만 하려고하는데 다양하게 알려주셔서 더 헷갈려서요..
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! 질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요 먼저 유사한 질문이 있었는지 검색해보세요 cond1 = df['구분'] = '발생건수' cond2 = df['구분'] = '검거건수' df1 = df[cond1] df2 = df[cond2] df2 이렇게 입력했는데 --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /usr/local/lib/python3.12/dist-packages/pandas/core/indexes/base.py in get_loc(self, key) 3804 try: -> 3805 return self._engine.get_loc(casted_key) 3806 except KeyError as err: index.pyx in pandas._libs.index.IndexEngine.get_loc() index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() KeyError: '발생건수' The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) 2 frames /usr/local/lib/python3.12/dist-packages/pandas/core/indexes/base.py in get_loc(self, key) 3810 ): 3811 raise InvalidIndexError(key) -> 3812 raise KeyError(key) from err 3813 except TypeError: 3814 # If we have a listlike key, _check_indexing_error will raise KeyError: '발생건수' 왜 발생건수에 대한 오류가 뜨는거죠? 정말 샅샅히 오류를 찾아봤는데 선생님이 하신거랑 똑같이한거같은데 ㅠㅠ
선생님 안녕하세요. 여러 모델을 외우기 힘들면 랜덤포레스트 하나로 가도 된다고 말씀해주셨는데, 그렇게하면 평가(RMSE, ...)를 하는게 의미가 없다고 생각하는데요. 평가자체를 하지 않고 랜덤포레스트 모델로 학습시켜 바로 예측하여 제출해도 문제가 없는걸까요? 그리고, 연습문제 저 혼자 풀어보고 선생님 파일이랑 대략 비교해보고싶은데, 어떻게 비교 또는 확인해볼 수 있을까요?