多元线性回归(pandas/scikit-learn)
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LinearRegression #数据1
tem16_1 = [3113,3122,3131,3137,3146,3149,3157,3166,3172,3178,3172,3151,3137,3131,3128,3107,3095,3081,3070,3049,3038,3023,3011,2997,2988,2985,2974,2957,2942,2928,2916,2901,2887,2884,2879,2870,2856,2848,2836,2828,2810,2802,2793,2785,2776,2768,2762,2756,2762,2765,2762,2771,2748,2731,2708,2697,2674,2697,2702,2725,2737,2759,2771,2787,2802,2819,2833,2845,2856,2859,2873,2879,2896,2898,2910,2922,2933,2945,2957,2968,2980,2985,3000,3011,3023,3038,3046,3058,3070,3072,3084,3090,3098,3107,3119,3122,3131,3134,3140,3143,3149,3154,3151,3166,3189,3178,3181,3169,3166,3169,3154,3137,3116,3107,3090,3093,3087,3075,3052,3038,3026,3017,3008,3002,2994,2991,2988,2977,2957,2951,2936,2931,2936,2957,2980,2962,2948,2928,2913,2898,2879,2867,2865,2856,2853,2848,2842,2833,2830,2819,2813,2807,2799,2796,2787,2785,2779,2773]
#数据2
tem16_2 = [4185,4209,4233,4256,4279,4303,4326,4349,4372,4398,4421,4414,4387,4383,4360,4349,4326,4303,4279,4264,4233,4209,4185,4161,4113,4088,4064,4043,4019,4023,4002,3978,3954,3933,3912,3891,3870,3845,3824,3802,3781,3759,3715,3693,3671,3648,3626,3603,3580,3534,3507,3496,3490,3467,3451,3429,3419,3432,3454,3464,3486,3496,3518,3542,3565,3588,3611,3633,3656,3678,3700,3722,3744,3766,3788,3809,3831,3873,3895,3919,3940,3964,3988,4010,4039,4060,4084,4108,4133,4157,4181,4205,4228,4252,4276,4299,4322,4345,4368,4391,4414,4436,4458,4455,4470,4485,4462,4458,4451,4447,4425,4402,4387,4364,4368,4349,4326,4307,4287,4264,4240,4221,4225,4197,4177,4169,4149,4133,4113,4088,4064,4043,4019,3995,3985,3968,3947,3926,3905,3884,3863,3842,3820,3799,3777,3773,3759,3737,3715,3693,3671,3648,3626,3603,3576,3553,3530,3507]
#回归数据
result = [2364,2356,2356,2353,2353,2353,2353,2367,2367,2367,2383,2362,2435,2460,2427,2427,2451,2446,2424,2430,2407,2399,2386,2367,2372,2375,2364,2342,2326,2309,2285,2283,2288,2277,2285,2307,2329,2351,2372,2396,2421,2492,2312,2283,2280,2266,2253,2239,2234,2231,2247,2247,2242,2220,2198,2098,2034,2031,2053,2031,2093,2071,2093,2077,2142,2163,2185,2206,2215,2215,2215,2215,2217,2217,2217,2217,2217,2239,2239,2239,2256,2256,2256,2256,2274,2274,2274,2274,2293,2309,2293,2309,2331,2331,2331,2331,2331,2331,2331,2331,2331,2331,2356,2367,2380,2383,2386,2370,2378,2372,2351,2337,2320,2299,2293,2312,2334,2329,2323,2315,2304,2307,2301,2304,2290,2272,2256,2234,2237,2245,2266,2258,2261,2253,2266,2245,2223,2212,2215,2204,2198,2201,2223,2245,2261,2277,2269,2288,2290,2315,2261,2253,2266,2245,2223,2212,2215,2215]
#以DataFrame存储数据
data = pd.DataFrame([tem16_1,tem16_2,result],index=['tem16_1','tem16_2','result'])
data = data.T
X = data[['tem16_1','tem16_2']] y = data['result']
#测试集和训练集
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
#训练
linreg = LinearRegression()
linreg.fit(X_train, y_train)
#结果
print linreg.intercept_
print linreg.coef_
print zip(['tem16_1','tem16_2'], linreg.coef_)
多元线性回归(pandas/scikit-learn)的更多相关文章
- (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探
一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...
- (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探
目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...
- [机器学习Lesson4]多元线性回归
1. 多元线性回归定义 多元线性回归也被称为多元线性回归. 我们现在介绍方程的符号,我们可以有任意数量的输入变量. 这些多个特征的假设函数的多变量形式如下: hθ(x)=θ0+θ1x1+θ2x2+θ3 ...
- 利用TensorFlow实现多元线性回归
利用TensorFlow实现多元线性回归,代码如下: # -*- coding:utf-8 -*- import tensorflow as tf import numpy as np from sk ...
- Scikit Learn: 在python中机器学习
转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...
- 机器学习——Day 3 多元线性回归
写在开头 由于某些原因开始了机器学习,为了更好的理解和深入的思考(记录)所以开始写博客. 学习教程来源于github的Avik-Jain的100-Days-Of-MLCode 英文版:https:// ...
- Tensorflow之多元线性回归问题(以波士顿房价预测为例)
一.根据波士顿房价信息进行预测,多元线性回归+特征数据归一化 #读取数据 %matplotlib notebook import tensorflow as tf import matplotlib. ...
- 100天搞定机器学习|Day3多元线性回归
前情回顾 [第二天100天搞定机器学习|Day2简单线性回归分析][1],我们学习了简单线性回归分析,这个模型非常简单,很容易理解.实现方式是sklearn中的LinearRegression,我们也 ...
- R语言解读多元线性回归模型
转载:http://blog.fens.me/r-multi-linear-regression/ 前言 本文接上一篇R语言解读一元线性回归模型.在许多生活和工作的实际问题中,影响因变量的因素可能不止 ...
随机推荐
- HTTP、HTTP2.0、HTTPS、SPDY
本文原链接:https://cloud.tencent.com/developer/article/1082516 HTTP,HTTP2.0,SPDY,HTTPS你应该知道的一些事 1.web始祖HT ...
- js类型判别大合集
1.typeof number,string,boolean,undefined,symbol,object,function 对象中除了函数为function,其他对象都判别为object, 缺陷: ...
- java基础—基础语法1
一.标识符
- Java基础面试操作题: File IO 文件过滤器FileFilter 练习 把一个文件夹下的.java文件复制到另一个文件夹下的.txt文件
package com.swift; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File ...
- Xcode 的expression命令
expression命令是执行一个表达式,并将表达式返回的结果输出,是LLDB调试命令中最重要的命令,也是我们常用的 p 和 po 命令的 鼻祖. 他主要有2个功能 (1) 执行表达式 举例:改变视图 ...
- cocos2x (c++/lua) spine 文件的预加载
在之前,笔者写过一编博客,通过lua在加载场景加载spineAnimation动画精灵,保存在table中,然后在游戏中创建动画精灵时,提取加载好的spineAnimaiton中的 spSkeleto ...
- 【模板】树套树(线段树套Splay)
如题,这是一个模板... #include <algorithm> #include <iostream> #include <cstring> #include ...
- Java AES加密解密工具 -- GUI 、在线传输文件
原理 对于任意长度的明文,AES首先对其进行分组,每组的长度为128位.分组之后将分别对每个128位的明文分组进行加密. 对于每个128位长度的明文分组的加密过程如下: (1)将128位AES ...
- 科学计算库Numpy——numpy.ndarray
创建ndarray 元素类型 对于ndarray结构来说,里面所有的元素必须是同一类型的,如果不是的话,会自动的向下进行转换. 元素类型所占字节数 数组维数 元素个数 数组的维度 数组中填充固定值 索 ...
- Python中的端口协议之基于UDP协议的通信传输
UDP协议: 1.python中基于udp协议的客户端与服务端通信简单过程实现 2.udp协议的一些特点(与tcp协议的比较) 3.利用socketserver模块实现udp传输协议的并 ...