Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code update and results
  • Loading branch information
eam15110 committed Apr 26, 2020
1 parent db00322 commit ed92476
Show file tree
Hide file tree
Showing 3 changed files with 739 additions and 2 deletions.
6 changes: 6 additions & 0 deletions preprocessing.py
Expand Up @@ -9,6 +9,12 @@ def get_data(data_file):
return data


def get_data_with_id(data_file):
data = pd.read_csv(data_file)

return data


# imputation
def get_average_column_value(data, col):
total = 0
Expand Down
35 changes: 33 additions & 2 deletions random_forest.py
Expand Up @@ -14,7 +14,7 @@ def get_train_test(data):
labels = np.where(labels == 2, 0, labels)
labels = np.where(labels == 4, 1, labels)
train, test, train_labels, test_labels = train_test_split(data, labels,
test_size=0.3, random_state=42)
test_size=0.3, random_state=1)
return [train, test, train_labels.astype(int), test_labels.astype(int)]


Expand Down Expand Up @@ -259,13 +259,44 @@ def all_combos_accuracy(removed_data, average_data):

print(test_accuracy)


def get_results(model, X, y, result_doc, ids):
result = open(result_doc, 'w+')
result.write('samplecodenumber,trueclass,predclass\n')

loaded_model = pickle.load(open(model, 'rb'))
predictions = loaded_model.predict(X)

for i in range(len(predictions)):
if y[i] == 2:
Y = 0
else:
Y = 1

result.write(str(ids[i]))
result.write(',')
result.write(str(Y))
result.write(',')
result.write(str(predictions[i]))
result.write('\n')

result.close()


if __name__ == '__main__':
original, removed, average = preprocessing.preprocess()
with_id = preprocessing.get_data_with_id('breast-cancer-wisconsin.data')
# train_all_combos(removed, average)
# all_combos_accuracy(removed, average)
# all_combos_roc(removed, average)
investigate(removed, average)
# investigate(removed, average)

X = average[average.columns[:-1]]
y = average[average.columns[-1]].values

get_results('models/average_gini_normal_80.model', X, y, 'randomforest_result.txt', with_id['ID'].values)





Expand Down

0 comments on commit ed92476

Please sign in to comment.