728x90
반응형

https://ichi.pro/ko/yeonsog-yeol-nulag-deiteo-cheoli-bangbeob-mich-guhyeon-78086618663363

 

연속 열 누락 데이터 처리 방법 및 구현

지난 블로그 링크에서 누락 된 값과 그 유형에 대해 설명했습니다. 이 블로그에서는 구현을 통해 데이터 세트의 연속 데이터 열에 대한 누락 된 값을 처리하는 방법을 설명합니다.

ichi.pro

 

 

 

728x90
반응형
728x90
반응형

https://teddylee777.github.io/pandas/pandas-interpolation

 

Pandas를 활용한 결측치 보간(interpolation) 하기

Pandas를 활용한 결측치 보간(interpolation) 하는 방법에 대해 알아보겠습니다.

teddylee777.github.io

 

 

728x90
반응형
728x90
반응형

학습/테스트 데이터의 스케일 변환시 주의사항

 

MinMaxScaler 객체의 fit( ) 과 transform( )

이 둘은 2차원 데이터만 가능하므로 reshape(-1, 1)로 차원 변경해야 한다. 

 

train_array = np.arrange(0, 11).reshape(-1,1)

test_array = np.arrange(0, 6).reshape(-1,1)

 

 

fit( ) 의 경우 [0,10] 스케일이 적용됨.

 

 

일반적으로 fit_transform( )을 사용하여 학습데이터와 테스트 데이터 스케일을 변환한다. 이는 fit( )과 transform( )을 순차적으로 수행하는 메소드이다. 

 

학습데이터에서는 상관없지만, 테스트 데이터에서는 fit_transform( )을 절대 사용해서는 안된다. 

 

라서, 정확히 사용하려면, 학습과 테스트 데이터를 분리하기 전에 스케일링을 적용하고 분리해야 한다. 

 

이 주의사항은 차원축소변환, 피쳐벡터화 변화 작업에도 동일하게 적용된다. 

 

728x90
반응형
728x90
반응형

df = dd.reset_index()['Tair']

728x90
반응형
728x90
반응형

 

 

 

https://www.youtube.com/watch?v=7PWgx16kH8s 

 

728x90
반응형
728x90
반응형

LSTM 다룰 때 중요한 부분!

에러 

 

ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 100, 1), found shape=(None, 21)

 

 

 

원인

LSTM 모델을 사용할 때는, train 차원을 바꾸어야 하는데, 차원 변경을 해 주지 않으면 발생하는 에러

 

 

 

해결

 

X_train = X_train.reshape(X_train.shape[0], X_train[1], 1) 

명령으로 2차원 데이터를 3차원으로 변경하면 됨. 

728x90
반응형
728x90
반응형

 

 

 

코드

 

ftr_importances_values = model.feature_importances_
ftr_importances = pd.Series(ftr_importances_values)#, index=X_train.columns)
ftr_top20 = ftr_importances.sort_values(ascending=False)[:20]

plt.figure(figsize=(15,6))
sns.barplot(x=ftr_top20, y=ftr_top20.index)
# plt.show()

728x90
반응형
728x90
반응형

 

 

 

코드 

 

from sklearn.model_selection import GridSearchCV

params = {
    'n_estimators':[100],
    'max_depth'   : [6,8,10.,12],
    'min_samples_leaf' : [8,12, 18], 
    'min_samples_split' : [8,16, 20]
}

rf_clf = RandomForestClassifier(random_state=0)
model = rf_clf

 

 

grid_cv = GridSearchCV(model, param_grid=params, cv=2, n_jobs=-1)
grid_cv.fit(X_train, y_train)

print('Best parameter:\n', grid_cv.best_params_)
print('Highest accuracy: {0:.4f}'.format(grid_cv.best_score_))

 

 

 

 

 

 

 

 

 

 

출처: 파이썬 머신러닝 완벽가이드 p220

 

 

728x90
반응형
728x90
반응형

def roc_curve_plot(y_test, pred_proba_c1):
    fprs, tprs, thresholds = roc_curve(y_test, pred_proba_c1)
    plt.plot(fprs, tprs, label='ROC')
    plt.plot([0,1], [0,1], 'k--', label='Random')
    
    start, end = plt.xlim()
    plt.xticks(np.round(np.arange(start, end, 0.1), 2))
    plt.xlim(0,1);plt.ylim(0,1)
    plt.xlabel('FPR( 1 - sensitivity )'); plt.ylabel('TPR( Recall )')
    plt.legend()
    

    

728x90
반응형
728x90
반응형
from sklearn.metrics import accuracy_score, precision_score, recall_score, confusion_matrix, f1_score, roc_auc_score
from sklearn.metrics import roc_curve
def get_clf_eval(y_test, pred=None, pred_proba=None):
    confusion = confusion_matrix(y_test, pred)
    accuracy= accuracy_socre(y_test, pred)
    precision = precision_score(y_test, pred)
    recall = recall_score(y_test, pred)
    f1 = f1_score(y_test, pred)
    roc_auc = roc_auc_score(y_test, pred_proba)
    print('error matrix')
    print(confusion)
    print('Accu : {0:.4f}, Prec : {1:.4f}, Recu : {2:.4f},\
             F1 : {3:.4f},  AUC : {4:.4f}'.format(accuracy, precision, recall, f1, roc_auc))
728x90
반응형

+ Recent posts