This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import roc_curve, auc | |
best_depth=dt_grid.best_params_['max_depth'] | |
best_samples=dt_grid.best_params_['min_samples_split'] | |
dt_1 = DecisionTreeClassifier(max_depth=best_depth,min_samples_split=best_samples) | |
dt_1.fit(X_train, y_train) | |
# roc_auc_score(y_true, y_score) the 2nd parameter should be probability estimates of the positive class | |
# not the predicted outputs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters = {'max_depth':[1, 5, 10, 20, 50], | |
'min_samples_split':[5, 10, 100, 500]} | |
dt = DecisionTreeClassifier() | |
dt_grid = GridSearchCV(dt, param_grid=parameters, n_jobs=-1, verbose=1,scoring='f1_macro',cv=3,return_train_score=True) | |
dt_grid.fit(X_train,y_train) | |
best_depth=dt_grid.best_params_['max_depth'] | |
best_samples=dt_grid.best_params_['min_samples_split'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min_max_scaler = preprocessing.MinMaxScaler() | |
def scale_fun(X_train,X_test,col): | |
min_max_scaler.fit(X_train[col].values.reshape(-1,1)) | |
X_train_=min_max_scaler.transform(X_train[col].values.reshape(-1,1)) | |
X_test_=min_max_scaler.transform(X_test[col].values.reshape(-1,1)) | |
return X_train_,X_test_ | |
for col in X_train.columns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
col_to_remove = ['Provider','BeneID', 'ClaimID', 'ClaimStartDt','ClaimEndDt','AttendingPhysician',\ | |
'OperatingPhysician', 'OtherPhysician','ClmAdmitDiagnosisCode','NoOfMonths_PartACov',\ | |
'NoOfMonths_PartBCov','DiagnosisGroupCode','AdmissionDt','DischargeDt'] | |
diagnosis_codes = ['ClmDiagnosisCode_1', 'ClmDiagnosisCode_2', 'ClmDiagnosisCode_3', | |
'ClmDiagnosisCode_4', 'ClmDiagnosisCode_5', 'ClmDiagnosisCode_6', | |
'ClmDiagnosisCode_7', 'ClmDiagnosisCode_8', 'ClmDiagnosisCode_9', | |
'ClmDiagnosisCode_10'] | |
procedure_codes = ['ClmProcedureCode_1','ClmProcedureCode_2','ClmProcedureCode_3','ClmProcedureCode_4','ClmProcedureCode_5','ClmProcedureCode_6'] | |
oth_cols = ['DOB','DOD','Claim_Start','Claim_Start','Admission_Date','Admission_Date','Claim_End','Discharge_Date'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClmProcedureCode_1_count = patient_data['ClmProcedureCode_1'].value_counts().to_dict() | |
patient_data['ClmProcedureCode_1_count']=patient_data['ClmProcedureCode_1'].map(ClmProcedureCode_1_count) | |
ClmProcedureCode_2_count = patient_data['ClmProcedureCode_2'].value_counts().to_dict() | |
patient_data['ClmProcedureCode_2_count']=patient_data['ClmProcedureCode_2'].map(ClmProcedureCode_2_count) | |
ClmProcedureCode_3_count = patient_data['ClmProcedureCode_3'].value_counts().to_dict() | |
patient_data['ClmProcedureCode_3_count']=patient_data['ClmProcedureCode_3'].map(ClmProcedureCode_3_count) | |
ClmDiagnosisCode_1_count = patient_data['ClmDiagnosisCode_1'].value_counts().to_dict() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patient_data['PotentialFraud'] = np.where(patient_data['PotentialFraud']=='Yes',1,0) | |
patient_data['RenalDiseaseIndicator'] = np.where(patient_data['RenalDiseaseIndicator']=='Y',1,0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patient_data['is_primary'] = np.where(patient_data['AttendingPhysician'].notnull(),1,0) | |
patient_data['is_secondary'] = np.where(patient_data['OperatingPhysician'].notnull(),1,0) | |
patient_data['is_tertiary'] = np.where(patient_data['OtherPhysician'].notnull(),1,0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diagnosis_codes = patient_data[['ClmDiagnosisCode_1', 'ClmDiagnosisCode_2', 'ClmDiagnosisCode_3', | |
'ClmDiagnosisCode_4', 'ClmDiagnosisCode_5', 'ClmDiagnosisCode_6', | |
'ClmDiagnosisCode_7', 'ClmDiagnosisCode_8', 'ClmDiagnosisCode_9', | |
'ClmDiagnosisCode_10']] | |
procedure_codes = patient_data[['ClmProcedureCode_1','ClmProcedureCode_2','ClmProcedureCode_3','ClmProcedureCode_4','ClmProcedureCode_5','ClmProcedureCode_6']] | |
Seven_diag_codes = ['4019','25000','2724','V5869','4011','42731','V5861'] # from EDA | |
patient_df = pd.DataFrame(columns = ['procedure']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reimb_amount = patient_data['IPAnnualReimbursementAmt'] + patient_data['OPAnnualReimbursementAmt'] | |
deduct_amount = patient_data['IPAnnualDeductibleAmt'] + patient_data['OPAnnualDeductibleAmt'] | |
patient_data['total_diff_amount'] = reimb_amount - deduct_amount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patient_data['Admission_Date'] = pd.to_datetime(patient_data['AdmissionDt'] , format = '%Y-%m-%d') | |
patient_data['Discharge_Date'] = pd.to_datetime(patient_data['DischargeDt'],format = '%Y-%m-%d') | |
patient_data['hospitalization_days'] = ((patient_data['Discharge_Date'] - patient_data['Admission_Date']).dt.days) + 1 |