第一次提交
实现了线性回归:将康宁给的有效窗口和波长文件 →(转化) 为y=ax+b 的参数a、b;
This commit is contained in:
243
.gitignore
vendored
Normal file
243
.gitignore
vendored
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
# tc
|
||||||
|
/.idea
|
||||||
|
*.xlsx
|
||||||
|
*.cal
|
||||||
|
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
.pdm.toml
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
88
main.py
Normal file
88
main.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# https://www.cnblogs.com/vachester/p/7202793.html
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
from sklearn import datasets, linear_model
|
||||||
|
|
||||||
|
|
||||||
|
def get_data(file_name):
|
||||||
|
# data = pd.read_csv(file_name, header = None)
|
||||||
|
# data = pd.read_excel(file_name)
|
||||||
|
# X_parameter = []
|
||||||
|
# Y_parameter = []
|
||||||
|
# for single_square_feet, single_price_value in zip(data['square_feet'], data['price']):
|
||||||
|
# X_parameter.append([float(single_square_feet)])
|
||||||
|
# Y_parameter.append(float(single_price_value))
|
||||||
|
|
||||||
|
row = list(range(340, 340 + 300))
|
||||||
|
wave = [399.959, 401.958, 403.958, 405.957, 407.957, 409.957, 411.956, 413.956, 415.955, 417.955, 419.954, 421.954,
|
||||||
|
423.954, 425.953, 427.953, 429.952, 431.952, 433.951, 435.951, 437.951, 439.95, 441.95, 443.949, 445.949,
|
||||||
|
447.948, 449.948, 451.947, 453.947, 455.947, 457.946, 459.946, 461.945, 463.945, 465.944, 467.944, 469.944,
|
||||||
|
471.943, 473.943, 475.942, 477.942, 479.941, 481.941, 483.94, 485.94, 487.94, 489.939, 491.939, 493.938,
|
||||||
|
495.938, 497.937, 499.937, 501.937, 503.936, 505.936, 507.935, 509.935, 511.934, 513.934, 515.933, 517.933,
|
||||||
|
519.933, 521.932, 523.932, 525.931, 527.931, 529.93, 531.93, 533.93, 535.929, 537.929, 539.928, 541.928,
|
||||||
|
543.927, 545.927, 547.927, 549.926, 551.926, 553.925, 555.925, 557.924, 559.924, 561.923, 563.923, 565.923,
|
||||||
|
567.922, 569.922, 571.921, 573.921, 575.92, 577.92, 579.92, 581.919, 583.919, 585.918, 587.918, 589.917,
|
||||||
|
591.917, 593.917, 595.916, 597.916, 599.915, 601.915, 603.914, 605.914, 607.913, 609.913, 611.913, 613.912,
|
||||||
|
615.912, 617.911, 619.911, 621.91, 623.91, 625.909, 627.909, 629.909, 631.908, 633.908, 635.907, 637.907,
|
||||||
|
639.906, 641.906, 643.906, 645.905, 647.905, 649.904, 651.904, 653.903, 655.903, 657.903, 659.902, 661.902,
|
||||||
|
663.901, 665.901, 667.9, 669.9, 671.899, 673.899, 675.899, 677.898, 679.898, 681.897, 683.897, 685.896,
|
||||||
|
687.896, 689.896, 691.895, 693.895, 695.894, 697.894, 699.893, 701.893, 703.893, 705.892, 707.892, 709.891,
|
||||||
|
711.891, 713.89, 715.89, 717.889, 719.889, 721.889, 723.888, 725.888, 727.887, 729.887, 731.886, 733.886,
|
||||||
|
735.886, 737.885, 739.885, 741.884, 743.884, 745.883, 747.883, 749.883, 751.882, 753.882, 755.881, 757.881,
|
||||||
|
759.88, 761.88, 763.879, 765.879, 767.879, 769.878, 771.878, 773.877, 775.877, 777.876, 779.876, 781.876,
|
||||||
|
783.875, 785.875, 787.874, 789.874, 791.873, 793.873, 795.872, 797.872, 799.872, 801.871, 803.871, 805.87,
|
||||||
|
807.87, 809.869, 811.869, 813.869, 815.868, 817.868, 819.867, 821.867, 823.866, 825.866, 827.866, 829.865,
|
||||||
|
831.865, 833.864, 835.864, 837.863, 839.863, 841.862, 843.862, 845.862, 847.861, 849.861, 851.86, 853.86,
|
||||||
|
855.859, 857.859, 859.858, 861.858, 863.858, 865.857, 867.857, 869.856, 871.856, 873.855, 875.855, 877.855,
|
||||||
|
879.854, 881.854, 883.853, 885.853, 887.852, 889.852, 891.852, 893.851, 895.851, 897.85, 899.85, 901.849,
|
||||||
|
903.849, 905.848, 907.848, 909.848, 911.847, 913.847, 915.846, 917.846, 919.845, 921.845, 923.845, 925.844,
|
||||||
|
927.844, 929.843, 931.843, 933.842, 935.842, 937.841, 939.841, 941.841, 943.84, 945.84, 947.839, 949.839,
|
||||||
|
951.838, 953.838, 955.838, 957.837, 959.837, 961.836, 963.836, 965.835, 967.835, 969.835, 971.834, 973.834,
|
||||||
|
975.833, 977.833, 979.832, 981.832, 983.831, 985.831, 987.831, 989.83, 991.83, 993.829, 995.829, 997.828]
|
||||||
|
|
||||||
|
row_bin2 = list(range(170, 170 + 150))
|
||||||
|
wave_bin2 = []
|
||||||
|
for i in range(0, len(wave), 2):
|
||||||
|
# print(i)
|
||||||
|
# print(wave[i:i + 2])
|
||||||
|
wave_bin2.append((wave[i] + wave[i+1])/2)
|
||||||
|
|
||||||
|
X_parameter = []
|
||||||
|
Y_parameter = []
|
||||||
|
for single_square_feet, single_price_value in zip(row_bin2, wave_bin2):
|
||||||
|
X_parameter.append([float(single_square_feet)])
|
||||||
|
Y_parameter.append(float(single_price_value))
|
||||||
|
|
||||||
|
return X_parameter, Y_parameter
|
||||||
|
|
||||||
|
|
||||||
|
def plot(x, y, regre):
|
||||||
|
plt.scatter(x, y, color='blue')
|
||||||
|
plt.plot(x, regre.predict(x), color='red', linewidth=4)
|
||||||
|
# plt.xticks(())
|
||||||
|
# plt.yticks(())
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def linearRegression(X_parameters, Y_parameters):#
|
||||||
|
regr = linear_model.LinearRegression()
|
||||||
|
regr.fit(X_parameters, Y_parameters)
|
||||||
|
|
||||||
|
# 绘图
|
||||||
|
plot(X_parameters, Y_parameters, regr)
|
||||||
|
|
||||||
|
return regr
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
x, y = get_data(r'D:\PycharmProjects\linear_regression\123.xlsx')
|
||||||
|
regr = linearRegression(x, y)
|
||||||
|
|
||||||
|
yPredicted = []
|
||||||
|
for i in x:
|
||||||
|
xxxx = regr.predict(i[0])
|
||||||
|
yPredicted.append(xxxx[0])
|
||||||
|
|
||||||
|
print("Intercept value ", regr.intercept_)
|
||||||
|
print("coefficient", regr.coef_)
|
Reference in New Issue
Block a user