Fhernd icon

p1-2.py

Fhernd | PRO | 03/21/19 01:57:02 AM UTC | 0 ⭐ | 1147 👁️ | Never ⏰ | []
Python |

1.12 KB

|

None

|

0 👍

/

0 👎

import pandas as pd
from sklearn import linear_model
 
Stock_Market = {
'Year': [2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2016,2016,2016,2016,2016,2016,
2016,2016,2016,2016,2016,2016],
'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],
'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],
'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],
'Stock Index Price': [1464,1394,1357,1293,1256,1254,1234,1195,1159,1167,1130,1075,1047,965,943,958,971,949,
884,866,876,822,704,719]
}
 
def calcular_regresion_lineal_multiple(datos):
    
    market = pd.DataFrame(datos, columns=['Year', 'Month', 'Interest Rate', 'Unemployment Rate', 'Stock Index Price'])
 
    X = market[['Interest Rate', 'Unemployment Rate']]
    Y = market['Stock Index Price']
 
    regresion = linear_model.LinearRegression()
    regresion.fit(X, Y)
 
    print("Intercepto: {} / Coeficientes {}".format(regresion.intercept_, regresion.coef_))
 
 
calcular_regresion_lineal_multiple(Stock_Market)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎