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')

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

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

In [5]:
import chartkick

In [21]:



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 [4]:
ecuacion_lineal_voltaje_m2=re.regresion_lineal(motores,'busVoltage_m1','busVoltage_m2')


la ecuacion de regresion lineal es: -0.448088 + 1.002858x
el error cuadratico medio es: 0.581786, (menor valor es mejor ajuste)
la varianza es: 0.997300, (1 significa prediccion perfecta)

In [7]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-368e828df2db> in <module>()
----> 1 re.score

AttributeError: 'module' object has no attribute 'score'

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


la ecuacion de regresion lineal es: 0.784864 + 0.994863x
el error cuadratico medio es: 0.581063, (menor valor es mejor ajuste)
la varianza es: 0.997191, (1 significa prediccion perfecta)

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


la ecuacion de regresion lineal es: 0.406216 + 1.132608x
el error cuadratico medio es: 3.526157, (menor valor es mejor ajuste)
la varianza es: 0.925885, (1 significa prediccion perfecta)

In [60]:
motorTest=motores.dropna()

In [61]:
Potencia=motorTest.busCurrent_m1*motorTest.busVoltage_m1+motorTest.busCurrent_m2*motorTest.busVoltage_m2

In [18]:
from scipy import integrate
import pandas as pd
import numpy as np

def integrate_method(self, how='trapz', unit='s'):
    '''Numerically integrate the time series.

    @param how: the method to use (trapz by default)
    @return 

    Available methods:
     * trapz - trapezoidal
     * cumtrapz - cumulative trapezoidal
     * simps - Simpson's rule
     * romb - Romberger's rule

    See http://docs.scipy.org/doc/scipy/reference/integrate.html for the method details.
    or the source code
    https://github.com/scipy/scipy/blob/master/scipy/integrate/quadrature.py
    '''
    available_rules = set(['trapz', 'cumtrapz', 'simps', 'romb'])
    if how in available_rules:
        rule = integrate.__getattribute__(how)
    else:
        print('Unsupported integration rule: %s' % (how))
        print('Expecting one of these sample-based integration rules: %s' % (str(list(available_rules))))
        raise AttributeError
    
    result = rule(self.values, self.index.astype(np.int64) / 10**9)
    #result = rule(self.values)
    return result

pd.TimeSeries.integrate = integrate_method

In [25]:
Potencia.integrate()


Out[25]:
20499512.706907701

In [62]:
np.trapz(Potencia.values, x=None, dx=0.2)


Out[62]:
9917028.8053125944

In [63]:
busVoltageEst = motorTest.busVoltage_m1*ecuacion_lineal_voltaje_m1[1]+ecuacion_lineal_voltaje_m1[0]

In [64]:
busCurrentEst = motorTest.busCurrent_m1*ecuacion_lineal_corriente_m1[1]+ecuacion_lineal_corriente_m1[0]

In [65]:
PotenciaEst=motorTest.busCurrent_m1*motorTest.busVoltage_m1+busVoltageEst*busCurrentEst

In [66]:
np.trapz(PotenciaEst.values, x=None, dx=0.2)


Out[66]:
13250955.452463975

In [ ]:
np.trapz(PotenciaEst.values, x=None, dx=0.2)