Using logistic regression to predict the parameter value
<p>I have written vary basic sklearn code using logistic regression to predict the value. </p>

<p>Training data looks like - </p>

<p><a href="https://gist.github.com/anonymous/563591e0395e8d988277d3ce63d7438f" rel="nofollow">https://gist.github.com/anonymous/563591e0395e8d988277d3ce63d7438f</a></p>

<pre><code>date    hr_of_day   vals
01/05/2014  9   929
01/05/2014  10  942
01/05/2014  11  968
01/05/2014  12  856
01/05/2014  13  835
01/05/2014  14  885
01/05/2014  15  945
01/05/2014  16  924
01/05/2014  17  914
01/05/2014  18  744
01/05/2014  19  377
01/05/2014  20  219
01/05/2014  21  106
</code></pre>

<p>and I have selected first 8 items from training data to just validate the classifier which is </p>

<p>I  want to predict the value of <code>vals</code>, in testing data, I have put it as <code>0</code>. Is that correct?</p>

<pre><code>date    hr_of_day   vals
2014-05-01  0   0
2014-05-01  1   0
2014-05-01  2   0
2014-05-01  3   0
2014-05-01  4   0
2014-05-01  5   0
2014-05-01  6   0
2014-05-01  7   0
</code></pre>

<p>My model code, works fine. But my result looks trange. I was expecting value of <code>vals</code> in result. Rather then that, I am getting large matrix with all element value as <code>0.00030676</code>.</p>

<p>I appreciate if someone can give details or help me to play better with this result.</p>

<pre><code>import pandas as pd
from sklearn import datasets
from sklearn import metrics
from sklearn.linear_model import LogisticRegression
from datetime import datetime, date, timedelta
Train = pd.read_csv("data_scientist_assignment.tsv", sep='\t', parse_dates=['date'])
Train['timestamp'] = Train.date.values.astype(pd.np.int64)
x1=["timestamp", "hr_of_day"]
test=pd.read_csv("test.tsv", sep='\t', parse_dates=['date'])
test['timestamp'] = test.date.values.astype(pd.np.int64)
print(Train.columns)
print(test.columns)
model = LogisticRegression()
model.fit(Train[x1], Train["vals"])
print(model)
print model.score(Train[x1], Train["vals"])
print model.predict_proba(test[x1])
</code></pre>

<p>results looks like this:</p>

<pre><code>In [92]: print(model)
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,
          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,
          verbose=0, warm_start=False)

In [93]: print model.score(Train[x1], Train["vals"])
0.00520833333333

In [94]: 

In [94]: print model.predict_proba(test[x1])
[[ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]
 [ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]
 [ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]
 ..., 
 [ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]
 [ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]
 [ 0.00030676  0.00030676  0.00030676 ...,  0.00030889  0.00030885
   0.00030902]]
</code></pre>

<ol>
<li>You are using <strong><em>predict_proba()</em></strong> which gives class probabilities, instead of that you should use <strong><em>predict()</em></strong> function.</li>
<li>You are using a <strong><em>wrong model</em></strong>. The target variable in your data has <strong>continuous data</strong>, therefore you will have to use <strong>linear regression</strong>. 
<strong>Logistic Regression</strong> actually works as a <strong>classifier</strong> and classification tasks require discrete data(as in fixed number of labels).</li>
</ol>

python machine-learning scikit-learn classification logistic-regression