From a51f1f134d0442e40dac5ce122f5ff31c6201919 Mon Sep 17 00:00:00 2001 From: ltcptgeneral <35508619+ltcptgeneral@users.noreply.github.com> Date: Wed, 6 Nov 2019 15:26:13 -0600 Subject: [PATCH] analysis.py v 1.1.9.000 --- data analysis/analysis/analysis.py | 66 +++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/data analysis/analysis/analysis.py b/data analysis/analysis/analysis.py index b784f6f2..96116e45 100644 --- a/data analysis/analysis/analysis.py +++ b/data analysis/analysis/analysis.py @@ -7,10 +7,13 @@ # current benchmark of optimization: 1.33 times faster # setup: -__version__ = "1.1.8.000" +__version__ = "1.1.9.000" # changelog should be viewed using print(analysis.__changelog__) __changelog__ = """changelog: + 1.1.9.000: + - added SVM class, subclasses, and functions + - note: untested 1.1.8.000: - added NaiveBayes classification engine - note: untested @@ -471,6 +474,67 @@ class NaiveBayes: return model, cm, cr +class SVM: + + class CustomKernel: + + def __init__(self, C, kernel, degre, gamma, coef0, shrinking, probability, tol, cache_size, class_weight, verbose, max_iter, decision_function_shape, random_state): + + return sklearn.svm.SVC(C = C, kernel = kernel, gamma = gamma, coef0 = coef0, shrinking + shrinking, probability = probability, tol = tol, cache_size = cache_size, class_weight = class_weight, verbose = verbose, max_iter = max_iter, decision_function_shape = decision_function_shape, random_state = random_state) + + class StandardKernel: + + def __init__(self, kernel, C=1.0, degree=3, gamma='auto_deprecated', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape='ovr', random_state=None): + + return sklearn.svm.SVC(C = C, kernel = kernel, gamma = gamma, coef0 = coef0, shrinking + shrinking, probability = probability, tol = tol, cache_size = cache_size, class_weight = class_weight, verbose = verbose, max_iter = max_iter, decision_function_shape = decision_function_shape, random_state = random_state) + + class PrebuiltKernel: + + class Linear: + + def __init__(self): + + return sklearn.svm.SVC(kernel = 'linear') + + class Polynomial: + + def __init__(self, power, r_bias): + + return sklearn.svm.SVC(kernel = 'polynomial', degree = power, coef0 = r_bias) + + class RBF: + + def __init__(self, gamma): + + return sklearn.svm.SVC(kernel = 'rbf', gamma = gamma) + + class Sigmoid: + + def __init__(self, r_bias): + + return sklearn.svm.SVC(kernel = 'sigmoid', coef0 = r_bias) + + def fit(self, kernel, train_data, train_outputs): # expects *2d data, 1d labels or outputs + + return kernel.fit(train_data, train_outputs) + + def eval_classification(self, kernel, test_data, test_outputs): + + predictions = kernel.predict(test_data) + cm = sklearn.metrics.confusion_matrix(labels_test, predictions) + cr = sklearn.metrics.classification_report(labels_test, predictions) + + return cm, cr + + def eval_regression(self, kernel, test_data, test_outputs): + + predictions = kernel.predict(test_data) + r_2 = r_squared(predictions, test_outputs) + mse = mse(predictions, test_outputs) + rms = rms(predictions, test_outputs) + + return r_2, mse, rms + class Regression: # Titan Robotics Team 2022: CUDA-based Regressions Module