Skip to main content

自动化拟合多项式,并自动判断最佳次幂

Project description

Install

# only for python3
# need: sqlite3

pip install autoleastsq

Usage

# -*- coding: utf-8 -*-  

import autoleastsq

### 从文件获取数据到 list   其他数据源只要符合数据类型和对齐就行了

filename="./test.xlsx"
lists=autoleastsq.excel_col2list(filename,["a","b","result"])


################# 多元多项式回归样例

# 挑选所需要的因子  注意append 因子次序决定了拟合的公式,和后续使用时的入口次序, append 几个因子多项式就有几元,可灵活使用

factor=[]  # factor自由多个因子的二维list
factor.append(lists[0])
factor.append(lists[1])
y = lists[2]

##################### 拟合得到多项式模型

# 返回:多项式的参数列表、 幂次,并可根据新输入的因子list 进行预测

"""
支持的参数:
pows_start=1	# pows_start 起始拟合的幂次(默认为1)
loss_min=0.01		# loss 起始误差率要求(默认0.01, 达到即拟合结束), 过程中会自动判断最可能的误差率
leastsq_mult(factor,y,pows_start,loss_min)
"""

model=autoleastsq.leastsq_mult(factor,y)

print(model.args,model.pows)  ## 最终的多项式参数 按高次向低次逐个因子排列 ; 最终的多项式参数最高幂次
print(model.func)  ##  模型公式

################# 根据拟合后结果多项式,按顺序输入得到结果

factor=[29,101]

result=model.leastsq_result(factor)

print(result)


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autoleastsq-1.0.1.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file autoleastsq-1.0.1.tar.gz.

File metadata

  • Download URL: autoleastsq-1.0.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for autoleastsq-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2c99b34001506d10e6bf43a86e8057cf2e2f709159250b9d5da1e8f33ca6a663
MD5 db0e3e2ef57327002894908f9a7d0c72
BLAKE2b-256 c76dd9659a4fad8604e36b04d6a690fb7556c02af3b1e0f43085767136c53b8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page