Hackerrank Day 9: Multiple Linear Regression

Multiple Regression in Python

from sklearn import linear_model
x = [[5, 7], [6, 6], [7, 4], [8, 5], [9, 6]]
y = [10, 20, 60, 40, 50]
lm = linear_model.LinearRegression()
lm.fit(x, y)
a = lm.intercept_
b = lm.coef_
print a, b[0], b[1]

Running the above code produces the following output:

51.9534883721 6.6511627907 -11.1627906977

CODING TEST:

Sample Input

2 7
0.18 0.89 109.85
1.0 0.26 155.72
0.92 0.11 137.66
0.07 0.37 76.17
0.85 0.16 139.75
0.99 0.41 162.6
0.87 0.47 151.77
4
0.49 0.18
0.57 0.83
0.56 0.64
0.76 0.18

Sample Output

105.22
142.68
132.94
129.71

line1=list(map(int,input().split()))
m=line1[0]
n=line1[1]
X=[]
Y=[]
for i in range(n):
    line=list(map(float,input().split()))
    X.append(line[:m])
    Y.append(line[m])

from sklearn import linear_model
lm = linear_model.LinearRegression()
lm.fit(X, Y)

a = lm.intercept_
b = lm.coef_
#print a, b[0], b[1]
import numpy as np

n1=int(input())


for j in range(n1):
    line=list(map(float,input().split()))
    y=a+np.dot(line,b) 
    print(round(y,2))

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值