Commit d6532bae authored by Feliks Kiszkurno's avatar Feliks Kiszkurno
Browse files

Modifications required to test labels instead of numerical classes

parent 20f1182c
......@@ -17,8 +17,8 @@ import test_definitions
settings.init()
test_definitions.init()
# Config
create_new_data = False # set to True if you need to reassign the classes
create_new_data_only = False # set to False in order to run ML classifications
create_new_data = True # set to True if you need to reassign the classes
create_new_data_only = True # set to False in order to run ML classifications
reassign_classes = False; class_type = 'norm'
# Load existing data instead of creating new one.
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"data = pd.read_csv('../results/data/hor_06.csv')\n",
"classesn = data['CLASSN']"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 11,
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-11-e87ec824444d>, line 12)",
"output_type": "error",
"traceback": [
"\u001B[0;36m File \u001B[0;32m\"<ipython-input-11-e87ec824444d>\"\u001B[0;36m, line \u001B[0;32m12\u001B[0m\n\u001B[0;31m labels = [labels[idx] = labels_translator[key] for idx in id_new]\u001B[0m\n\u001B[0m ^\u001B[0m\n\u001B[0;31mSyntaxError\u001B[0m\u001B[0;31m:\u001B[0m invalid syntax\n"
]
}
],
"source": [
"labels_translator = {0: 'Very Low',\n",
" 1: 'Low',\n",
" 2: 'Medium',\n",
" 3: 'High',\n",
" 4: 'Very High'}\n",
"labels = [None] * len(classesn)\n",
"find_all = lambda x, xs: [i for (y, i) in zip(xs, range(len(xs))) if x == y]\n",
"for key in labels_translator.keys():\n",
" id_new = find_all(key, classesn)\n",
" for idx in id_new:\n",
" labels[idx] = labels_translator[key]"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ def init():
settings['norm_class'] = True # True to use normalized classes, False to use class_ids
settings['norm_class_num'] = 5 # Number of classes for normalized data
settings['norm'] = True # True to use normalized data, False to use raw data
settings['use_labels'] = True # True to use labels instead of classes
# Include sensitivity
settings['sen'] = True # True - include sensitivity, False - ignore sensitivity
......
......@@ -59,12 +59,16 @@ def run_classification(test_training, test_prediction, test_results, clf, clf_na
#cat_feat = ['CLASS']
cat_lab = [0, 1]
#cat_trans = OneHotEncoder(categories=[cat_lab])
num_trans = StandardScaler()
preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat)])#,
#('cat', cat_trans, cat_feat)])
if settings.settings['use_labels'] is True:
cat_feat = ['LABEL']
cat_trans = OneHotEncoder(categories=[cat_lab])
preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat),
('cat', cat_trans, cat_feat)])
else:
preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat)])
clf_pipeline = make_pipeline(preprocessor, clf)
......
......@@ -20,7 +20,6 @@ import settings
def create_data(test_name, test_config, max_depth):
world_boundary_v = [-9 * max_depth, 0] # [NW edge] relatively to the middle
world_boundary_h = [9 * max_depth, -9 * max_depth] # [SE edge]
# world_boundary_v = [-500, 0] # [right, left border] relatively to the middle
......@@ -98,7 +97,7 @@ def create_data(test_name, test_config, max_depth):
array_min = np.min(input_model2_array)
result_array = slostabcreatedata.clip_data(result_array, array_max, array_min)
input_model2_array_norm = np.log(input_model2_array)
#input_model2_array_norm = slopestabilitytools.normalize(input_model2_array)
# input_model2_array_norm = slopestabilitytools.normalize(input_model2_array)
fig_input, ax_input = plt.subplots(1)
pg.show(ert_manager.paraDomain, input_model2, label=pg.unit('res'), showMesh=True, ax=ax_input)
......@@ -136,11 +135,23 @@ def create_data(test_name, test_config, max_depth):
rho_min = np.min(rho_arr)
# TODO: this assumes only two resistivities, extend it to consider more
#result_array[np.where(result_array < rho_min)] = rho_min
#result_array[np.where(result_array > rho_max)] = rho_max
# result_array[np.where(result_array < rho_min)] = rho_min
# result_array[np.where(result_array > rho_max)] = rho_max
result_array_norm = np.log(result_array)
#result_array_norm = slopestabilitytools.normalize(result_array)
# result_array_norm = slopestabilitytools.normalize(result_array)
labels_translator = {0: 'Very Low',
1: 'Low',
2: 'Medium',
3: 'High',
4: 'Very High'}
labels = [None] * len(classesn)
find_all = lambda x, xs: [i for (y, i) in zip(xs, range(len(xs))) if x == y]
for key in labels_translator.keys():
id_new = find_all(key, classesn)
for idx in id_new:
labels[idx] = labels_translator[key]
experiment_results = pd.DataFrame(data={'X': ert_manager.paraDomain.cellCenters().array()[:, 0],
'Y': ert_manager.paraDomain.cellCenters().array()[:, 1],
......@@ -151,7 +162,8 @@ def create_data(test_name, test_config, max_depth):
'RESN': result_array_norm,
'SEN': cov,
'CLASS': classes,
'CLASSN': classesn})
'CLASSN': classesn,
'LABELS': labels})
experiment_results.to_csv(settings.settings['data_folder'] + '/' + test_name + '.csv')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment