From 5d5d6c4c5ef8c4053dadde18ad48f5fd248f0652 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 9 Nov 2021 22:52:04 +0000 Subject: [PATCH] fixed/optimized imports, fixed headers Signed-off-by: Arthur Lu --- analysis-master/tra_analysis/Analysis.py | 24 ++++--------------- .../tra_analysis/ClassificationMetric.py | 5 ++-- .../tra_analysis/CorrelationTest.py | 5 ++-- analysis-master/tra_analysis/KNN.py | 5 ++-- analysis-master/tra_analysis/NaiveBayes.py | 7 +++--- analysis-master/tra_analysis/RandomForest.py | 7 +++--- .../tra_analysis/RegressionMetric.py | 5 ++-- analysis-master/tra_analysis/SVM.py | 5 ++-- analysis-master/tra_analysis/Sort.py | 2 +- .../tra_analysis/StatisticalTest.py | 9 +++---- analysis-master/tra_analysis/__init__.py | 3 +++ 11 files changed, 37 insertions(+), 40 deletions(-) diff --git a/analysis-master/tra_analysis/Analysis.py b/analysis-master/tra_analysis/Analysis.py index df81951c..e736ec62 100644 --- a/analysis-master/tra_analysis/Analysis.py +++ b/analysis-master/tra_analysis/Analysis.py @@ -7,10 +7,13 @@ # current benchmark of optimization: 1.33 times faster # setup: -__version__ = "3.0.4" +__version__ = "3.0.5" # changelog should be viewed using print(analysis.__changelog__) __changelog__ = """changelog: + 3.0.5: + - removed extra submodule imports + - fixed/optimized header 3.0.4: - removed -_obj imports 3.0.3: @@ -361,7 +364,6 @@ __all__ = [ 'histo_analysis', 'regression', 'Metric', - 'kmeans', 'pca', 'decisiontree', # all statistics functions left out due to integration in other functions @@ -374,21 +376,14 @@ __all__ = [ import csv from tra_analysis.metrics import elo as Elo from tra_analysis.metrics import glicko2 as Glicko2 -import math import numpy as np import scipy -from scipy import optimize, stats -import sklearn -from sklearn import preprocessing, pipeline, linear_model, metrics, cluster, decomposition, tree, neighbors, naive_bayes, svm, model_selection, ensemble +import sklearn, sklearn.cluster from tra_analysis.metrics import trueskill as Trueskill -import warnings # import submodules -from .Array import Array from .ClassificationMetric import ClassificationMetric -from .RegressionMetric import RegressionMetric -from . import SVM class error(ValueError): pass @@ -599,16 +594,7 @@ def npmin(data): def npmax(data): return np.amax(data) -""" need to decide what to do with this function -def kmeans(data, n_clusters=8, init="k-means++", n_init=10, max_iter=300, tol=0.0001, precompute_distances="auto", verbose=0, random_state=None, copy_x=True, n_jobs=None, algorithm="auto"): - kernel = sklearn.cluster.KMeans(n_clusters = n_clusters, init = init, n_init = n_init, max_iter = max_iter, tol = tol, precompute_distances = precompute_distances, verbose = verbose, random_state = random_state, copy_x = copy_x, n_jobs = n_jobs, algorithm = algorithm) - kernel.fit(data) - predictions = kernel.predict(data) - centers = kernel.cluster_centers_ - - return centers, predictions -""" def pca(data, n_components = None, copy = True, whiten = False, svd_solver = "auto", tol = 0.0, iterated_power = "auto", random_state = None): kernel = sklearn.decomposition.PCA(n_components = n_components, copy = copy, whiten = whiten, svd_solver = svd_solver, tol = tol, iterated_power = iterated_power, random_state = random_state) diff --git a/analysis-master/tra_analysis/ClassificationMetric.py b/analysis-master/tra_analysis/ClassificationMetric.py index a1afcf25..6dc2ff31 100644 --- a/analysis-master/tra_analysis/ClassificationMetric.py +++ b/analysis-master/tra_analysis/ClassificationMetric.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import ClassificationMetric' # setup: -__version__ = "1.0.1" +__version__ = "1.0.2" __changelog__ = """changelog: + 1.0.2: + - optimized imports 1.0.1: - fixed __all__ 1.0.0: @@ -22,7 +24,6 @@ __all__ = [ ] import sklearn -from sklearn import metrics class ClassificationMetric(): diff --git a/analysis-master/tra_analysis/CorrelationTest.py b/analysis-master/tra_analysis/CorrelationTest.py index bc35ce92..ddb27939 100644 --- a/analysis-master/tra_analysis/CorrelationTest.py +++ b/analysis-master/tra_analysis/CorrelationTest.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import CorrelationTest' # setup: -__version__ = "1.0.1" +__version__ = "1.0.2" __changelog__ = """changelog: + 1.0.2: + - optimized imports 1.0.1: - fixed __all__ 1.0.0: @@ -29,7 +31,6 @@ __all__ = [ ] import scipy -from scipy import stats def anova_oneway(*args): #expects arrays of samples diff --git a/analysis-master/tra_analysis/KNN.py b/analysis-master/tra_analysis/KNN.py index d594c72f..09d663f3 100644 --- a/analysis-master/tra_analysis/KNN.py +++ b/analysis-master/tra_analysis/KNN.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import KNN' # setup: -__version__ = "1.0.0" +__version__ = "1.0.1" __changelog__ = """changelog: + 1.0.1: + - optimized imports 1.0.0: - ported analysis.KNN() here - removed classness @@ -23,7 +25,6 @@ __all__ = [ ] import sklearn -from sklearn import model_selection, neighbors from . import ClassificationMetric, RegressionMetric def knn_classifier(data, labels, n_neighbors = 5, test_size = 0.3, algorithm='auto', leaf_size=30, metric='minkowski', metric_params=None, n_jobs=None, p=2, weights='uniform'): #expects *2d data and 1d labels post-scaling diff --git a/analysis-master/tra_analysis/NaiveBayes.py b/analysis-master/tra_analysis/NaiveBayes.py index f6b68f1e..007d3e6e 100644 --- a/analysis-master/tra_analysis/NaiveBayes.py +++ b/analysis-master/tra_analysis/NaiveBayes.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import NaiveBayes' # setup: -__version__ = "1.0.0" +__version__ = "1.0.1" __changelog__ = """changelog: + 1.0.1: + - optimized imports 1.0.0: - ported analysis.NaiveBayes() here - removed classness @@ -24,8 +26,7 @@ __all__ = [ ] import sklearn -from sklearn import model_selection, naive_bayes -from . import ClassificationMetric, RegressionMetric +from . import ClassificationMetric def gaussian(data, labels, test_size = 0.3, priors = None, var_smoothing = 1e-09): diff --git a/analysis-master/tra_analysis/RandomForest.py b/analysis-master/tra_analysis/RandomForest.py index 44bee009..02afe73c 100644 --- a/analysis-master/tra_analysis/RandomForest.py +++ b/analysis-master/tra_analysis/RandomForest.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import RandomForest' # setup: -__version__ = "1.0.1" +__version__ = "1.0.2" __changelog__ = """changelog: + 1.0.2: + - optimized imports 1.0.1: - fixed __all__ 1.0.0: @@ -23,8 +25,7 @@ __all__ = [ "random_forest_regressor", ] -import sklearn -from sklearn import ensemble, model_selection +import sklearn, sklearn.ensemble, sklearn.naive_bayes from . import ClassificationMetric, RegressionMetric def random_forest_classifier(data, labels, test_size, n_estimators, criterion="gini", max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features="auto", max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, class_weight=None): diff --git a/analysis-master/tra_analysis/RegressionMetric.py b/analysis-master/tra_analysis/RegressionMetric.py index 0b985493..e71689d4 100644 --- a/analysis-master/tra_analysis/RegressionMetric.py +++ b/analysis-master/tra_analysis/RegressionMetric.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import RegressionMetric' # setup: -__version__ = "1.0.0" +__version__ = "1.0.1" __changelog__ = """changelog: + 1.0.1: + - optimized imports 1.0.0: - ported analysis.RegressionMetric() here """ @@ -21,7 +23,6 @@ __all__ = [ import numpy as np import sklearn -from sklearn import metrics class RegressionMetric(): diff --git a/analysis-master/tra_analysis/SVM.py b/analysis-master/tra_analysis/SVM.py index acf189f3..02b86138 100644 --- a/analysis-master/tra_analysis/SVM.py +++ b/analysis-master/tra_analysis/SVM.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import SVM' # setup: -__version__ = "1.0.2" +__version__ = "1.0.3" __changelog__ = """changelog: + 1.0.3: + - optimized imports 1.0.2: - fixed __all__ 1.0.1: @@ -30,7 +32,6 @@ __all__ = [ ] import sklearn -from sklearn import svm from . import ClassificationMetric, RegressionMetric class CustomKernel: diff --git a/analysis-master/tra_analysis/Sort.py b/analysis-master/tra_analysis/Sort.py index 63dc3677..90ba6409 100644 --- a/analysis-master/tra_analysis/Sort.py +++ b/analysis-master/tra_analysis/Sort.py @@ -16,7 +16,7 @@ __changelog__ = """changelog: __author__ = ( "Arthur Lu ", - "James Pan " + "James Pan ", ) __all__ = [ diff --git a/analysis-master/tra_analysis/StatisticalTest.py b/analysis-master/tra_analysis/StatisticalTest.py index 44fa3a07..e07649e9 100644 --- a/analysis-master/tra_analysis/StatisticalTest.py +++ b/analysis-master/tra_analysis/StatisticalTest.py @@ -4,9 +4,11 @@ # this should be imported as a python module using 'from tra_analysis import StatisticalTest' # setup: -__version__ = "1.0.2" +__version__ = "1.0.3" __changelog__ = """changelog: + 1.0.3: + - optimized imports 1.0.2: - added tukey_multicomparison - fixed styling @@ -61,7 +63,6 @@ __all__ = [ import numpy as np import scipy -from scipy import stats, interpolate def ttest_onesample(a, popmean, axis = 0, nan_policy = 'propagate'): @@ -279,9 +280,9 @@ def get_tukeyQcrit(k, df, alpha=0.05): cv001 = c[:, 2::2] if alpha == 0.05: - intp = interpolate.interp1d(crows, cv005[:,k-2]) + intp = scipy.interpolate.interp1d(crows, cv005[:,k-2]) elif alpha == 0.01: - intp = interpolate.interp1d(crows, cv001[:,k-2]) + intp = scipy.interpolate.interp1d(crows, cv001[:,k-2]) else: raise ValueError('only implemented for alpha equal to 0.01 and 0.05') return intp(df) diff --git a/analysis-master/tra_analysis/__init__.py b/analysis-master/tra_analysis/__init__.py index 0f170bdd..d74c1c9d 100644 --- a/analysis-master/tra_analysis/__init__.py +++ b/analysis-master/tra_analysis/__init__.py @@ -16,6 +16,8 @@ __changelog__ = """changelog: - deprecated titanlearn.py - deprecated visualization.py - removed matplotlib from requirements + - removed extra submodule imports in Analysis + - added typehinting, docstrings for each function 3.0.0: - incremented version to release 3.0.0 3.0.0-rc2: @@ -45,6 +47,7 @@ __all__ = [ "Analysis", "Array", "ClassificationMetric", + "Clustering", "CorrelationTest", "Expression", "Fit",