Advertisement
Fhernd

p1-2.py

Mar 20th, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn import linear_model
  3.  
  4. Stock_Market = {
  5. 'Year': [2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2016,2016,2016,2016,2016,2016,
  6. 2016,2016,2016,2016,2016,2016],
  7. 'Month': [12, 11,10,9,8,7,6,5,4,3,2,1,12,11,10,9,8,7,6,5,4,3,2,1],
  8. 'Interest Rate': [2.75,2.5,2.5,2.5,2.5,2.5,2.5,2.25,2.25,2.25,2,2,2,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75],
  9. 'Unemployment Rate': [5.3,5.3,5.3,5.3,5.4,5.6,5.5,5.5,5.5,5.6,5.7,5.9,6,5.9,5.8,6.1,6.2,6.1,6.1,6.1,5.9,6.2,6.2,6.1],
  10. 'Stock Index Price': [1464,1394,1357,1293,1256,1254,1234,1195,1159,1167,1130,1075,1047,965,943,958,971,949,
  11. 884,866,876,822,704,719]
  12. }
  13.  
  14. def calcular_regresion_lineal_multiple(datos):
  15.    
  16.     market = pd.DataFrame(datos, columns=['Year', 'Month', 'Interest Rate', 'Unemployment Rate', 'Stock Index Price'])
  17.  
  18.     X = market[['Interest Rate', 'Unemployment Rate']]
  19.     Y = market['Stock Index Price']
  20.  
  21.     regresion = linear_model.LinearRegression()
  22.     regresion.fit(X, Y)
  23.  
  24.     print("Intercepto: {} / Coeficientes {}".format(regresion.intercept_, regresion.coef_))
  25.  
  26.  
  27. calcular_regresion_lineal_multiple(Stock_Market)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement