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 c1cd8b8a authored by felikskiszkurno's avatar felikskiszkurno
Browse files

MILESTONE

First working version. Executes test of classification with SVM and plots evaluated result.
parent 1d056330
......@@ -11,43 +11,52 @@ import matplotlib.pyplot as plt
import pandas as pd
import slopestabilitytools
import slopestabilitytools.datamanagement
import slopestabilityML
import slostabcreatedata
import pygimli as pg
import pygimli.meshtools as mt
import pygimli.physics.ert as ert
# Config
create_new_data = False
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
# Settings
number_of_tests = 10
rho_spread_factor = 1.5
rho_max = 150
layers_min = 1
layers_max = 5
min_depth = 1
max_depth = 25
if not create_new_data:
test_results = slopestabilitytools.datamanagement.import_tests()
else:
# Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
rho_spread_factor, rho_max,
layers_min, layers_max,
min_depth, max_depth)
# TODO Put this part into a function
# Create models and invert them
test_results = {}
# Settings
number_of_tests = 10
rho_spread_factor = 1.5
rho_max = 150
layers_min = 1
layers_max = 5
min_depth = 1
max_depth = 25
for test_name in tests_horizontal.keys():
# Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
rho_spread_factor, rho_max,
layers_min, layers_max,
min_depth, max_depth)
test_result_curr = slostabcreatedata.create_data(test_name, tests_horizontal[test_name], max_depth)
test_results.update({test_name: test_result_curr})
del test_result_curr
# Create models and invert them
test_results = {}
# Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: '+test_name)
for test_name in tests_horizontal.keys():
test_result_curr = slostabcreatedata.create_data(test_name, tests_horizontal[test_name], max_depth)
test_results.update({test_name: test_result_curr})
del test_result_curr
# Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
svm_accuracy_score, svm_accuracy_labels = slopestabilityML.svm_run(test_results)
......@@ -26,7 +26,7 @@ def svm_run(test_results):
k=math.ceil(test_number * 0.1))
test_training = slopestabilitytools.set_diff(list(test_results.keys()), set(test_prediction))
print(test_prediction)
# Create classifier
clf = svm.SVC(gamma=0.001, C=100, kernel='linear')
......@@ -35,7 +35,7 @@ def svm_run(test_results):
for test_name in test_training:
# Prepare data
data_set = test_results[test_name]
x_train = data_set.drop('Z', 'INM', 'CLASS')
x_train = data_set.drop(['Z', 'INM', 'CLASS'], axis='columns')
y_train = data_set['CLASS']
# Train classifier
......@@ -44,8 +44,10 @@ def svm_run(test_results):
# Predict with classfier
for test_name_pred in test_prediction:
# Prepare data
data_set_pred = test_prediction[test_name_pred]
x_question = data_set_pred.drop('Z', 'INM', 'CLASS')
data_set_pred = test_results[test_name_pred]
print(data_set_pred)
x_question = data_set_pred.drop(['Z', 'INM', 'CLASS'], axis='columns')
y_answer = data_set_pred['CLASS']
y_pred = clf.predict(x_question)
......
......@@ -11,13 +11,15 @@ import matplotlib.pyplot as plt
def plot_results(accuracy_labels, accuracy_score):
plt.figure()
plt.scatter(accuracy_labels, accuracy_score)
plt.ylabel('Test name')
plt.xlabel('Correct points [%]')
fig = plt.figure()
ax = plt.subplot(111)
ax.scatter(accuracy_labels, accuracy_score)
plt.xlabel('Test name')
plt.ylabel('Correct points [%]')
plt.title('SVM classification accuracy')
plt.savefig('results/figures/SVM.eps')
plt.savefig('results/figures/SVM.pdf')
plt.savefig('results/figures/SVM.png')
print('plot script is executed')
fig.savefig('results/figures/SVM.eps')
fig.savefig('results/figures/SVM.pdf')
fig.savefig('results/figures/SVM.png')
return
......@@ -20,3 +20,7 @@ from .set_diff import set_diff
from .folder_structure.create_folder_structure import create_folder_structure
from .folder_structure.create_folder_for_test import create_folder_for_test
from .folder_structure.check_create_folder import check_create_folder
from .datamanagement.import_tests import import_tests
from .datamanagement.read_to_pandas import read_to_pandas
from .datamanagement.test_list import test_list
......@@ -8,5 +8,4 @@ Created on
from .test_list import test_list
from .read_to_pandas import read_to_pandas
from .write import write
from .import_tests import import_tests
\ No newline at end of file
from .import_tests import import_tests
......@@ -6,7 +6,18 @@ Created on 17.01.2021
@author: Feliks Kiszkurno
"""
import slopestabilitytools.datamanagement.test_list
import pandas as pd
def import_tests():
test_results = {}
test_names = slopestabilitytools.datamanagement.test_list('.csv')
#print('test')
#print(test_names)
for test_name in test_names:
test_result_curr = pd.read_csv('results/results/' + test_name + '.csv')
test_results.update({test_name: test_result_curr})
return
return test_results
......@@ -8,6 +8,8 @@ Created on 17.01.2021
import os
# TODO Add more flexibility in the way, that the path is handled
def test_list(extension):
......@@ -19,7 +21,12 @@ def test_list(extension):
for file in file_list:
test_names.append(file[:file.find(extension)])
print(file[:file.find(extension)])
test_names = test_names.sort()
print('start')
print(test_names)
print('end')
test_names = sorted(test_names)
print(test_names)
return test_names
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 17.01.2021
@author: Feliks Kiszkurno
"""
def read_to_pandas():
return
......@@ -8,4 +8,4 @@ Created on 15.01.2021
from .create_folder_for_test import create_folder_for_test
from .create_folder_structure import create_folder_structure
from .check_create_folder import check_create_folder
\ No newline at end of file
from .check_create_folder import check_create_folder
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