Simple prediction using linear regression with python

The first thing you have to do is split your data into two arrays, X and y. Each element of X will be a date, and the corresponding element of y will be the associated kwh.

Once you have that, you will want to use sklearn.linear_model.LinearRegression to do the regression. The documentation is here.

As for every sklearn model, there are two steps. First you must fit your data. Then, put the dates of which you want to predict the kwh in another array, X_predict, and predict the kwh using the predict method.

from sklearn.linear_model import LinearRegression

X = []  # put your dates in here
y = []  # put your kwh in here

model = LinearRegression()
model.fit(X, y)

X_predict = []  # put the dates of which you want to predict kwh here
y_predict = model.predict(X_predict)

Predict() function takes 2 dimensional array as arguments. So, If u want to predict the value for simple linear regression, then you have to issue the prediction value within 2 dimentional array like,

model.predict([[2012-04-13 05:55:30]]);

If it is a multiple linear regression then,

model.predict([[2012-04-13 05:44:50,0.327433]])