In [1]:
import ext_datos as ext
import pandas as pd
import matplotlib.pyplot as plt
import procesar as pr
import rellenar as re

In [2]:
data = ext.extraer_data('dia2')


1
2
4
5
1
5
2
2
1
4
4
5
3
4
3
1
3
1
5
2

In [3]:
motores = pr.procesar(data)

In [5]:
motoresTest=motores.dropna()

In [21]:
len(motores)


Out[21]:
208236

In [22]:
motoresTest=motoresTest[['busVoltage_m1','busVoltage_m2']]
motoresTest=motoresTest.reindex(np.random.permutation(motoresTest.index))

In [23]:
motor1=motoresTest['busVoltage_m1']
motor2=motoresTest['busVoltage_m2']

In [24]:
from sklearn import linear_model

In [25]:
motor1test=motor1[:len(motor1)/2]
motor2test=motor2[:len(motor2)/2]
motor1val=motor1[len(motor1)/2:]
motor2val=motor2[len(motor2)/2:]

In [26]:
xx = motor1test.reshape((motor1test.shape[0],-1))
yy = motor2test.reshape((motor2test.shape[0],-1))
xt = motor1val.reshape((motor1val.shape[0],-1))
yt = motor2val.reshape((motor2val.shape[0],-1))

In [27]:
regr = linear_model.LinearRegression()

In [28]:
regr.fit(xx,yy)


Out[28]:
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)

In [29]:
print(regr.coef_,regr.intercept_)


(array([[ 1.00212909]]), array([-0.3345311]))

In [30]:
np.mean((regr.predict(xt)-yt)**2)


Out[30]:
0.56373398610309999

In [31]:
regr.score(xt, yt)


Out[31]:
0.9972757018507804

In [32]:
plt.scatter(xt,yt,  color='black')
plt.plot(xt, regr.predict(xt), color='blue',linewidth=3)

plt.show()



In [ ]:
np.array([regr.intercept_[0], regr.coef_[0]])

In [33]:
ecuacion_lineal_voltaje_m2=re.regresion_lineal(motores,'busVoltage_m1','busVoltage_m2')


la ecuacion de regresion lineal es: -0.325004 + 1.002095x
el error cuadratico medio es: 0.618875, (menor valor es mejor ajuste)
la varianza es: 0.997111, (1 significa prediccion perfecta)

In [34]:
ecuacion_lineal_voltaje_m1=re.regresion_lineal(motores,'busVoltage_m2','busVoltage_m1')


la ecuacion de regresion lineal es: 0.873353 + 0.994329x
el error cuadratico medio es: 0.580611, (menor valor es mejor ajuste)
la varianza es: 0.997305, (1 significa prediccion perfecta)

In [35]:
ecuacion_lineal_corriente_m2=re.regresion_lineal(motores,'busCurrent_m1','busCurrent_m2')


la ecuacion de regresion lineal es: -0.187912 + 0.814952x
el error cuadratico medio es: 2.498282, (menor valor es mejor ajuste)
la varianza es: 0.927576, (1 significa prediccion perfecta)

In [36]:
ecuacion_lineal_corriente_m1=re.regresion_lineal(motores,'busCurrent_m2','busCurrent_m1')


la ecuacion de regresion lineal es: 0.407470 + 1.129005x
el error cuadratico medio es: 3.493346, (menor valor es mejor ajuste)
la varianza es: 0.927422, (1 significa prediccion perfecta)

In [ ]:
motortest=motores[motores['busVoltage_m2'].isnull()]['busVoltage_m2']
motortest=ecuacion_lineal_voltaje_m2[0]+ecuacion_lineal_voltaje_m2[1]*motores[motores['busVoltage_m2'].isnull()]['busVoltage_m1']

In [ ]:
series=motores
series['busVoltage_m2'][series['busVoltage_m2'].isnull()].replace(motortest,inplace=True)

In [ ]:
motores['busVoltage_m2']

In [ ]: