To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 816be74a authored by felikskiszkurno's avatar felikskiszkurno
Browse files

WORKS!!!!!!!

parent 3cf7fae9
......@@ -20,8 +20,8 @@ import pygimli.meshtools as mt
import pygimli.physics.ert as ert
# Config
create_new_data = True
create_new_data_only = True
create_new_data = False
create_new_data_only = False
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
......@@ -35,13 +35,13 @@ else:
# TODO Put this part into a function
# Settings
number_of_tests = 100
number_of_tests = 50
rho_spread_factor = 1.5
rho_max = 25
rho_max = 20
layers_min = 1
layers_max = 2
min_depth = 4
max_depth = 15
max_depth = 10
# Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
......@@ -67,6 +67,7 @@ else:
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
if not create_new_data_only:
print('Running ML stuff...')
#for test_name in test_results.keys():
#slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
......
......@@ -22,7 +22,8 @@ def gbc_run(test_results, random_seed):
clf = ensemble.GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=1, random_state=0)
# Train classifier
accuracy_labels, accuracy_score = slopestabilityML.run_classification(test_training, test_prediction, test_results, clf)
accuracy_labels, accuracy_score = slopestabilityML.run_classification(test_training, test_prediction, test_results,
clf, 'GBC')
# Plot
slopestabilityML.plot_results(accuracy_labels, accuracy_score, 'GBC')
......
......@@ -22,9 +22,9 @@ def sgd_run(test_results, random_seed):
# Train classifier
accuracy_labels, accuracy_score = slopestabilityML.run_classification(test_training, test_prediction, test_results,
clf)
clf, 'SGD')
# Plot
slopestabilityML.plot_results(accuracy_labels, accuracy_score, 'GBC')
slopestabilityML.plot_results(accuracy_labels, accuracy_score, 'SGD')
return accuracy_score, accuracy_labels
......@@ -28,7 +28,8 @@ def svm_run(test_results, random_seed):
clf = svm.SVC(gamma=0.001, C=100, kernel='linear')
# Train classifier
accuracy_labels, accuracy_score = slopestabilityML.run_classification(test_training, test_prediction, test_results, clf)
accuracy_labels, accuracy_score = slopestabilityML.run_classification(test_training, test_prediction, test_results,
clf, 'SVM')
# for test_name in test_training:
#
......
......@@ -18,8 +18,8 @@ def plot_results(accuracy_labels, accuracy_score, clf_name):
plt.ylabel('Correct points [%]')
plt.title(clf_name+' classification accuracy')
print('plot script is executed')
fig.savefig('results/figures/'+clf_name+'.eps')
fig.savefig('results/figures/'+clf_name+'.pdf')
fig.savefig('results/figures/'+clf_name+'.png')
fig.savefig('results/figures/ML/'+clf_name+'.eps')
fig.savefig('results/figures/ML/'+clf_name+'.pdf')
fig.savefig('results/figures/ML/'+clf_name+'.png')
return
......@@ -11,7 +11,8 @@ import pandas as pd
def preprocess_data(data_set):
x_train = data_set.drop(['X', 'Y', 'Z', 'INM'], axis='columns')
x_train = data_set.drop(['X', 'Y', 'Z', 'INM', 'CLASS'], axis='columns')
print(x_train)
#y_train = data_set.drop(['X', 'Y', 'Z', 'INM'], axis='columns')
y_train = pd.DataFrame(data_set['CLASS'])
......
......@@ -18,21 +18,21 @@ from scipy import interpolate
import slopestabilitytools
def run_classification(test_training, test_prediction, test_results, clf):
def run_classification(test_training, test_prediction, test_results, clf, clf_name):
accuracy_score = []
accuracy_labels = []
num_feat = ['RES', 'SEN']
cat_feat = ['CLASS']
#cat_feat = ['CLASS']
cat_lab = [0, 1]
num_trans = StandardScaler()
cat_trans = OneHotEncoder(categories=[cat_lab])
#cat_trans = OneHotEncoder(categories=[cat_lab])
preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat),
('cat', cat_trans, cat_feat)])
preprocessor = ColumnTransformer(transformers=[('num', num_trans, num_feat),])
#('cat', cat_trans, cat_feat)])
clf_pipeline_UM = make_pipeline(preprocessor, clf)
......@@ -54,7 +54,7 @@ def run_classification(test_training, test_prediction, test_results, clf):
y_pred = clf_pipeline_UM.predict(x_question)
# print(y_pred)
score = clf_pipeline_UM.score(x_question, y_answer)
# print('score: '+str(score))
print('score: '+str(score))
# TODO: Move plotting to a function for plotting a, b and a-b
x = test_results[test_name_pred]['X']
......@@ -83,7 +83,7 @@ def run_classification(test_training, test_prediction, test_results, clf):
fig, _ax = plt.subplots(nrows=3, ncols=1)
ax = _ax.flatten()
fig.suptitle(test_name_pred)
fig.suptitle(test_name_pred+' '+clf_name)
fig.subplots_adjust(hspace=0.8)
im0 = ax[0].contourf(xi, yi, class_in_i)
......@@ -110,9 +110,9 @@ def run_classification(test_training, test_prediction, test_results, clf):
cb[2].locator = tick_locator
cb[2].update_ticks()
fig.savefig('results/figures/eps/{}_ML_class_res.eps'.format(test_name_pred))
fig.savefig('results/figures/png/{}_ML_class_res.png'.format(test_name_pred))
fig.savefig('results/figures/pdf/{}_ML_class_res.pdf'.format(test_name_pred))
fig.savefig('results/figures/ML/eps/{}_ML_{}_class_res.eps'.format(test_name_pred, clf_name))
fig.savefig('results/figures/ML/png/{}_ML_{}_class_res.png'.format(test_name_pred, clf_name))
fig.savefig('results/figures/ML/pdf/{}_ML_{}_class_res.pdf'.format(test_name_pred, clf_name))
# Evaluate result
#accuracy_score.append(len(np.where(y_pred == y_answer.to_numpy())) / len(y_answer.to_numpy()) * 100)
......
......@@ -17,7 +17,7 @@ def split_dataset(test_names, random_seed):
test_number = len(test_names)
test_prediction = random.choices(list(test_names),
k=math.ceil(test_number * 0.1))
k=math.ceil(test_number * 0.25))
test_training = slopestabilitytools.set_diff(list(test_names), set(test_prediction))
......
......@@ -25,6 +25,12 @@ def create_folder_structure():
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/png'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/ML/pdf'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/ML/eps'
is_success = check_create_folder(folder_path)
folder_path = os.getcwd() + '/results/figures/ML/png'
is_success = check_create_folder(folder_path)
# Folder for results
folder_path = os.getcwd()+'/results/'
......
......@@ -36,7 +36,7 @@ def create_data(test_name, test_config, max_depth):
ax_geometry.set_title('1 Geometry of the model')
fig_geometry.savefig('results/figures/png/'+test_name+'_1_geometry.png')
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-8*max_depth, stop=8*max_depth, num=16*max_depth+1),
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-8*max_depth, stop=8*max_depth, num=8*max_depth+1),
schemeName='dd')
for electrode in measurement_scheme.sensors():
......
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