多项式回归

简介: 机器学习中的多项式回归是一种用于解决回归问题的非线性模型。与线性回归不同,

机器学习中的多项式回归是一种用于解决回归问题的非线性模型。与线性回归不同,多项式回归可以拟合数据中的非线性关系。多项式回归的基本形式如下:y = a0 + a1x1^n1 + a2x2^n2 +... + an*xn^nn 其中,y 是我们的输出变量,x1, x2,..., xn 是我们的输入变量,a0, a1,..., an 是我们需要学习的权重,n1, n2,..., nn 是多项式的阶数。为了使用多项式回归模型,我们需要完成以下步骤:1. 收集数据:收集一组包含输入变量和输出变量的数据集。这些数据可以是实验室测量值、历史数据或现实世界中的观测值。2. 数据预处理:处理数据中的异常值、缺失值,并将连续变量标准化(例如归一化)以提高模型性能。3. 划分数据集:将数据集划分为训练集和测试集。训练集用于训练模型,而测试集用于评估模型性能。4. 训练模型:使用训练集数据,通过最小化代价函数(如均方误差,MSE)来调整模型参数(权重和偏差)。5. 评估模型:使用测试集数据,评估模型的性能。如果性能不佳,可以调整学习率、迭代次数等超参数,或尝试使用其他模型。6. 应用模型:将训练好的模型应用于新数据,进行预测。总之,多项式回归是一种非线性的机器学习模型,可以用于解决回归问题。通过收集数据、预处理数据、划分数据集、训练模型、评估模型和应用模型等步骤,我们可以使用多项式回归模型来预测连续值。


Queue of text from file
The previous notebook (Concept 09) introduced queues. Let's see how we can use them with real world data.

Download a corpus of text.

$ wget http://norvig.com/big.txt
Create a queue of filenames:

import tensorflow as tf

filename_queue = tf.train.string_input_producer(["big.txt"])
Define an op to dequeue a line from file:

reader = tf.TextLineReader()
key_op, value_op = reader.read(filename_queue)
Start all queue runners collected in the graph:

sess = tf.InteractiveSession()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
Try reading lines from the file by dequeuing:

for i in range(100):
    key, value = sess.run([key_op, value_op])
    print(key, value)
b'big.txt:1' b'The Project Gutenberg EBook of The Adventures of Sherlock Holmes'
b'big.txt:2' b'by Sir Arthur Conan Doyle'
b'big.txt:3' b'(#15 in our series by Sir Arthur Conan Doyle)'
b'big.txt:4' b''
b'big.txt:5' b'Copyright laws are changing all over the world. Be sure to check the'
b'big.txt:6' b'copyright laws for your country before downloading or redistributing'
b'big.txt:7' b'this or any other Project Gutenberg eBook.'
b'big.txt:8' b''
b'big.txt:9' b'This header should be the first thing seen when viewing this Project'
b'big.txt:10' b'Gutenberg file.  Please do not remove it.  Do not change or edit the'
b'big.txt:11' b'header without written permission.'
b'big.txt:12' b''
b'big.txt:13' b'Please read the "legal small print," and other information about the'
b'big.txt:14' b'eBook and Project Gutenberg at the bottom of this file.  Included is'
b'big.txt:15' b'important information about your specific rights and restrictions in'
b'big.txt:16' b'how the file may be used.  You can also find out about how to make a'
b'big.txt:17' b'donation to Project Gutenberg, and how to get involved.'
b'big.txt:18' b''
b'big.txt:19' b''
b'big.txt:20' b'**Welcome To The World of Free Plain Vanilla Electronic Texts**'
b'big.txt:21' b''
b'big.txt:22' b'**eBooks Readable By Both Humans and By Computers, Since 1971**'
b'big.txt:23' b''
b'big.txt:24' b'*****These eBooks Were Prepared By Thousands of Volunteers!*****'
b'big.txt:25' b''
b'big.txt:26' b''
b'big.txt:27' b'Title: The Adventures of Sherlock Holmes'
b'big.txt:28' b''
b'big.txt:29' b'Author: Sir Arthur Conan Doyle'
b'big.txt:30' b''
b'big.txt:31' b'Release Date: March, 1999  [EBook #1661]'
b'big.txt:32' b'[Most recently updated: November 29, 2002]'
b'big.txt:33' b''
b'big.txt:34' b'Edition: 12'
b'big.txt:35' b''
b'big.txt:36' b'Language: English'
b'big.txt:37' b''
b'big.txt:38' b'Character set encoding: ASCII'
b'big.txt:39' b''
b'big.txt:40' b'*** START OF THE PROJECT GUTENBERG EBOOK, THE ADVENTURES OF SHERLOCK HOLMES ***'
b'big.txt:41' b''
b'big.txt:42' b''
b'big.txt:43' b''
b'big.txt:44' b''
b'big.txt:45' b'(Additional editing by Jose Menendez)'
b'big.txt:46' b''
b'big.txt:47' b''
b'big.txt:48' b''
b'big.txt:49' b'THE ADVENTURES OF'
b'big.txt:50' b'SHERLOCK HOLMES'
b'big.txt:51' b''
b'big.txt:52' b'BY'
b'big.txt:53' b''
b'big.txt:54' b'SIR ARTHUR CONAN DOYLE'
b'big.txt:55' b''
b'big.txt:56' b'CONTENTS'
b'big.txt:57' b''
b'big.txt:58' b'I.\tA Scandal in Bohemia'
b'big.txt:59' b'II.\tThe Red-Headed League'
b'big.txt:60' b'III.\tA Case of Identity'
b'big.txt:61' b'IV.\tThe Boscombe Valley Mystery'
b'big.txt:62' b'V.\tThe Five Orange Pips'
b'big.txt:63' b'VI.\tThe Man with the Twisted Lip'
b'big.txt:64' b'VII.\tThe Adventure of the Blue Carbuncle'
b'big.txt:65' b'VIII.\tThe Adventure of the Speckled Band'
b'big.txt:66' b"IX.\tThe Adventure of the Engineer's Thumb"
b'big.txt:67' b'X.\tThe Adventure of the Noble Bachelor'
b'big.txt:68' b'XI.\tThe Adventure of the Beryl Coronet'
b'big.txt:69' b'XII.\tThe Adventure of the Copper Beeches'
b'big.txt:70' b''
b'big.txt:71' b''
b'big.txt:72' b'ADVENTURE  I.  A SCANDAL IN BOHEMIA'
b'big.txt:73' b''
b'big.txt:74' b'I.'
b'big.txt:75' b''
b'big.txt:76' b''
b'big.txt:77' b"To Sherlock Holmes she is always the woman. I have seldom heard him mention her under any other name. In his eyes she eclipses and predominates the whole of her sex. It was not that he felt any emotion akin to love for Irene Adler. All emotions, and that one particularly, were abhorrent to his cold, precise but admirably balanced mind. He was, I take it, the most perfect reasoning and observing machine that the world has seen, but as a lover he would have placed himself in a false position. He never spoke of the softer passions, save with a gibe and a sneer. They were admirable things for the observer--excellent for drawing the veil from men's motives and actions. But for the trained reasoner to admit such intrusions into his own delicate and finely adjusted temperament was to introduce a distracting factor which might throw a doubt upon all his mental results. Grit in a sensitive instrument, or a crack in one of his own high-power lenses, would not be more disturbing than a strong emotion in a nature such as his. And yet there was but one woman to him, and that woman was the late Irene Adler, of dubious and questionable memory."
b'big.txt:78' b''
b'big.txt:79' b'I had seen little of Holmes lately. My marriage had drifted us away from each other. My own complete happiness, and the home-centred interests which rise up around the man who first finds himself master of his own establishment, were sufficient to absorb all my attention, while Holmes, who loathed every form of society with his whole Bohemian soul, remained in our lodgings in Baker Street, buried among his old books, and alternating from week to week between cocaine and ambition, the drowsiness of the drug, and the fierce energy of his own keen nature. He was still, as ever, deeply attracted by the study of crime, and occupied his immense faculties and extraordinary powers of observation in following out those clues, and clearing up those mysteries which had been abandoned as hopeless by the official police. From time to time I heard some vague account of his doings: of his summons to Odessa in the case of the Trepoff murder, of his clearing up of the singular tragedy of the Atkinson brothers at Trincomalee, and finally of the mission which he had accomplished so delicately and successfully for the reigning family of Holland. Beyond these signs of his activity, however, which I merely shared with all the readers of the daily press, I knew little of my former friend and companion.'
b'big.txt:80' b''
b'big.txt:81' b'One night--it was on the twentieth of March, 1888--I was returning from a journey to a patient (for I had now returned to civil practice), when my way led me through Baker Street. As I passed the well-remembered door, which must always be associated in my mind with my wooing, and with the dark incidents of the Study in Scarlet, I was seized with a keen desire to see Holmes again, and to know how he was employing his extraordinary powers. His rooms were brilliantly lit, and, even as I looked up, I saw his tall, spare figure pass twice in a dark silhouette against the blind. He was pacing the room swiftly, eagerly, with his head sunk upon his chest and his hands clasped behind him. To me, who knew his every mood and habit, his attitude and manner told their own story. He was at work again. He had risen out of his drug-created dreams and was hot upon the scent of some new problem. I rang the bell and was shown up to the chamber which had formerly been in part my own.'
b'big.txt:82' b''
b'big.txt:83' b'His manner was not effusive. It seldom was; but he was glad, I think, to see me. With hardly a word spoken, but with a kindly eye, he waved me to an armchair, threw across his case of cigars, and indicated a spirit case and a gasogene in the corner. Then he stood before the fire and looked me over in his singular introspective fashion.'
b'big.txt:84' b''
b'big.txt:85' b'"Wedlock suits you," he remarked. "I think, Watson, that you have put on seven and a half pounds since I saw you."'
b'big.txt:86' b''
b'big.txt:87' b'"Seven!" I answered.'
b'big.txt:88' b''
b'big.txt:89' b'"Indeed, I should have thought a little more. Just a trifle more, I fancy, Watson. And in practice again, I observe. You did not tell me that you intended to go into harness."'
b'big.txt:90' b''
b'big.txt:91' b'"Then, how do you know?"'
b'big.txt:92' b''
b'big.txt:93' b'"I see it, I deduce it. How do I know that you have been getting yourself very wet lately, and that you have a most clumsy and careless servant girl?"'
b'big.txt:94' b''
b'big.txt:95' b'"My dear Holmes," said I, "this is too much. You would certainly have been burned, had you lived a few centuries ago. It is true that I had a country walk on Thursday and came home in a dreadful mess, but as I have changed my clothes I can\'t imagine how you deduce it. As to Mary Jane, she is incorrigible, and my wife has given her notice, but there, again, I fail to see how you work it out."'
b'big.txt:96' b''
b'big.txt:97' b'He chuckled to himself and rubbed his long, nervous hands together.'
b'big.txt:98' b''
b'big.txt:99' b'"It is simplicity itself," said he; "my eyes tell me that on the inside of your left shoe, just where the firelight strikes it, the leather is scored by six almost parallel cuts. Obviously they have been caused by someone who has very carelessly scraped round the edges of the sole in order to remove crusted mud from it. Hence, you see, my double deduction that you had been out in vile weather, and that you had a particularly malignant boot-slitting specimen of the London slavey. As to your practice, if a gentleman walks into my rooms smelling of iodoform, with a black mark of nitrate of silver upon his right forefinger, and a bulge on the right side of his top-hat to show where he has secreted his stethoscope, I must be dull, indeed, if I do not pronounce him to be an active member of the medical profession."'
b'big.txt:100' b''
目录
相关文章
|
5月前
|
机器学习/深度学习 算法 数据挖掘
【MATLAB】数据拟合第10期-二阶多项式的局部加权回归拟合算法
【MATLAB】数据拟合第10期-二阶多项式的局部加权回归拟合算法
49 0
|
6月前
MATALB运用——最小二乘法拟合
MATALB运用——最小二乘法拟合
93 0
|
机器学习/深度学习 数据可视化 Python
逻辑回归那些事—使用牛顿法解决实际问题
逻辑回归是机器学习中的重要章节,本文将带你从公式推导到算法实现详细讲述这部分内容,想学习这个高大上的技能么,快来看吧!!!
5409 0
|
14天前
R语言多项式线性模型:最大似然估计二次曲线
R语言多项式线性模型:最大似然估计二次曲线
12 0
|
13天前
|
数据采集
R语言用线性模型进行臭氧预测: 加权泊松回归,普通最小二乘,加权负二项式模型,多重插补缺失值
R语言用线性模型进行臭氧预测: 加权泊松回归,普通最小二乘,加权负二项式模型,多重插补缺失值
11 0
|
13天前
使用R语言进行多项式回归、非线性回归模型曲线拟合
使用R语言进行多项式回归、非线性回归模型曲线拟合
12 1
|
13天前
|
数据可视化
R语言多项式回归拟合非线性关系
R语言多项式回归拟合非线性关系
20 0
R语言多项式回归拟合非线性关系
|
14天前
|
C++
拟合R语言中的多项式回归
拟合R语言中的多项式回归
|
8月前
|
机器学习/深度学习 算法
非线性世界的探索:多项式回归解密
非线性世界的探索:多项式回归解密
|
机器学习/深度学习
PRML 1.1 多项式曲线拟合
PRML 1.1 多项式曲线拟合
PRML 1.1 多项式曲线拟合