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