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]:
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]:
In [29]:
print(regr.coef_,regr.intercept_)
In [30]:
np.mean((regr.predict(xt)-yt)**2)
Out[30]:
In [31]:
regr.score(xt, yt)
Out[31]:
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')
In [7]:
In [58]:
ecuacion_lineal_voltaje_m1=re.regresion_lineal(motores,'busVoltage_m2','busVoltage_m1')
In [59]:
ecuacion_lineal_corriente_m1=re.regresion_lineal(motores,'busCurrent_m2','busCurrent_m1')
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]:
In [62]:
np.trapz(Potencia.values, x=None, dx=0.2)
Out[62]:
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]:
In [ ]:
np.trapz(PotenciaEst.values, x=None, dx=0.2)