lendres 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. lendres-0.1.1/.github/workflows/build-and-publish.yaml +55 -0
  2. lendres-0.1.1/.github/workflows/build-source-dist.yaml +31 -0
  3. lendres-0.1.1/.github/workflows/build-windows-wheel.yaml +36 -0
  4. lendres-0.1.1/.gitignore +141 -0
  5. lendres-0.1.1/Examples/Examples.py +171 -0
  6. lendres-0.1.1/Examples/QuizHelper.py +116 -0
  7. lendres-0.1.1/Examples/psd.py +49 -0
  8. lendres-0.1.1/Installation.txt +14 -0
  9. lendres-0.1.1/License.txt +20 -0
  10. lendres-0.1.1/PKG-INFO +45 -0
  11. lendres-0.1.1/README.md +2 -0
  12. lendres-0.1.1/Testing/Data/Cardiac.csv +890 -0
  13. lendres-0.1.1/Testing/Data/CardioGoodFitness.csv +181 -0
  14. lendres-0.1.1/Testing/Data/Credit Card Customer Data.csv +661 -0
  15. lendres-0.1.1/Testing/Data/Cust_Spend_Data.csv +11 -0
  16. lendres-0.1.1/Testing/Data/Loan_Modelling.csv +5001 -0
  17. lendres-0.1.1/Testing/Data/Tweets.csv +8387 -0
  18. lendres-0.1.1/Testing/Data/backpain.csv +311 -0
  19. lendres-0.1.1/Testing/Data/car-mpg.csv +399 -0
  20. lendres-0.1.1/Testing/Data/credit.csv +1001 -0
  21. lendres-0.1.1/Testing/Data/datawitherrors.csv +1339 -0
  22. lendres-0.1.1/Testing/Data/dynamicsmodel1.csv +60003 -0
  23. lendres-0.1.1/Testing/Data/dynamicsmodel2.csv +6002 -0
  24. lendres-0.1.1/Testing/Data/insurance.csv +1339 -0
  25. lendres-0.1.1/Testing/Data/logo.png +0 -0
  26. lendres-0.1.1/Testing/Data/plant-species-images-reduced.npy +0 -0
  27. lendres-0.1.1/Testing/Data/plant-species-labels-reduced.csv +101 -0
  28. lendres-0.1.1/Testing/Data/preprocessed-tweets-reduced.csv +5000 -0
  29. lendres-0.1.1/Testing/Data/preprocessed-tweets.csv +14641 -0
  30. lendres-0.1.1/Testing/Data/technical_support_data.csv +24 -0
  31. lendres-0.1.1/Testing/Data/used_cars_data.csv +7254 -0
  32. lendres-0.1.1/Testing/DataSetLoading.py +185 -0
  33. lendres-0.1.1/Testing/Library Tests/OpenCVTests.py +35 -0
  34. lendres-0.1.1/Testing/Library Tests/clownfish.jpg +0 -0
  35. lendres-0.1.1/Testing/RunAllColabUnitTestsScript.py +10 -0
  36. lendres-0.1.1/Testing/RunAllUnitTestsScript.py +14 -0
  37. lendres-0.1.1/Testing/UnitTestHelper.py +34 -0
  38. lendres-0.1.1/Testing/testAnnotationHelper.py +84 -0
  39. lendres-0.1.1/Testing/testBivariateAnalysis.py +103 -0
  40. lendres-0.1.1/Testing/testConsoleHelper.py +57 -0
  41. lendres-0.1.1/Testing/testDataComparison.py +89 -0
  42. lendres-0.1.1/Testing/testDataHelper.py +119 -0
  43. lendres-0.1.1/Testing/testDisplayColors.py +64 -0
  44. lendres-0.1.1/Testing/testFile.py +42 -0
  45. lendres-0.1.1/Testing/testFunctionGenerator.py +84 -0
  46. lendres-0.1.1/Testing/testImageHelper.py +42 -0
  47. lendres-0.1.1/Testing/testListTools.py +104 -0
  48. lendres-0.1.1/Testing/testPath.py +67 -0
  49. lendres-0.1.1/Testing/testPlotHelper.py +205 -0
  50. lendres-0.1.1/Testing/testPlotMaker.py +80 -0
  51. lendres-0.1.1/Testing/testSearching.py +84 -0
  52. lendres-0.1.1/Testing/testUnivariateAnalysis.py +39 -0
  53. lendres-0.1.1/Testing/zOrderTest.py +80 -0
  54. lendres-0.1.1/lendres/__init__.py +7 -0
  55. lendres-0.1.1/lendres/algorithms/Search.py +118 -0
  56. lendres-0.1.1/lendres/algorithms/__init__.py +0 -0
  57. lendres-0.1.1/lendres/computervision/ImageDataHelper.py +713 -0
  58. lendres-0.1.1/lendres/computervision/ImageHelper.py +443 -0
  59. lendres-0.1.1/lendres/computervision/__init__.py +0 -0
  60. lendres-0.1.1/lendres/data/BivariateAnalysis.py +508 -0
  61. lendres-0.1.1/lendres/data/DataComparison.py +324 -0
  62. lendres-0.1.1/lendres/data/DataHelper.py +1125 -0
  63. lendres-0.1.1/lendres/data/DataHelperBase.py +298 -0
  64. lendres-0.1.1/lendres/data/UnivariateAnalysis.py +393 -0
  65. lendres-0.1.1/lendres/data/__init__.py +0 -0
  66. lendres-0.1.1/lendres/datatypes/ListTools.py +203 -0
  67. lendres-0.1.1/lendres/datatypes/__init__.py +0 -0
  68. lendres-0.1.1/lendres/demonstration/FunctionGenerator.py +213 -0
  69. lendres-0.1.1/lendres/demonstration/__init__.py +0 -0
  70. lendres-0.1.1/lendres/io/ConsoleHelper.py +528 -0
  71. lendres-0.1.1/lendres/io/IO.py +18 -0
  72. lendres-0.1.1/lendres/io/__init__.py +0 -0
  73. lendres-0.1.1/lendres/mathematics/Precision.py +57 -0
  74. lendres-0.1.1/lendres/mathematics/__init__.py +0 -0
  75. lendres-0.1.1/lendres/modeling/LanguageHelper.py +668 -0
  76. lendres-0.1.1/lendres/path/File.py +167 -0
  77. lendres-0.1.1/lendres/path/Path.py +127 -0
  78. lendres-0.1.1/lendres/path/__init__.py +0 -0
  79. lendres-0.1.1/lendres/plotting/AnnotationHelper.py +197 -0
  80. lendres-0.1.1/lendres/plotting/AxesHelper.py +450 -0
  81. lendres-0.1.1/lendres/plotting/DisplayColors.py +130 -0
  82. lendres-0.1.1/lendres/plotting/FormatSettings.py +153 -0
  83. lendres-0.1.1/lendres/plotting/LegendHelper.py +45 -0
  84. lendres-0.1.1/lendres/plotting/LegendOptions.py +56 -0
  85. lendres-0.1.1/lendres/plotting/PlotHelper.py +948 -0
  86. lendres-0.1.1/lendres/plotting/PlotMaker.py +474 -0
  87. lendres-0.1.1/lendres/plotting/__init__.py +4 -0
  88. lendres-0.1.1/lendres/plotting/artistic.mplstyle +28 -0
  89. lendres-0.1.1/lendres/plotting/default.mplstyle +27 -0
  90. lendres-0.1.1/lendres/plotting/gridless.mplstyle +28 -0
  91. lendres-0.1.1/lendres/plotting/imagedefault.mplstyle +38 -0
  92. lendres-0.1.1/lendres/plotting/lightweightlines.mplstyle +27 -0
  93. lendres-0.1.1/lendres/plotting/manim.mplstyle +39 -0
  94. lendres-0.1.1/lendres/plotting/mediumsizefont.mplstyle +27 -0
  95. lendres-0.1.1/lendres/plotting/seaborn.mplstyle +52 -0
  96. lendres-0.1.1/lendres/plotting/transparentlegend.mplstyle +27 -0
  97. lendres-0.1.1/lendres/signalprocessing/SignalProcessing.py +70 -0
  98. lendres-0.1.1/lendres/utilities/PrintExecutable.py +7 -0
  99. lendres-0.1.1/lendres/utilities/__init__.py +0 -0
  100. lendres-0.1.1/lendres.egg-info/PKG-INFO +45 -0
  101. lendres-0.1.1/lendres.egg-info/SOURCES.txt +105 -0
  102. lendres-0.1.1/lendres.egg-info/dependency_links.txt +1 -0
  103. lendres-0.1.1/lendres.egg-info/requires.txt +14 -0
  104. lendres-0.1.1/lendres.egg-info/top_level.txt +1 -0
  105. lendres-0.1.1/pyproject.toml +24 -0
  106. lendres-0.1.1/requirements.txt +14 -0
  107. lendres-0.1.1/setup.cfg +4 -0
@@ -0,0 +1,55 @@
1
+ name: build-and-publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+
9
+ build-windows-python312:
10
+
11
+ uses: ./.github/workflows/build-windows-wheel.yaml
12
+ with:
13
+ python_version: 3.12
14
+
15
+ build-source-dist:
16
+
17
+ uses: ./.github/workflows/build-source-dist.yaml
18
+
19
+ publish-release:
20
+
21
+ needs: [build-source-dist, build-windows-python312]
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ contents: write
25
+ steps:
26
+
27
+ - name: Get Wheels
28
+ uses: actions/download-artifact@v4
29
+ with:
30
+ pattern: file-*
31
+ path: "./dist"
32
+ merge-multiple: true
33
+
34
+ - name: Upload Wheels to Release
35
+ env:
36
+ GH_TOKEN: ${{ github.token }}
37
+ run: gh release upload "${{ github.event.release.tag_name }}" "./dist/"** --repo ${{ github.repository }}
38
+
39
+ publish-pypi:
40
+
41
+ needs: [build-source-dist, build-windows-python312]
42
+ runs-on: ubuntu-latest
43
+ permissions:
44
+ id-token: write
45
+ steps:
46
+
47
+ - name: Get Wheels
48
+ uses: actions/download-artifact@v4
49
+ with:
50
+ pattern: file-*
51
+ path: "./dist"
52
+ merge-multiple: true
53
+
54
+ - name: Publish to PyPI
55
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,31 @@
1
+ name: build-source-dist
2
+
3
+ on:
4
+ workflow_call
5
+
6
+ jobs:
7
+
8
+ build:
9
+
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+
13
+ - name: Checkout Repository
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Install Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: 3.12
20
+
21
+ - name: Update Python
22
+ run: python -m pip install --upgrade pip build
23
+
24
+ - name: Build Source Distribution
25
+ run: python -m build --sdist --outdir "./dist"
26
+
27
+ - name: Store Source Distribution
28
+ uses: actions/upload-artifact@v4
29
+ with:
30
+ name: file-source-dist
31
+ path: "./dist"
@@ -0,0 +1,36 @@
1
+ name: build-windows-wheel
2
+
3
+ on:
4
+ workflow_call:
5
+ inputs:
6
+
7
+ python_version:
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+
13
+ build:
14
+
15
+ runs-on: windows-latest
16
+ steps:
17
+
18
+ - name: Checkout Repository
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Install Python
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ inputs.python_version }}
25
+
26
+ - name: Update Python
27
+ run: python -m pip install --upgrade pip setuptools wheel
28
+
29
+ - name: Build Wheel
30
+ run: python -m pip wheel --no-deps --wheel-dir "./dist" "."
31
+
32
+ - name: Store Wheel
33
+ uses: actions/upload-artifact@v4
34
+ with:
35
+ name: file-${{ inputs.python_version }}
36
+ path: "./dist"
@@ -0,0 +1,141 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+ lendres/plotting/Matplotlib Colors - BASE - Names.png
131
+ lendres/plotting/Matplotlib Colors - CSS - Names.png
132
+ lendres/plotting/Matplotlib Colors - TABLEAU - Names.png
133
+ lendres/plotting/Matplotlib Colors - XKCD - Names.png
134
+ lendres/plotting/Matplotlib Colors - BASE - Hex.png
135
+ lendres/plotting/Matplotlib Colors - CSS - Hex.png
136
+ lendres/plotting/Matplotlib Colors - FULL - Hex.png
137
+ lendres/plotting/Matplotlib Colors - FULL - Names.png
138
+ lendres/plotting/Matplotlib Colors - SEABORN - Hex.png
139
+ lendres/plotting/Matplotlib Colors - SEABORN - Names.png
140
+ lendres/plotting/Matplotlib Colors - TABLEAU - Hex.png
141
+ lendres/plotting/Matplotlib Colors - XKCD - Hex.png
@@ -0,0 +1,171 @@
1
+ """
2
+ Created on July 31, 2022
3
+ @author: Lance A. Endres
4
+ """
5
+
6
+ """
7
+ Miscellaneous Python examples.
8
+ """
9
+
10
+ import math
11
+ import os
12
+ import random
13
+ import re
14
+ import sys
15
+
16
+
17
+ def CountNumberOfPairs(n, ar):
18
+ # Get unique values. Convert to list because set doesn't have a count function.# Get unique values.
19
+ colors = list(set(ar))
20
+ print("\nColors:")
21
+ print(colors)
22
+
23
+ # Count the number of times each value appears in the input.
24
+ counts = [ar.count(i) for i in colors]
25
+ print("\nCounts")
26
+ print(counts)
27
+
28
+ # Calculate the number of pairs of each type.
29
+ pairs = [math.floor(i/2.0) for i in counts]
30
+ print("\nPairs:")
31
+ print(pairs)
32
+
33
+ # Total number of pairs in the input.
34
+ result = sum(pairs)
35
+ print("Result:", result)
36
+ return result
37
+
38
+
39
+ def CountingValleys(steps, path):
40
+ elevation = 0
41
+ valleyCount = 0
42
+ inValley = False
43
+
44
+ for i in range(steps):
45
+ # Track our current elevation.
46
+ if path[i] == "U":
47
+ elevation += 1
48
+ else:
49
+ elevation -= 1
50
+ print("\nElevation:", elevation)
51
+
52
+ # Valleys must be below sea level.
53
+ # The problem statement is poorly worded (no suprise for HackerRank).
54
+ # What they intend to mean is a valley is any sequence of steps that
55
+ # start with a step down from sea level and end with a step up to sea level.
56
+ # The way the question is worded ("consecutive steps below sea level") could
57
+ # be interpretued to mean you need multiple steps below sea level. At which
58
+ # point you need to define the elevation of a step as a step starts at one
59
+ # elevation and ends at another.
60
+ if elevation < 0:
61
+ inValley = True
62
+ print("In valley")
63
+
64
+ # This catches when we were below sea leven and return to sea level.
65
+ if elevation == 0 and inValley:
66
+ valleyCount += 1
67
+ inValley = False
68
+
69
+ return valleyCount
70
+
71
+
72
+ def OrganizingContainers(container):
73
+ # Sums and sorts rows.
74
+ r = sorted([sum(x) for x in container])
75
+
76
+ # Sums and sorts columns.
77
+ c = sorted([sum(x) for x in zip(*container)])
78
+ return "Possible" if r == c else "Impossible"
79
+ # So in order to explain that, you have to understand the zip() function itself. If zip()
80
+ # was to be given two or more arrays as arguments, it would create one multi-dimensional
81
+ # array by grouping up the values of the given arrays by their indices. When paired with
82
+ # the zip() function, the "*" operator instead allows you to invert the operation and "unzip"
83
+ # a multi-dimensional array into the component arrays it would have taken in a hypothetical
84
+ # initial "zip()" argument. In this case, you break the container down into smaller arrays of
85
+ # its components that previously shared the same column. So the R operation line takes the
86
+ # sums of the rows, and the C operation line takes the sums of the columns.
87
+
88
+
89
+
90
+ def BomberMan(r, c, n, gridString):
91
+ time = 1
92
+ bombTimes = [[0]*c for i in range(r)]
93
+
94
+ # Grid string is an array of strings like:
95
+ # ["xoox", "xxox", "oxxo", "xoxo"]
96
+ # This converts it to a list of lists (the strings are parsed by each character).
97
+ grid = [list(x) for x in gridString]
98
+
99
+ printDebug = 0
100
+ if printDebug:
101
+ #print("\nInitial grid:", gridString)
102
+ #print("\nConverted grid:", grid)
103
+ #print("\nBomb times initial:", bombTimes)
104
+ print("\nTotal time:", n)
105
+
106
+ finalTime = n if n < 4 else 4 + n % 4
107
+
108
+ while time < finalTime:
109
+ # First second do nothing.
110
+ # Second second plant bombs
111
+ time += 1
112
+ if time % 2 == 0:
113
+ PlantBombs(r, c, n, grid, time, bombTimes, printDebug)
114
+ else:
115
+ ExplodeBombs(r, c, n, grid, time, bombTimes, printDebug)
116
+
117
+ newGrid = JoinStrings(grid)
118
+ #if printDebug:
119
+ # print("\nNew grid:", newGrid)
120
+ return newGrid
121
+
122
+
123
+ def PlantBombs(r, c, n, grid, time, bombTimes, printDebug):
124
+ #DisplayGrid("Before planting bombs", grid, printDebug)
125
+ for i in range(r):
126
+ for j in range(c):
127
+ if grid[i][j] == ".":
128
+ grid[i][j] = "O"
129
+ bombTimes[i][j] = time
130
+
131
+ #DisplayGrid("After planting bombs", grid, printDebug)
132
+ #if printDebug:
133
+ # print("Times:", bombTimes)
134
+
135
+
136
+ def ExplodeBombs(r, c, n, grid, time, bombTimes, printDebug):
137
+ #DisplayGrid("Before exploding bombs", grid, printDebug)
138
+ explodeTime = time - 3
139
+ for i in range(r):
140
+ for j in range(c):
141
+ if bombTimes[i][j] == explodeTime:
142
+ grid[i][j] = "."
143
+ if i-1 >= 0:
144
+ grid[i-1][j] = "."
145
+ if i+1 < r:
146
+ grid[i+1][j] = "."
147
+ if j-1 >= 0:
148
+ grid[i][j-1] = "."
149
+ if j+1 < c:
150
+ grid[i][j+1] = "."
151
+ #DisplayGrid("After exploding bombs", grid, printDebug)
152
+
153
+
154
+ def JoinStrings(grid):
155
+ return ["".join(string) for string in grid]
156
+
157
+
158
+ def DisplayGrid(label, grid, printDebug):
159
+ if printDebug:
160
+ print("\n"+label+":")
161
+ joinedGrid = JoinStrings(grid)
162
+ print('\n'.join(joinedGrid))
163
+
164
+
165
+ def BirthdayCakeCandles(candles):
166
+ maxValue = max(candles)
167
+ numberOfMax = candles.count(maxValue)
168
+
169
+ print("Candles:", candles)
170
+ print("numberOfMax:", numberOfMax)
171
+ return numberOfMax
@@ -0,0 +1,116 @@
1
+ """
2
+ Created on April 9, 2022
3
+ @author: Lance A. Endres
4
+ """
5
+ # To help with reading and manipulation of data.
6
+ import numpy as np
7
+ import pandas as pd
8
+
9
+ # To help with data visualization.
10
+ import matplotlib.pyplot as plt
11
+ import seaborn as sns
12
+
13
+
14
+ from lendres.plotting.PlotHelper import PlotHelper
15
+ from lendres.plotting.AxesHelper import AxesHelper
16
+
17
+ # To get different performance metrics.
18
+ import sklearn.metrics as metrics
19
+ from sklearn.metrics import (
20
+ classification_report,
21
+ confusion_matrix,
22
+ recall_score,
23
+ accuracy_score,
24
+ precision_score,
25
+ f1_score
26
+ )
27
+
28
+
29
+ # defining a function to compute different metrics to check performance of a classification model built using sklearn
30
+ def model_performance_classification_sklearn(model, predictors, target):
31
+ """
32
+ Function to compute different metrics to check classification model performance
33
+
34
+ model: classifier
35
+ predictors: independent variables
36
+ target: dependent variable
37
+ """
38
+
39
+ # predicting using the independent variables
40
+ pred = model.predict(predictors)
41
+
42
+ accuracy = accuracy_score(target, pred)
43
+ recall = recall_score(target, pred)
44
+ precision = precision_score(target, pred)
45
+ f1 = f1_score(target, pred)
46
+
47
+ # creating a dataframe of metrics
48
+ df_perf = pd.DataFrame(
49
+ {
50
+ "Accuracy" : accuracy,
51
+ "Recall" : recall,
52
+ "Precision" : precision,
53
+ "F1" : f1,
54
+ },
55
+ index=[0],
56
+ )
57
+
58
+ return df_perf
59
+
60
+
61
+ def model_performance_classification(trueValues, predictedValues):
62
+ """
63
+ Function to compute different metrics to check classification model performance. Uses
64
+ the true (specified) and predicted values as input.
65
+
66
+ trueValues: independent variable true values
67
+ predictedValues: independent variable predicted values
68
+ """
69
+ accuracy = accuracy_score(trueValues, predictedValues)
70
+ recall = recall_score(trueValues, predictedValues)
71
+ precision = precision_score(trueValues, predictedValues)
72
+ f1 = f1_score(trueValues, predictedValues)
73
+
74
+ # creating a dataframe of metrics
75
+ performanceDataFrame = pd.DataFrame(
76
+ {
77
+ "Accuracy" : accuracy,
78
+ "Recall" : recall,
79
+ "Precision" : precision,
80
+ "F1" : f1,
81
+ },
82
+ index=[0],
83
+ )
84
+
85
+ return performanceDataFrame
86
+
87
+
88
+ def confusion_matrix_sklearn(model, predictors, target, titleSuffix=None):
89
+ """
90
+ To plot the confusion_matrix with percentages
91
+
92
+ model: classifier
93
+ predictors: independent variables
94
+ target: dependent variable
95
+ """
96
+ y_pred = model.predict(predictors)
97
+ cm = confusion_matrix(target, y_pred)
98
+
99
+ labels = np.asarray(
100
+ [
101
+ ["{0:0.0f}".format(item) + "\n{0:.2%}".format(item / cm.flatten().sum())]
102
+ for item in cm.flatten()
103
+ ]
104
+ ).astype("object").reshape(2, 2)
105
+
106
+ # Tack on the type labels to the numerical information.
107
+ labels[0, 0] += "\nTN"
108
+ labels[1, 0] += "\nFN\nType 2"
109
+ labels[0, 1] += "\nFP\nType 1"
110
+ labels[1, 1] += "\nTP"
111
+
112
+ PlotHelper.Format(width=5.35, height=4)
113
+ #plt.figure(figsize=(6, 4))
114
+ axis = sns.heatmap(cm, annot=labels, annot_kws={"fontsize" : 14*PlotHelper.formatSettings.Scale}, fmt="")
115
+ AxesHelper.Label(axis, title="Data", xLabels="Predicted", yLabel="Actual", titleSuffix=titleSuffix)
116
+ plt.show()
@@ -0,0 +1,49 @@
1
+ """
2
+ Created on March 23, 2024
3
+ @author: Lance Endres
4
+ """
5
+ import numpy as np
6
+ from matplotlib import pyplot as plt
7
+ from scipy import signal
8
+
9
+ np.random.seed(0)
10
+
11
+ time_step = .01
12
+ time_vec = np.arange(0, 70, time_step)
13
+
14
+ # A signal with a small frequency chirp
15
+ vals = 0.5 * np.pi * time_vec * (1 + .1 * time_vec)
16
+ print("Values Type:", type(vals))
17
+ print("Values Length:", len(vals))
18
+ print("Values Shape:", vals.shape)
19
+
20
+ sig = np.sin(vals)
21
+
22
+ print("Signal Type:", type(sig))
23
+ print("Signal Length:", len(sig))
24
+ print("Signal Shape:", sig.shape)
25
+
26
+ plt.figure(figsize=(8, 5))
27
+ plt.plot(time_vec, sig)
28
+
29
+
30
+
31
+ freqs, times, spectrogram = signal.spectrogram(sig, fs=1.0/time_step)
32
+
33
+ plt.figure(figsize=(5, 4))
34
+ plt.imshow(spectrogram, aspect='auto', cmap='hot_r', origin='lower')
35
+ plt.title('Spectrogram')
36
+ plt.ylabel('Frequency band')
37
+ plt.xlabel('Time window')
38
+ plt.tight_layout()
39
+
40
+
41
+
42
+ freqs, psd = signal.welch(sig)
43
+
44
+ plt.figure(figsize=(5, 4))
45
+ plt.semilogx(freqs, psd)
46
+ plt.title('PSD: power spectral density')
47
+ plt.xlabel('Frequency')
48
+ plt.ylabel('Power')
49
+ plt.tight_layout()
@@ -0,0 +1,14 @@
1
+ WINDOWS MACHINES
2
+
3
+ Add the environmental variable:
4
+ PYTHONPATH
5
+ C:\Custom Program Files\Python
6
+
7
+
8
+ VISUAL STUDIO CODE
9
+
10
+ To prevent "importing the numpy c-extensions failed":
11
+ - Open VS Code's Command Palette menu by pressing Ctrl+Shift+P or F1
12
+ - Choose "Terminal: Select Default Profile"
13
+ - Then pick "Command Prompt" option
14
+ - Restart VS Code
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021-2024 Lance A. Endres
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lendres-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.1
2
+ Name: lendres
3
+ Version: 0.1.1
4
+ Summary: A collection of general Python utilities from Lance A. Endres.
5
+ License: Copyright (c) 2021-2024 Lance A. Endres
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ Project-URL: homepage, https://github.com/lendres/Python
27
+ Requires-Python: >=3.11.0
28
+ Description-Content-Type: text/markdown
29
+ Requires-Dist: adjustText==1.2.0
30
+ Requires-Dist: beautifulsoup4==4.12.3
31
+ Requires-Dist: contractions==0.1.73
32
+ Requires-Dist: ipython==8.12.3
33
+ Requires-Dist: matplotlib==3.9.0
34
+ Requires-Dist: nltk==3.8.1
35
+ Requires-Dist: numpy==1.26.4
36
+ Requires-Dist: pandas==2.2.2
37
+ Requires-Dist: Pillow==10.4.0
38
+ Requires-Dist: scikit_learn==1.5.1
39
+ Requires-Dist: scipy==1.13.1
40
+ Requires-Dist: seaborn==0.13.2
41
+ Requires-Dist: spacy==3.7.5
42
+ Requires-Dist: wordcloud==1.9.3
43
+
44
+ # Python Library
45
+ A collection of general Python utilities from Lance A. Endres.
@@ -0,0 +1,2 @@
1
+ # Python Library
2
+ A collection of general Python utilities from Lance A. Endres.