Adding Probability to the predicted value
<p>I have a testDF like this and try to make a binary classification [0;1]:</p>

<p><a href="http://i.stack.imgur.com/wTSmJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/wTSmJ.png" alt="enter image description here"></a></p>

<p>Also I have a trainDF with the same structured and with filled bad values in it for training purposes.</p>

<p>I make a target and train sets from trainDF:</p>

<pre><code>target = trainDF.bad.values
train = trainDF.drop('bad', axis=1).values
</code></pre>

<p>Then I append the logistic regression model and do the cross validation:</p>

<pre><code>model=[]
model.append (linear_model.LogisticRegression(C=1e5))
TRNtrain, TRNtest, TARtrain, TARtest = train_test_split(train, target,test_size=0.3, random_state=0)
</code></pre>

<p>Then fit on validated and do the preds:</p>

<pre><code>model.fit(TRNtrain, TARtrain)
pred_scr = model.predict_proba(TRNtest)[:, 1]
</code></pre>

<p>Then fit on the whole set and predict bad value:</p>

<pre><code>model.fit(train, target)
test = testDF.drop('bad', axis=1).values
testDF.bad=model.predict(test)
</code></pre>

<p>I receive a df with filled values:<a href="http://i.stack.imgur.com/G4nvN.png" rel="nofollow"><img src="http://i.stack.imgur.com/G4nvN.png" alt="enter image description here"></a></p>

<p>My question: How can I add the probability from logistic regression of bad value=1 in additional column? What steps should I take for that?</p>

<p>Any help would be greatly appreciated!</p>

<p>The <code>.predict</code> method selects the most probable assignment for your input.  If you want to access the probabilities you can use:</p>

<pre><code>log_prob = model.predict_log_proba(test)  # Log of probability estimates.
prob = model.predict_proba(test)   # Probability estimates.
</code></pre>

<p>You can add either of these directly to the data frame via columnar assignment.</p>

<pre><code>testDF['bad_prob'] = model.predict_proba(test)
</code></pre>

python pandas scikit-learn logistic-regression prediction