analysistoolbox 3.2.2__tar.gz → 3.9.9__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 (188) hide show
  1. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/PKG-INFO +75 -4
  2. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/README.md +74 -3
  3. analysistoolbox-3.9.9/analysistoolbox/calculus/FindDerivative.py +111 -0
  4. analysistoolbox-3.9.9/analysistoolbox/calculus/FindLimitOfFunction.py +123 -0
  5. analysistoolbox-3.9.9/analysistoolbox/calculus/FindMinimumSquareLoss.py +106 -0
  6. analysistoolbox-3.9.9/analysistoolbox/calculus/PlotFunction.py +227 -0
  7. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/data_collection/ExtractTextFromPDF.py +54 -7
  8. analysistoolbox-3.9.9/analysistoolbox/data_collection/FetchPDFFromURL.py +71 -0
  9. analysistoolbox-3.9.9/analysistoolbox/data_collection/FetchUSShapefile.py +128 -0
  10. analysistoolbox-3.9.9/analysistoolbox/data_collection/FetchWebsiteText.py +100 -0
  11. analysistoolbox-3.9.9/analysistoolbox/data_collection/GetCompanyFilings.py +180 -0
  12. analysistoolbox-3.9.9/analysistoolbox/data_collection/GetGoogleSearchResults.py +140 -0
  13. analysistoolbox-3.9.9/analysistoolbox/data_collection/GetZipFile.py +93 -0
  14. analysistoolbox-3.9.9/analysistoolbox/data_processing/AddDateNumberColumns.py +98 -0
  15. analysistoolbox-3.9.9/analysistoolbox/data_processing/AddLeadingZeros.py +112 -0
  16. analysistoolbox-3.9.9/analysistoolbox/data_processing/AddRowCountColumn.py +142 -0
  17. analysistoolbox-3.9.9/analysistoolbox/data_processing/AddTPeriodColumn.py +130 -0
  18. analysistoolbox-3.9.9/analysistoolbox/data_processing/AddTukeyOutlierColumn.py +316 -0
  19. analysistoolbox-3.9.9/analysistoolbox/data_processing/CleanTextColumns.py +89 -0
  20. analysistoolbox-3.9.9/analysistoolbox/data_processing/ConductAnomalyDetection.py +197 -0
  21. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/data_processing/ConductEntityMatching.py +137 -14
  22. analysistoolbox-3.9.9/analysistoolbox/data_processing/ConvertOddsToProbability.py +92 -0
  23. analysistoolbox-3.9.9/analysistoolbox/data_processing/CountMissingDataByGroup.py +98 -0
  24. analysistoolbox-3.9.9/analysistoolbox/data_processing/CreateBinnedColumn.py +134 -0
  25. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/data_processing/CreateDataOverview.py +70 -7
  26. analysistoolbox-3.9.9/analysistoolbox/data_processing/CreateRandomSampleGroups.py +79 -0
  27. analysistoolbox-3.9.9/analysistoolbox/data_processing/CreateRareCategoryColumn.py +112 -0
  28. analysistoolbox-3.9.9/analysistoolbox/data_processing/CreateStratifiedRandomSampleGroups.py +105 -0
  29. analysistoolbox-3.9.9/analysistoolbox/data_processing/GeocodeUSAddresses.py +102 -0
  30. analysistoolbox-3.9.9/analysistoolbox/data_processing/ImputeMissingValuesUsingNearestNeighbors.py +113 -0
  31. analysistoolbox-3.9.9/analysistoolbox/data_processing/VerifyGranularity.py +121 -0
  32. analysistoolbox-3.9.9/analysistoolbox/descriptive_analytics/ConductManifoldLearning.py +161 -0
  33. analysistoolbox-3.9.9/analysistoolbox/descriptive_analytics/ConductPrincipalComponentAnalysis.py +173 -0
  34. analysistoolbox-3.9.9/analysistoolbox/descriptive_analytics/ConductPropensityScoreMatching.py +261 -0
  35. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/descriptive_analytics/CreateAssociationRules.py +149 -22
  36. analysistoolbox-3.9.9/analysistoolbox/descriptive_analytics/CreateGaussianMixtureClusters.py +223 -0
  37. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/descriptive_analytics/CreateHierarchicalClusters.py +136 -15
  38. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/descriptive_analytics/CreateKMeansClusters.py +139 -14
  39. analysistoolbox-3.9.9/analysistoolbox/descriptive_analytics/GenerateEDAWithLIDA.py +255 -0
  40. analysistoolbox-3.9.9/analysistoolbox/file_management/ConvertWordDocsToPDF.py +132 -0
  41. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/file_management/ConvertWordToHTML.py +103 -6
  42. analysistoolbox-3.9.9/analysistoolbox/file_management/CreateCopyOfPDF.py +154 -0
  43. analysistoolbox-3.9.9/analysistoolbox/file_management/CreateFileTree.py +122 -0
  44. analysistoolbox-3.9.9/analysistoolbox/file_management/ImportDataFromFolder.py +158 -0
  45. analysistoolbox-3.9.9/analysistoolbox/geospatial_analysis/ConductClusterAnalysis.py +128 -0
  46. analysistoolbox-3.9.9/analysistoolbox/geospatial_analysis/ConductSpatialAutocorrelation.py +159 -0
  47. analysistoolbox-3.9.9/analysistoolbox/geospatial_analysis/__init__.py +1 -0
  48. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/ChiSquareTestOfIndependence.py +135 -22
  49. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/ChiSquareTestOfIndependenceFromTable.py +123 -20
  50. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/ConductCoxProportionalHazardRegression.py +133 -26
  51. analysistoolbox-3.9.9/analysistoolbox/hypothesis_testing/ConductLinearRegressionAnalysis.py +159 -0
  52. analysistoolbox-3.9.9/analysistoolbox/hypothesis_testing/ConductLogisticRegressionAnalysis.py +186 -0
  53. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/ConductSurvivalAnalysis.py +136 -29
  54. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/OneSampleTTest.py +110 -24
  55. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/OneWayANOVA.py +109 -21
  56. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/TTestOfMeanFromStats.py +105 -26
  57. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/TTestOfProportionFromStats.py +104 -22
  58. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/TTestOfTwoMeansFromStats.py +108 -25
  59. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/TwoSampleTTestOfIndependence.py +115 -22
  60. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/TwoSampleTTestPaired.py +110 -22
  61. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/linear_algebra/CalculateEigenvalues.py +66 -20
  62. analysistoolbox-3.9.9/analysistoolbox/linear_algebra/ConvertMatrixToRowEchelonForm.py +77 -0
  63. analysistoolbox-3.9.9/analysistoolbox/linear_algebra/ConvertSystemOfEquationsToMatrix.py +88 -0
  64. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/linear_algebra/PlotVectors.py +52 -9
  65. analysistoolbox-3.9.9/analysistoolbox/linear_algebra/SolveSystemOfEquations.py +108 -0
  66. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/linear_algebra/VisualizeMatrixAsLinearTransformation.py +57 -14
  67. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateARIMAModel.py +102 -29
  68. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateBoostedTreeModel.py +107 -0
  69. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateDecisionTreeModel.py +125 -0
  70. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateExponentialSmoothingModel.py +118 -51
  71. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateLinearRegressionModel.py +109 -0
  72. analysistoolbox-3.9.9/analysistoolbox/predictive_analytics/CreateLogisticRegressionModel.py +185 -0
  73. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/CreateNeuralNetwork_SingleOutcome.py +93 -0
  74. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/prescriptive_analytics/ConductLinearOptimization.py +100 -20
  75. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/prescriptive_analytics/CreateContentBasedRecommender.py +109 -1
  76. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/probability/ProbabilityOfAtLeastOne.py +91 -23
  77. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/probability/ProbabilityOfHypothesisGivenData.py +70 -6
  78. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateCorrelatedSIPs.py +93 -21
  79. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateMetalogDistribution.py +113 -31
  80. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateMetalogDistributionFromPercentiles.py +107 -30
  81. analysistoolbox-3.9.9/analysistoolbox/simulations/CreateSIPDataframe.py +81 -0
  82. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateSLURPDistributionFromExponentialSmoothing.py +110 -61
  83. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateSLURPDistributionFromLinearRegression.py +138 -28
  84. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/CreateSLURPDistributionFromLogisticRegression.py +98 -60
  85. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateCountOfSuccesses.py +85 -31
  86. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateCountOutcome.py +81 -29
  87. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateCountUntilFirstSuccess.py +83 -31
  88. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateNormallyDistributedOutcome.py +88 -31
  89. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateTDistributedOutcome.py +92 -32
  90. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateTimeBetweenEvents.py +82 -27
  91. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/SimulateTimeUntilNEvents.py +87 -29
  92. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/support.py +5 -5
  93. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/statistics/CalculateConfidenceIntervalOfMean.py +99 -1
  94. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/statistics/CalculateConfidenceIntervalOfProportion.py +90 -1
  95. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/Plot100PercentStackedBarChart.py +112 -23
  96. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotBarChart.py +102 -24
  97. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotBoxWhiskerByGroup.py +114 -21
  98. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotBulletChart.py +137 -33
  99. analysistoolbox-3.9.9/analysistoolbox/visualizations/PlotCard.py +169 -0
  100. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotClusteredBarChart.py +109 -21
  101. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotContingencyHeatmap.py +91 -17
  102. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotCorrelationMatrix.py +104 -19
  103. analysistoolbox-3.9.9/analysistoolbox/visualizations/PlotDensityByGroup.py +221 -0
  104. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotDotPlot.py +136 -46
  105. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotHeatmap.py +113 -31
  106. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotOverlappingAreaChart.py +119 -24
  107. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotRiskTolerance.py +102 -23
  108. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotScatterplot.py +132 -29
  109. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotSingleVariableCountPlot.py +116 -25
  110. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotSingleVariableHistogram.py +92 -20
  111. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/PlotTimeSeries.py +124 -23
  112. analysistoolbox-3.9.9/analysistoolbox/visualizations/RenderTableOne.py +145 -0
  113. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox.egg-info/PKG-INFO +75 -4
  114. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox.egg-info/SOURCES.txt +3 -0
  115. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/setup.py +1 -1
  116. analysistoolbox-3.2.2/analysistoolbox/calculus/FindDerivative.py +0 -65
  117. analysistoolbox-3.2.2/analysistoolbox/calculus/FindLimitOfFunction.py +0 -79
  118. analysistoolbox-3.2.2/analysistoolbox/calculus/FindMinimumSquareLoss.py +0 -57
  119. analysistoolbox-3.2.2/analysistoolbox/calculus/PlotFunction.py +0 -165
  120. analysistoolbox-3.2.2/analysistoolbox/data_collection/FetchPDFFromURL.py +0 -29
  121. analysistoolbox-3.2.2/analysistoolbox/data_collection/FetchUSShapefile.py +0 -67
  122. analysistoolbox-3.2.2/analysistoolbox/data_collection/FetchWebsiteText.py +0 -54
  123. analysistoolbox-3.2.2/analysistoolbox/data_collection/GetCompanyFilings.py +0 -97
  124. analysistoolbox-3.2.2/analysistoolbox/data_collection/GetGoogleSearchResults.py +0 -66
  125. analysistoolbox-3.2.2/analysistoolbox/data_collection/GetZipFile.py +0 -36
  126. analysistoolbox-3.2.2/analysistoolbox/data_processing/AddDateNumberColumns.py +0 -41
  127. analysistoolbox-3.2.2/analysistoolbox/data_processing/AddLeadingZeros.py +0 -48
  128. analysistoolbox-3.2.2/analysistoolbox/data_processing/AddRowCountColumn.py +0 -48
  129. analysistoolbox-3.2.2/analysistoolbox/data_processing/AddTPeriodColumn.py +0 -48
  130. analysistoolbox-3.2.2/analysistoolbox/data_processing/AddTukeyOutlierColumn.py +0 -203
  131. analysistoolbox-3.2.2/analysistoolbox/data_processing/CleanTextColumns.py +0 -23
  132. analysistoolbox-3.2.2/analysistoolbox/data_processing/ConductAnomalyDetection.py +0 -97
  133. analysistoolbox-3.2.2/analysistoolbox/data_processing/ConvertOddsToProbability.py +0 -34
  134. analysistoolbox-3.2.2/analysistoolbox/data_processing/CountMissingDataByGroup.py +0 -44
  135. analysistoolbox-3.2.2/analysistoolbox/data_processing/CreateBinnedColumn.py +0 -65
  136. analysistoolbox-3.2.2/analysistoolbox/data_processing/CreateRandomSampleGroups.py +0 -32
  137. analysistoolbox-3.2.2/analysistoolbox/data_processing/CreateRareCategoryColumn.py +0 -54
  138. analysistoolbox-3.2.2/analysistoolbox/data_processing/CreateStratifiedRandomSampleGroups.py +0 -46
  139. analysistoolbox-3.2.2/analysistoolbox/data_processing/GeocodeUSAddresses.py +0 -43
  140. analysistoolbox-3.2.2/analysistoolbox/data_processing/ImputeMissingValuesUsingNearestNeighbors.py +0 -49
  141. analysistoolbox-3.2.2/analysistoolbox/data_processing/VerifyGranularity.py +0 -67
  142. analysistoolbox-3.2.2/analysistoolbox/descriptive_analytics/ConductManifoldLearning.py +0 -84
  143. analysistoolbox-3.2.2/analysistoolbox/descriptive_analytics/ConductPrincipalComponentAnalysis.py +0 -88
  144. analysistoolbox-3.2.2/analysistoolbox/descriptive_analytics/ConductPropensityScoreMatching.py +0 -158
  145. analysistoolbox-3.2.2/analysistoolbox/descriptive_analytics/CreateGaussianMixtureClusters.py +0 -117
  146. analysistoolbox-3.2.2/analysistoolbox/descriptive_analytics/GenerateEDAWithLIDA.py +0 -136
  147. analysistoolbox-3.2.2/analysistoolbox/file_management/ConvertWordDocsToPDF.py +0 -52
  148. analysistoolbox-3.2.2/analysistoolbox/file_management/CreateCopyOfPDF.py +0 -44
  149. analysistoolbox-3.2.2/analysistoolbox/file_management/CreateFileTree.py +0 -30
  150. analysistoolbox-3.2.2/analysistoolbox/file_management/ImportDataFromFolder.py +0 -54
  151. analysistoolbox-3.2.2/analysistoolbox/hypothesis_testing/ConductLinearRegressionAnalysis.py +0 -82
  152. analysistoolbox-3.2.2/analysistoolbox/hypothesis_testing/ConductLogisticRegressionAnalysis.py +0 -111
  153. analysistoolbox-3.2.2/analysistoolbox/linear_algebra/ConvertMatrixToRowEchelonForm.py +0 -39
  154. analysistoolbox-3.2.2/analysistoolbox/linear_algebra/ConvertSystemOfEquationsToMatrix.py +0 -41
  155. analysistoolbox-3.2.2/analysistoolbox/linear_algebra/SolveSystemOfEquations.py +0 -60
  156. analysistoolbox-3.2.2/analysistoolbox/predictive_analytics/CreateLogisticRegressionModel.py +0 -105
  157. analysistoolbox-3.2.2/analysistoolbox/simulations/CreateSIPDataframe.py +0 -39
  158. analysistoolbox-3.2.2/analysistoolbox/visualizations/PlotCard.py +0 -104
  159. analysistoolbox-3.2.2/analysistoolbox/visualizations/PlotDensityByGroup.py +0 -155
  160. analysistoolbox-3.2.2/analysistoolbox/visualizations/RenderTableOne.py +0 -72
  161. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/LICENSE.md +0 -0
  162. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/__init__.py +0 -0
  163. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/calculus/__init__.py +0 -0
  164. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/data_collection/__init__.py +0 -0
  165. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/data_processing/__init__.py +0 -0
  166. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/descriptive_analytics/__init__.py +0 -0
  167. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/file_management/__init__.py +0 -0
  168. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/hypothesis_testing/__init__.py +0 -0
  169. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/linear_algebra/__init__.py +0 -0
  170. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/llm/SendDeepResearchQuery.py +0 -0
  171. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/llm/SendPromptToAnthropic.py +0 -0
  172. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/llm/SendPromptToChatGPT.py +0 -0
  173. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/llm/__init__.py +0 -0
  174. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/predictive_analytics/__init__.py +0 -0
  175. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/prescriptive_analytics/__init__.py +0 -0
  176. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/probability/__init__.py +0 -0
  177. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/__init__.py +0 -0
  178. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/__init__.py +0 -0
  179. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/a_vector.py +0 -0
  180. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/class_method.py +0 -0
  181. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/metalog.py +0 -0
  182. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/simulations/pymetalog/pdf_quantile_functions.py +0 -0
  183. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/statistics/__init__.py +0 -0
  184. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox/visualizations/__init__.py +0 -0
  185. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox.egg-info/dependency_links.txt +0 -0
  186. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox.egg-info/requires.txt +0 -0
  187. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/analysistoolbox.egg-info/top_level.txt +0 -0
  188. {analysistoolbox-3.2.2 → analysistoolbox-3.9.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: analysistoolbox
3
- Version: 3.2.2
3
+ Version: 3.9.9
4
4
  Summary: A collection tools in Python for data collection and processing, statistics, analytics, and intelligence analysis.
5
5
  Home-page: https://github.com/KyleProtho/AnalysisToolBox/tree/master/analysistoolbox
6
6
  Author: Kyle Protho
@@ -44,6 +44,12 @@ sns.set(
44
44
  )
45
45
  ```
46
46
 
47
+ ## Documentation Standards
48
+
49
+ To verify that the library remains accessible to students and professionals alike, all functions in the library should include a **Teaching Note** in their docstring. This note should explain *why* the function matters, how it aids in "sense-making," or what qualitative insights it reveals, rather than just describing the mechanics of the code.
50
+
51
+ See `analysistoolbox.calculus.PlotFunction` for a canonical example.
52
+
47
53
  ## Table of Contents / Usage
48
54
 
49
55
  There are many modules in the analysistoolbox package, each with their own functions. The following is a list of the modules:
@@ -93,6 +99,9 @@ There are many modules in the analysistoolbox package, each with their own funct
93
99
  - [CreateFileTree](#createfiletree)
94
100
  - [CreateCopyOfPDF](#createcopyofpdf)
95
101
  - [ConvertWordDocsToPDF](#convertworddocstopdf)
102
+ - [Geospatial Analysis](#geospatial-analysis)
103
+ - [ConductClusterAnalysis](#conductclusteranalysis)
104
+ - [ConductSpatialAutocorrelation](#conductspatialautocorrelation)
96
105
  - [Hypothesis Testing](#hypothesis-testing)
97
106
  - [ChiSquareTestOfIndependence](#chisquaretestofindependence)
98
107
  - [ChiSquareTestOfIndependenceFromTable](#chisquaretestofindependencefromtable)
@@ -1135,6 +1144,68 @@ ConvertWordDocsToPDF(
1135
1144
  )
1136
1145
  ```
1137
1146
 
1147
+
1148
+ ### Geospatial Analysis
1149
+
1150
+ #### ConductClusterAnalysis
1151
+
1152
+ The **ConductClusterAnalysis** function groups geospatial data points into clusters based on their proximity using the DBSCAN algorithm. It mimics the functionality of Bellingcat's geoclustering tool and can optionally display a map of the clusters.
1153
+
1154
+ ```python
1155
+ # Import the function
1156
+ from analysistoolbox.geospatial_analysis import ConductClusterAnalysis
1157
+ import pandas as pd
1158
+
1159
+ # Create a sample dataframe
1160
+ df = pd.DataFrame({
1161
+ 'lat': [40.7128, 40.7130, 34.0522, 34.0525],
1162
+ 'lon': [-74.0060, -74.0065, -118.2437, -118.2440]
1163
+ })
1164
+
1165
+ # Run cluster analysis
1166
+ summary = ConductClusterAnalysis(
1167
+ dataframe=df,
1168
+ longitude_column='lon',
1169
+ latitude_column='lat',
1170
+ distance_km=0.5,
1171
+ min_samples=2,
1172
+ map_clusters=True
1173
+ )
1174
+
1175
+ # Print summary
1176
+ print(summary)
1177
+ ```
1178
+
1179
+ #### ConductSpatialAutocorrelation
1180
+
1181
+ The **ConductSpatialAutocorrelation** function identifies spatial clusters and outliers using Local Moran's I. Spatial autocorrelation measures how much a variable at a location is correlated with the same variable at neighboring locations, effectively identifying if similar values cluster together (hotspots/coldspots) or if dissimilar values are near each other (spatial outliers).
1182
+
1183
+ ```python
1184
+ # Import the function
1185
+ from analysistoolbox.geospatial_analysis import ConductSpatialAutocorrelation
1186
+ import pandas as pd
1187
+
1188
+ # Create a sample dataframe
1189
+ df = pd.DataFrame({
1190
+ 'lat': [40.7128, 40.7130, 34.0522, 34.0525, 34.0500],
1191
+ 'lon': [-74.0060, -74.0065, -118.2437, -118.2440, -118.2500],
1192
+ 'value': [100, 105, 10, 15, 8]
1193
+ })
1194
+
1195
+ # Run spatial autocorrelation analysis
1196
+ results = ConductSpatialAutocorrelation(
1197
+ dataframe=df,
1198
+ longitude_column='lon',
1199
+ latitude_column='lat',
1200
+ value_column='value',
1201
+ k=5,
1202
+ plot=True
1203
+ )
1204
+
1205
+ # Print results
1206
+ print(results[['lat', 'lon', 'value', 'cluster_category']])
1207
+ ```
1208
+
1138
1209
  ### Hypothesis Testing
1139
1210
 
1140
1211
  #### ChiSquareTestOfIndependence
@@ -1677,11 +1748,11 @@ model = CreateNeuralNetwork_SingleOutcome(
1677
1748
 
1678
1749
  ### Prescriptive Analytics
1679
1750
 
1680
- The prescriptive analytics module provides tools for making data-driven recommendations and decisions:
1751
+ The prescriptive analytics module empowers users to determine the best course of action through optimization and personalized recommendation systems, bridging the gap between insight and action.
1681
1752
 
1682
1753
  #### ConductLinearOptimization
1683
1754
 
1684
- Conducts linear optimization to find the optimal input values for a given output variable, with optional constraints.
1755
+ Identifies the optimal values for input variables to maximize or minimize a specific output, subject to logical constraints and data-driven linear relationships. This approach is essential for resource allocation, logistics optimization, and cost minimization.
1685
1756
 
1686
1757
  ```python
1687
1758
  import pandas as pd
@@ -1712,7 +1783,7 @@ results = ConductLinearOptimization(
1712
1783
 
1713
1784
  #### CreateContentBasedRecommender
1714
1785
 
1715
- Builds a content-based recommendation system using neural networks to learn user and item embeddings.
1786
+ Generates a customized recommendation engine using a "two-tower" neural network architecture to match users with highly relevant items or resources based on shared characteristics. This is particularly useful for personalized content delivery, such as matching patients to clinical trials or identifying relevant intelligence reports.
1716
1787
 
1717
1788
  ```python
1718
1789
  from analysistoolbox.prescriptive_analytics import CreateContentBasedRecommender
@@ -26,6 +26,12 @@ sns.set(
26
26
  )
27
27
  ```
28
28
 
29
+ ## Documentation Standards
30
+
31
+ To verify that the library remains accessible to students and professionals alike, all functions in the library should include a **Teaching Note** in their docstring. This note should explain *why* the function matters, how it aids in "sense-making," or what qualitative insights it reveals, rather than just describing the mechanics of the code.
32
+
33
+ See `analysistoolbox.calculus.PlotFunction` for a canonical example.
34
+
29
35
  ## Table of Contents / Usage
30
36
 
31
37
  There are many modules in the analysistoolbox package, each with their own functions. The following is a list of the modules:
@@ -75,6 +81,9 @@ There are many modules in the analysistoolbox package, each with their own funct
75
81
  - [CreateFileTree](#createfiletree)
76
82
  - [CreateCopyOfPDF](#createcopyofpdf)
77
83
  - [ConvertWordDocsToPDF](#convertworddocstopdf)
84
+ - [Geospatial Analysis](#geospatial-analysis)
85
+ - [ConductClusterAnalysis](#conductclusteranalysis)
86
+ - [ConductSpatialAutocorrelation](#conductspatialautocorrelation)
78
87
  - [Hypothesis Testing](#hypothesis-testing)
79
88
  - [ChiSquareTestOfIndependence](#chisquaretestofindependence)
80
89
  - [ChiSquareTestOfIndependenceFromTable](#chisquaretestofindependencefromtable)
@@ -1117,6 +1126,68 @@ ConvertWordDocsToPDF(
1117
1126
  )
1118
1127
  ```
1119
1128
 
1129
+
1130
+ ### Geospatial Analysis
1131
+
1132
+ #### ConductClusterAnalysis
1133
+
1134
+ The **ConductClusterAnalysis** function groups geospatial data points into clusters based on their proximity using the DBSCAN algorithm. It mimics the functionality of Bellingcat's geoclustering tool and can optionally display a map of the clusters.
1135
+
1136
+ ```python
1137
+ # Import the function
1138
+ from analysistoolbox.geospatial_analysis import ConductClusterAnalysis
1139
+ import pandas as pd
1140
+
1141
+ # Create a sample dataframe
1142
+ df = pd.DataFrame({
1143
+ 'lat': [40.7128, 40.7130, 34.0522, 34.0525],
1144
+ 'lon': [-74.0060, -74.0065, -118.2437, -118.2440]
1145
+ })
1146
+
1147
+ # Run cluster analysis
1148
+ summary = ConductClusterAnalysis(
1149
+ dataframe=df,
1150
+ longitude_column='lon',
1151
+ latitude_column='lat',
1152
+ distance_km=0.5,
1153
+ min_samples=2,
1154
+ map_clusters=True
1155
+ )
1156
+
1157
+ # Print summary
1158
+ print(summary)
1159
+ ```
1160
+
1161
+ #### ConductSpatialAutocorrelation
1162
+
1163
+ The **ConductSpatialAutocorrelation** function identifies spatial clusters and outliers using Local Moran's I. Spatial autocorrelation measures how much a variable at a location is correlated with the same variable at neighboring locations, effectively identifying if similar values cluster together (hotspots/coldspots) or if dissimilar values are near each other (spatial outliers).
1164
+
1165
+ ```python
1166
+ # Import the function
1167
+ from analysistoolbox.geospatial_analysis import ConductSpatialAutocorrelation
1168
+ import pandas as pd
1169
+
1170
+ # Create a sample dataframe
1171
+ df = pd.DataFrame({
1172
+ 'lat': [40.7128, 40.7130, 34.0522, 34.0525, 34.0500],
1173
+ 'lon': [-74.0060, -74.0065, -118.2437, -118.2440, -118.2500],
1174
+ 'value': [100, 105, 10, 15, 8]
1175
+ })
1176
+
1177
+ # Run spatial autocorrelation analysis
1178
+ results = ConductSpatialAutocorrelation(
1179
+ dataframe=df,
1180
+ longitude_column='lon',
1181
+ latitude_column='lat',
1182
+ value_column='value',
1183
+ k=5,
1184
+ plot=True
1185
+ )
1186
+
1187
+ # Print results
1188
+ print(results[['lat', 'lon', 'value', 'cluster_category']])
1189
+ ```
1190
+
1120
1191
  ### Hypothesis Testing
1121
1192
 
1122
1193
  #### ChiSquareTestOfIndependence
@@ -1659,11 +1730,11 @@ model = CreateNeuralNetwork_SingleOutcome(
1659
1730
 
1660
1731
  ### Prescriptive Analytics
1661
1732
 
1662
- The prescriptive analytics module provides tools for making data-driven recommendations and decisions:
1733
+ The prescriptive analytics module empowers users to determine the best course of action through optimization and personalized recommendation systems, bridging the gap between insight and action.
1663
1734
 
1664
1735
  #### ConductLinearOptimization
1665
1736
 
1666
- Conducts linear optimization to find the optimal input values for a given output variable, with optional constraints.
1737
+ Identifies the optimal values for input variables to maximize or minimize a specific output, subject to logical constraints and data-driven linear relationships. This approach is essential for resource allocation, logistics optimization, and cost minimization.
1667
1738
 
1668
1739
  ```python
1669
1740
  import pandas as pd
@@ -1694,7 +1765,7 @@ results = ConductLinearOptimization(
1694
1765
 
1695
1766
  #### CreateContentBasedRecommender
1696
1767
 
1697
- Builds a content-based recommendation system using neural networks to learn user and item embeddings.
1768
+ Generates a customized recommendation engine using a "two-tower" neural network architecture to match users with highly relevant items or resources based on shared characteristics. This is particularly useful for personalized content delivery, such as matching patients to clinical trials or identifying relevant intelligence reports.
1698
1769
 
1699
1770
  ```python
1700
1771
  from analysistoolbox.prescriptive_analytics import CreateContentBasedRecommender
@@ -0,0 +1,111 @@
1
+ # Load packages
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ # Declare function
6
+ def FindDerivative(
7
+ f_of_x: sympy.Expr,
8
+ print_functions: bool = False,
9
+ return_derivative_function: bool = False,
10
+ plot_functions: bool = False,
11
+ **plot_kwargs
12
+ ) -> Optional[sympy.Expr]:
13
+ """
14
+ Compute and explore the symbolic derivative of a mathematical function.
15
+
16
+ Derivatives describe how a quantity changes with respect to another — mathematically,
17
+ they are the instantaneous *rate of change* of a function with respect to a variable.
18
+ Symbolic differentiation produces an exact analytic expression for this change,
19
+ rather than a numerical approximation. SymPy is used to compute the derivative expression.
20
+
21
+ The derivative has broad interpretation outside mathematics:
22
+ * In intelligence analysis, the derivative of a threat likelihood function with respect
23
+ to time or another risk factor can reveal *acceleration* in an emerging risk trend.
24
+ * In criminal investigation time series (e.g., incident counts over time), changes in
25
+ slope or inflection points may signal a shift in offender behavior or an outbreak
26
+ pattern that warrants deeper inquiry.
27
+ * In healthcare analytics, derivatives quantify things like the *change in a biomarker
28
+ per unit time* or *how a treatment effect accelerates or decelerates over time*,
29
+ informing early warning signals or intervention effectiveness.
30
+
31
+ This function:
32
+ * Symbolically differentiates `func` with respect to the given variable (or infers the
33
+ single symbolic variable if omitted).
34
+ * Optionally prints the original and derivative expressions.
35
+ * Optionally plots both functions using matplotlib for visual insight into their relationship.
36
+ * Optionally returns the symbolic derivative expression.
37
+
38
+ Parameters
39
+ ----------
40
+ f_of_x
41
+ A SymPy expression representing the analytic function (e.g., f(x) = x**2 + 3*x).
42
+ print_functions
43
+ If True, prints the original and derivative expressions for inspection.
44
+ return_derivative_function
45
+ If True, returns the symbolic derivative expression.
46
+ show_plot
47
+ If True, generates a plot of the original and derivative over a default or user-supplied
48
+ domain using `plot_kwargs`.
49
+ **plot_kwargs
50
+ Additional keyword arguments passed to the plotting routine.
51
+
52
+ Returns
53
+ -------
54
+ The symbolic derivative expression if `return_derivative_function` is True, else None.
55
+
56
+ Examples
57
+ --------
58
+ # Symbolically differentiate f(x) = x^3 + 2*x^2
59
+ x = sympy.symbols('x')
60
+ FindDerivative(x**3 + 2*x**2, print_functions=True, return_derivative_function=True)
61
+
62
+ Teaching Note
63
+ -------------
64
+ A derivative transforms a function into a new one that reflects *how fast* the original
65
+ changes. For example, steep slopes (large derivative values) may indicate critical
66
+ transitions. Plotting the original and derivative together often reveals features
67
+ like maxima, minima, or inflection points that are not obvious from raw numbers alone.
68
+
69
+ """
70
+ # Lazy load uncommon packages
71
+ import sympy
72
+
73
+ # Compute the derivative of the higher-order function using sympy
74
+ try:
75
+ d_f_of_x = sympy.diff(f_of_x, x)
76
+ except NameError:
77
+ raise ValueError("The function must be a sympy expression. Ensure that you have imported sympy and declared x as a sympy symbol. ( e.g., x = sympy.Symbol('x') )" )
78
+
79
+ # Print the derivative function
80
+ if print_functions:
81
+ print("f(x):", f_of_x)
82
+ print("f'(x):", d_f_of_x)
83
+
84
+ # Plot the derivative function if requested
85
+ if plot_functions:
86
+ # Create x values
87
+ x_values = np.linspace(minimum_x, maximum_x, n)
88
+
89
+ # Vectorize the original function and its derivative
90
+ vfunc = np.vectorize(lambda val: f_of_x.evalf(subs={x: val}))
91
+ vfunc_derivative = np.vectorize(lambda val: d_f_of_x.evalf(subs={x: val}))
92
+
93
+ # Create y values for original function and its derivative using the vectorized functions
94
+ y_values_original = vfunc(x_values)
95
+ y_values_derivative = vfunc_derivative(x_values)
96
+
97
+ # Plot the original function
98
+ plt.plot(x_values, y_values_original, label="f(x)")
99
+
100
+ # Plot the derivative function
101
+ plt.plot(x_values, y_values_derivative, label="f'(x)")
102
+
103
+ # Add a legend
104
+ plt.legend()
105
+
106
+ # Show the plot
107
+ plt.show()
108
+
109
+ # Return the derivative function if requested
110
+ if return_derivative_function:
111
+ return d_f_of_x
@@ -0,0 +1,123 @@
1
+ # Load packages
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ # Declare function
6
+ def FindLimitOfFunction(
7
+ f_of_x,
8
+ point,
9
+ step: float = 0.001,
10
+ plot_function: bool = False,
11
+ x_minimum: float = None,
12
+ x_maximum: float = None,
13
+ n: int = 500,
14
+ tangent_line_window: float = 1.0,
15
+ **plot_kwargs
16
+ ) -> sympy.Expr:
17
+ """
18
+ Compute and visualize the limit of a mathematical function as its input
19
+ approaches a specified point.
20
+
21
+ In calculus, a *limit* describes the value that a function’s output
22
+ approaches as its input gets arbitrarily close to a given point, even
23
+ if the function is not defined at that point itself. Limits underpin
24
+ many core ideas in analysis — including continuity, derivatives, and
25
+ asymptotic behavior — and have practical interpretive value in analytic
26
+ domains.
27
+
28
+ This function:
29
+ * Uses SymPy’s symbolic `limit` capability to compute the limit of
30
+ `f_of_x` as its independent variable approaches `point`.
31
+ * Optionally plots the function near `point` and overlays a tangent
32
+ line to illustrate the local approach behavior.
33
+ * Returns the symbolic limit expression for programmatic inspection.
34
+
35
+ Parameters
36
+ ----------
37
+ f_of_x
38
+ A symbolic or numeric expression representing f(x). Limits can
39
+ reveal behavior near discontinuities or indeterminate forms.:contentReference[oaicite:1]{index=1}
40
+ point
41
+ The input value that x approaches (e.g., 0, infinity, or a finite
42
+ critical point).
43
+ step
44
+ Step size used for numerical approximation or plotting.
45
+ plot_function
46
+ If True, generate a matplotlib plot of `func` near `point`.
47
+ x_minimum, x_maximum
48
+ The range over which to plot `func`. If None, a default window
49
+ around `point` is chosen.
50
+ n
51
+ Number of points used for plotting.
52
+ tangent_line_window
53
+ Width of the window around `point` over which the tangent line is
54
+ drawn.
55
+ **plot_kwargs
56
+ Additional keyword arguments passed to the plotting routine.
57
+
58
+ Returns
59
+ -------
60
+ A symbolic SymPy expression representing the limit of `func` as x→`point`.
61
+
62
+ Examples
63
+ --------
64
+ # Symbolically compute the limit of sin(x)/x as x→0
65
+ x = sympy.symbols('x')
66
+ FindLimitOfFunction(sympy.sin(x)/x, point=0, plot_function=True)
67
+
68
+ Teaching Note
69
+ -------------
70
+ A limit expresses the *behavior* of a function in the vicinity of a value:
71
+ it does not require the function to be defined at that exact point. For
72
+ instance, sin(x)/x is undefined at x=0, yet its limit as x approaches
73
+ 0 is 1 — reflecting the function’s approach behavior, not its value at
74
+ the point.
75
+ """
76
+
77
+ # Create array of values based on the function
78
+ x = np.linspace(x_minimum, x_maximum, n)
79
+ y = np.zeros(len(x))
80
+ for i in range(len(x)):
81
+ y[i] = f_of_x(x[i])
82
+
83
+ # Calculate the x_tangent
84
+ x_tangent = (f_of_x(point+step) - f_of_x(point-step)) / (2*step)
85
+
86
+ # Calculate the limit at the point of interest
87
+ try:
88
+ limit = f_of_x(point)
89
+ print("The limit at x={0} is ~{1}".format(point, limit))
90
+ # Create the tangent line
91
+ y_tangent = f_of_x(point) + x_tangent*(x - point)
92
+
93
+ # Plot the function if requested
94
+ if plot_function:
95
+ # Plot point at the point of interest
96
+ plt.plot(point, f_of_x(point), "ro")
97
+
98
+ # Plot the tangent line
99
+ if plot_tangent_line:
100
+ # plt.scatter(x0, my_function(x0), color='red')
101
+ plt.plot(x, y_tangent, label='Tangent line', color='red', alpha=0.5)
102
+ plt.scatter(point, f_of_x(point), color='red')
103
+
104
+ # Plot the function if requested
105
+ if plot_function:
106
+ # Plot the function
107
+ plt.plot(x, y, color="black", label='Function')
108
+
109
+ # Add title
110
+ plt.title("f(x)")
111
+
112
+ # Add legend
113
+ plt.legend()
114
+
115
+ # Show plot
116
+ plt.show()
117
+ plt.clf()
118
+
119
+ # Return the limit
120
+ return limit
121
+
122
+ except ZeroDivisionError:
123
+ print("The limit at x={0} is undefined.".format(point))
@@ -0,0 +1,106 @@
1
+ # Load packages
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ import seaborn as sns
5
+
6
+ # Declare function
7
+ def FindMinimumSquareLoss(
8
+ observed_values,
9
+ predicted_values,
10
+ show_plot: bool = False,
11
+ **plot_kwargs
12
+ ):
13
+ """
14
+ Find the parameter value that minimizes squared loss between observed data
15
+ and a model function.
16
+
17
+ Squared loss measures the total discrepancy between observed values and
18
+ model-predicted values by summing the squared residuals. Minimizing this
19
+ quantity yields the parameter value that best fits the data under a
20
+ least-squares criterion.
21
+
22
+ In analytic practice, least-squares minimization formalizes a common
23
+ reasoning task: choosing the explanation, model, or parameterization that
24
+ best accounts for observed evidence while penalizing large errors more
25
+ heavily than small ones.
26
+
27
+ This function:
28
+ * Constructs a squared loss function based on the difference between
29
+ observed `y_values` and the model's predictions.
30
+ * Symbolically differentiates the loss with respect to the model
31
+ parameter.
32
+ * Solves for the parameter value that minimizes total squared error.
33
+ * Optionally prints intermediate results and visualizes the fit.
34
+
35
+ Parameters
36
+ ----------
37
+ observed_values
38
+ Observed dependent variable values (e.g., incidents, biomarker levels,
39
+ risk scores).
40
+ predicted_values
41
+ Predicted dependent variable values (e.g., incidents, biomarker levels,
42
+ risk scores).
43
+ show_plot
44
+ If True, plots observed data against the fitted model.
45
+ **plot_kwargs
46
+ Additional keyword arguments passed to the plotting routine.
47
+
48
+ Returns
49
+ -------
50
+ The parameter value that minimizes the squared loss between observed data
51
+ and the model.
52
+
53
+ Examples
54
+ --------
55
+ FindMinimumSquareLoss(
56
+ observed_values=[1, 2, 3, 4],
57
+ predicted_values=[2.1, 4.2, 5.9, 8.3],
58
+ show_plot=True
59
+ )
60
+
61
+ Teaching Note
62
+ -------------
63
+ Squared loss grows rapidly as errors increase. This makes least-squares
64
+ methods especially sensitive to large deviations, which is often desirable
65
+ when large errors correspond to analytically meaningful failures rather
66
+ than random noise.
67
+ """
68
+
69
+ # Check if the number of observed values is equal to the number of predicted values.
70
+ if len(observed_values) != len(predicted_values):
71
+ raise ValueError("The number of observed values must be equal to the number of predicted values.")
72
+
73
+ # If values are passed as a list, convert them to a numpy array.
74
+ if type(observed_values) == list:
75
+ observed_values = np.array(observed_values)
76
+ if type(predicted_values) == list:
77
+ predicted_values = np.array(predicted_values)
78
+
79
+ # Count the number of observed values.
80
+ n = len(observed_values)
81
+
82
+ # Calculate the prediction error.
83
+ sq_prediction_error = (predicted_values - observed_values) ** 2
84
+
85
+ # Calculate the sum of squares.
86
+ sum_of_squares = sum(sq_prediction_error)
87
+
88
+ # Calculate the minimum square loss.
89
+ FindMinimumSquareLoss = sum_of_squares / n
90
+
91
+ # Plot the prediction errors in a plot, if requested.
92
+ if show_plot:
93
+ sns.boxplot(y=sq_prediction_error, color="grey")
94
+ # Add the minimum square loss as a horizontal line.
95
+ plt.axhline(FindMinimumSquareLoss, color="r", linestyle="--")
96
+ # Add labels.
97
+ plt.title("Squared Prediction Errors", fontsize=14, fontweight="bold")
98
+ plt.text(0.5, FindMinimumSquareLoss + .01, "Min. Sq. Loss = " + str(round(FindMinimumSquareLoss, 2)))
99
+ # Remove borders from plot
100
+ sns.despine(bottom=True)
101
+ # Show plot
102
+ plt.show()
103
+
104
+ # Return the minimum square loss.
105
+ return FindMinimumSquareLoss
106
+