title: Getting good accuracy but very low precision for classification task on an unbalanced dataset
body: <p>I have an unbalanced dataset , where the positive class is about 10,000 entries and the negative class is some 8,00,000 entries. I am trying a simple scikit's LogisticRegression model as a base line model, with class_weight='balanced' (hopefully unbalanced problem should be solved?).</p>
  
  <p>However, I am getting an accuracy score of 0.83, but a precision score of 0.03. What could be the issue? Do I need to handle the unbalanced part separately?</p>
  
  <p>This is my current code:</p>
  
  <pre><code>&gt;&gt;&gt; train = []
  &gt;&gt;&gt; target = []
  &gt;&gt;&gt; len(posList)
  ... 10214
  &gt;&gt;&gt; len(negList)
  ... 831134
  &gt;&gt;&gt; for entry in posList:
  ...     train.append(entry)
  ...     target.append(1)
  ...
  &gt;&gt;&gt; for entry in negList:
  ...     train.append(entry)
  ...     target.append(-1)
  ...
  &gt;&gt;&gt; train = np.array(train)
  &gt;&gt;&gt; target = np.array(target)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; X_train, X_test, y_train, y_test = train_test_split(train, target, test_size=0.3, random_state=42)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; model = LogisticRegression(class_weight='balanced')
  &gt;&gt;&gt; model.fit(X_train, y_train)
  LogisticRegression(C=1.0, class_weight='balanced', 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)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; predicted = model.predict(X_test)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; metrics.accuracy_score(y_test, predicted)
  0.835596671213
  &gt;&gt;&gt; 
  &gt;&gt;&gt; metrics.precision_score(y_test, predicted, average='weighted')
  /usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.py:976: DeprecationWarning: From version 0.18, binary input will not be handled specially when using averaged precision/recall/F-score. Please use average='binary' to report only the positive class performance.
    'positive class performance.', DeprecationWarning)
  0.033512518766
  </code></pre>