{"id":15038472,"url":"https://github.com/openalloc/swiftregressor","last_synced_at":"2025-04-09T23:40:36.845Z","repository":{"id":63919503,"uuid":"429559461","full_name":"openalloc/SwiftRegressor","owner":"openalloc","description":"A linear regression tool that’s flexible and easy to use","archived":false,"fork":false,"pushed_at":"2023-05-01T23:59:21.000Z","size":24,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-03T01:45:33.675Z","etag":null,"topics":["linear-regression","regression","swift-generics","swift-lang","swift-language","swift-library"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openalloc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-18T19:47:13.000Z","updated_at":"2024-05-03T23:45:15.000Z","dependencies_parsed_at":"2025-02-16T02:32:03.235Z","dependency_job_id":"0eb54a73-64c9-4ea0-b178-26cf1515811f","html_url":"https://github.com/openalloc/SwiftRegressor","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftRegressor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftRegressor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftRegressor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftRegressor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openalloc","download_url":"https://codeload.github.com/openalloc/SwiftRegressor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131466,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linear-regression","regression","swift-generics","swift-lang","swift-language","swift-library"],"created_at":"2024-09-24T20:38:37.657Z","updated_at":"2025-04-09T23:40:36.826Z","avatar_url":"https://github.com/openalloc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftRegressor\n\nA linear regression tool that’s flexible and easy to use.\n\nAvailable as an open source Swift library to be incorporated in other apps.\n\n_SwiftRegressor_ is part of the [OpenAlloc](https://github.com/openalloc) family of open source Swift software tools.\n\n## Regressor\n\n```swift\nlet points: [BaseRegressor\u003cDouble\u003e.Point] = [\n    Point(x: 0, y: 0),\n    Point(x: 1, y: 1),\n    Point(x: 2, y: 4),\n    Point(x: 3, y: 9),\n    Point(x: 4, y: 16),\n    Point(x: 5, y: 25),\n    Point(x: 6, y: 36),\n]\n\nlet lr = LinearRegressor(points: points)!\n\nprint(String(format: \"Intercept: %.1f\", lr.intercept))\n=\u003e \"Intercept: -5.0\"\n\nprint(String(format: \"Slope: %.1f\", lr.slope))\n=\u003e \"Slope: 6.0\"\n\nprint(String(format: \"y @ x=4.5: %.1f\", lr.yRegression(x: 4.5)))\n=\u003e \"y @ x=4.5: 22.0\"\n\nprint(String(format: \"x @ y=30: %.1f\", lr.xEstimate(y: 30)))\n=\u003e \"x @ y=30: 5.8\"\n\nprint(String(format: \"r^2: %.3f\", lr.rSquared))\n=\u003e \"r^2: 0.923\"\n```\n\n## Types\n\nThe `Point` type is declared within `BaseRegressor`, where `T` is your `BinaryFloatingPoint` data type:\n\n```swift\npublic struct Point: Equatable {\n    public let x, y: T\n    public init(x: T, y: T) {\n        self.x = x\n        self.y = y\n    }\n}\n```\n\nIt's often convenient to declare your own derivative type:\n\n```swift\ntypealias MyPoint = BaseRegressor\u003cFloat\u003e.Point\n```\n\n## Initialization\n\nBoth the base and linear regressor share the same initialization:\n\n- `init?(points: [BaseRegressor\u003cT\u003e.Point])`\n\nInitialization will fail and return `nil` if provided nonsense parameters, such as no points provided.\n\nThe initialization values are also available as properties:\n\n- `let points: [BaseRegressor\u003cT\u003e.Point]`: the points in the source data set\n\n## Instance Properties and Methods\n\nComputed properties are lazy, meaning that they are only calculated when first needed.\n\n#### Base Regressor\n\nThe base regressor offers functionality common to different types of regressions.\n\n- `var count: T`: the count of points in the data set\n\n- `var mean: BaseRegressor\u003cT\u003e.Point`: the mean values along both axes\n\n- `var summed: BaseRegressor\u003cT\u003e.Point`: the sum of values along both axes\n\n- `func xEstimates(y: T) -\u003e [T]`: estimate real-number x-value solutions from a y-value\n\n- `func yRegression(x: T) -\u003e T`: estimate a y-value from an x-value\n\n- `var resultPoints: [BaseRegressor\u003cT\u003e.Point]`: the resulting points for each x-value in the source data set \n\n- `var resultValuesY: [T]`: the resulting y-values for each x-value in the source data set \n\n#### Linear Regressor\n\nThe linear regressor inherits all the properties and methods of the base regressor.\n\n- `func xEstimate(y: T) -\u003e T`: estimate an x-value from a y-value\n\n- `var intercept: T`:  Intercept (a)\n\n- `var pearsonsCorrelation: T`: Pearson’s Correlation (r)\n\n- `var rSquared: T`: A measure of error in the regression (1.0 means zero error)\n\n- `var sampleStandardDeviation: BaseRegressor\u003cT\u003e.Point`: the calculated standard deviation along both axes\n\n- `var slope: T`: Slope (b)\n\n- `var ssRegression: T`: sum squared regression error\n\n- `var ssTotal: T`: sum squared total error\n\n- `var summedSquareError: BaseRegressor\u003cT\u003e.Point`: sum squared error along both axes\n\n## See Also\n\nThis library is a member of the _OpenAlloc Project_.\n\n* [_OpenAlloc_](https://openalloc.github.io) - product website for all the _OpenAlloc_ apps and libraries\n* [_OpenAlloc Project_](https://github.com/openalloc) - Github site for the development project, including full source code\n\n## License\n\nCopyright 2021, 2022 OpenAlloc LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n## Contributing\n\nThe contributions of other regressors, such as a polynominal regressor, would be most welcome!\n\nOther contributions are welcome too. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features. \n\nThe pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.\n\nContributions should ultimately have adequate test coverage. See tests for current entities to see what coverage is expected.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftregressor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenalloc%2Fswiftregressor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftregressor/lists"}