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)的更多相关文章

  1. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  2. (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探

    目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...

  3. [机器学习Lesson4]多元线性回归

    1. 多元线性回归定义 多元线性回归也被称为多元线性回归. 我们现在介绍方程的符号,我们可以有任意数量的输入变量. 这些多个特征的假设函数的多变量形式如下: hθ(x)=θ0+θ1x1+θ2x2+θ3 ...

  4. 利用TensorFlow实现多元线性回归

    利用TensorFlow实现多元线性回归,代码如下: # -*- coding:utf-8 -*- import tensorflow as tf import numpy as np from sk ...

  5. Scikit Learn: 在python中机器学习

    转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...

  6. 机器学习——Day 3 多元线性回归

    写在开头 由于某些原因开始了机器学习,为了更好的理解和深入的思考(记录)所以开始写博客. 学习教程来源于github的Avik-Jain的100-Days-Of-MLCode 英文版:https:// ...

  7. Tensorflow之多元线性回归问题(以波士顿房价预测为例)

    一.根据波士顿房价信息进行预测,多元线性回归+特征数据归一化 #读取数据 %matplotlib notebook import tensorflow as tf import matplotlib. ...

  8. 100天搞定机器学习|Day3多元线性回归

    前情回顾 [第二天100天搞定机器学习|Day2简单线性回归分析][1],我们学习了简单线性回归分析,这个模型非常简单,很容易理解.实现方式是sklearn中的LinearRegression,我们也 ...

  9. R语言解读多元线性回归模型

    转载:http://blog.fens.me/r-multi-linear-regression/ 前言 本文接上一篇R语言解读一元线性回归模型.在许多生活和工作的实际问题中,影响因变量的因素可能不止 ...

随机推荐

  1. jsp另外五大内置对象之response-操作重定向

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  2. POJ 1651 Multiplication Puzzle (区间DP,经典)

    题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...

  3. 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector

    题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her s ...

  4. Android(java)学习笔记117:SharedPreferences(轻量级存储类)

    1.SharedPreferences是Android平台上一个轻量级的存储类,简单的说就是可以存储一些我们需要的变量信息.2个activity 之间的数据传递除了可以他通过intent来传递数据,还 ...

  5. Python-OpenCV中图像合并显示

    在图像处理中,我们通常需要将原图像与处理后的图像放在同一个窗口显示,这样便于比较. 首先,需要介绍Numpy中的两个函数:hstack().vstack(). 函数原型:hstack(tup) ,参数 ...

  6. 校招准备-关系型数据库与nosql

    深入理解常见的数据库的设计架构, 其中用到的数据结构, 算法等 SQL执行流程和优化, 可以了解一下calcite: https://calcite.apache.org/

  7. Oracle Real Application Clusters (RAC)

    Oracle Real Application Clusters — 概述 包含 Oracle Real Application Clusters (RAC) 选件的 Oracle 数据库允许依托一组 ...

  8. JDK安装及环境变量配置详解

    一.下载(Jdk 1.8 ) 1.下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151 ...

  9. 作业题:闰年 if((year%4==0&&year%100!=0)||year&400==0)

    作业题:闰年 if((year%4==0&&year%100!=0)||year&400==0)

  10. 禅与 Objective-C 编程艺术(Zen and the Art of the Objective-C Craftsmanship)

    英文版Zen and the Art of the Objective-C Craftsmanshiphttps://github.com/objc-zen/objc-zen-book 中文版禅与 O ...