-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinalTestPCR.py
52 lines (39 loc) · 1.83 KB
/
FinalTestPCR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
import joblib
# Load the test dataset
test_data = pd.read_excel("TestDatasetExample.xls", header=None, na_values=['?'])
# Assume the first row contains column names
test_data.columns = test_data.iloc[0]
test_data = test_data.iloc[1:]
# Extract the 'ID' column
test_ids = test_data['ID']
# Extract selected feature from implementation
selected_features = ['ER', 'PgR', 'HER2', 'LNStatus', 'original_firstorder_10Percentile',
'original_gldm_DependenceEntropy',
'original_gldm_LargeDependenceEmphasis',
'original_glrlm_RunLengthNonUniformityNormalized',
'original_glrlm_RunPercentage']
test_data = test_data[selected_features]
# Exclude non-numeric columns from scaling (assuming 'ID' is non-numeric)
non_numeric_columns = ['ID']
numeric_columns = [col for col in test_data.columns if col not in non_numeric_columns]
# Replace 999 with NaN in numeric columns
test_data[numeric_columns] = test_data[numeric_columns].replace(999, np.nan)
# Mean imputation for numeric columns
test_data_imputed = test_data.copy()
test_data_imputed[numeric_columns] = test_data_imputed[numeric_columns].fillna(
test_data_imputed[numeric_columns].mean())
# Standardize only numeric columns
scaler = StandardScaler()
test_data_standardized = test_data_imputed.copy()
test_data_standardized[numeric_columns] = scaler.fit_transform(test_data_imputed[numeric_columns])
# Load the model
loaded_model = joblib.load('AdaBoost_Model.joblib')
# Predict using each model
predictions = pd.DataFrame({"ID": test_ids})
PCR_pred = loaded_model.predict(test_data_standardized[numeric_columns])
predictions["pCR( outcome )"] = PCR_pred
# Save predictions to a CSV file
predictions.to_csv("FinalTestPCR.csv", index=False)