질문&답변
PCA 관련 질문
import pandas as pd from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import cross_val_score df=pd.read_excel( '/content/drive/MyDrive/credit_card.xls' ,sheet_name= 'Data' ,header= 1 ) df.rename(columns={ 'PAY_0' : 'PAY_1' , 'default payment next month' : 'default' },inplace= True ) X_features=df.drop([ 'ID' , 'default' ],axis= 1 ) y_target=df[ 'default' ] bill_cols=[ 'BILL_AMT' +str(i) for i in range ( 1 , 7 )] scaler=StandardScaler() df_cols_scaled=scaler.fit_transform(X_features[bill_cols]) pca=PCA(n_components= 2 ) col_pca=pca.fit_transform(df_cols_scaled) bill=pd.DataFrame(data=col_pca, columns=[ 'bill_pca_1' , 'bill_pca_2' ]) df0=df.copy() pca_df=pd.concat([df0,bill],axis= 1 ) pca_df.drop(bill_cols,axis= 1 ,inplace= True ) X_features1=pca_df.drop( 'default' ,axis= 1 ) y_target=pca_df[ 'default' ] rf=RandomForestClassifier(n_estimators= 300 , random_state= 156 ) scores=cross_val_score(rf, X_features1, y_target,scoring= 'accuracy' , cv= 3 ) print ( '평균 정확도:' , np. round (np.mean(scores), 4 )) 이런 식으로 코드를 짜봤는데 0.61정도로 예측 성능이 많이 떨어지는 것 같습니다
- 좋아요수
- 0
- 댓글수
- 3
- 조회수
- 248





