Skip to content

Commit

Permalink
0.14 release (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Nov 10, 2018
1 parent 8228ca2 commit ec38ea3
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The CHANGELOG for the current development version is available at

---

### Version 0.14.0dev (TBD)
### Version 0.14.0 (11-09-2018)

##### Downloads

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mlxtend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#
# License: BSD 3 clause

__version__ = '0.14.0dev'
__version__ = '0.14.0'
5 changes: 3 additions & 2 deletions mlxtend/evaluate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .holdout import PredefinedHoldoutSplit
from .f_test import ftest
from .f_test import combined_ftest_5x2cv

from .proportion_difference import proportion_difference


__all__ = ["scoring", "confusion_matrix",
Expand All @@ -36,4 +36,5 @@
"paired_ttest_kfold_cv", "paired_ttest_5x2cv",
"feature_importance_permutation",
"RandomHoldoutSplit", "PredefinedHoldoutSplit",
"ftest", "combined_ftest_5x2cv"]
"ftest", "combined_ftest_5x2cv",
"proportion_difference"]
51 changes: 51 additions & 0 deletions mlxtend/evaluate/proportion_difference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Sebastian Raschka 2014-2018
# mlxtend Machine Learning Library Extensions
#
# Author: Sebastian Raschka <sebastianraschka.com>
#
# License: BSD 3 clause

import numpy as np
import scipy.stats


def proportion_difference(proportion_1, proportion_2, n_1, n_2=None):
"""
Computes the test statistic and p-value for a difference of
proportions test.
Parameters
-----------
proportion_1 : float
The first proportion
proportion_2 : float
The second proportion
n_1 : int
The sample size of the first test sample
n_2 : int or None (default=None)
The sample size of the second test sample.
If `None`, `n_1`=`n_2`.
Returns
-----------
z, p : float or None, float
Returns the z-score and the p-value
Examples
-----------
For usage examples, please see
http://rasbt.github.io/mlxtend/user_guide/evaluate/proportion_difference/
"""
if n_2 is None:
n_2 = n_1

var_1 = proportion_1*(1. - proportion_1) / n_1
var_2 = proportion_2*(1. - proportion_2) / n_2

z = (proportion_1 - proportion_2) / np.sqrt(var_1 + var_2)
p = scipy.stats.norm.cdf(z)

return z, p
53 changes: 53 additions & 0 deletions mlxtend/evaluate/tests/test_proportion_difference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Sebastian Raschka 2014-2018
# mlxtend Machine Learning Library Extensions
# Author: Sebastian Raschka <sebastianraschka.com>
#
# License: BSD 3 clause

from mlxtend.evaluate import proportion_difference
import numpy as np


def test_on_dataset():
y_true = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0])

ym1 = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0])

ym2 = np.array([1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0])

ym3 = np.array([1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1])

acc_1 = np.sum(y_true == ym1) / y_true.shape[0]
acc_2 = np.sum(y_true == ym2) / y_true.shape[0]
acc_3 = np.sum(y_true == ym3) / y_true.shape[0]
assert round(acc_1, 2) == 0.84
assert round(acc_2, 2) == 0.92
assert round(acc_3, 2) == 0.92

z, p_value = proportion_difference(acc_1, acc_2, n_1=y_true.shape[0])
assert round(z, 3) == -1.754
assert round(p_value, 3) == 0.040

z, p_value = proportion_difference(acc_2, acc_3, n_1=y_true.shape[0])
assert round(z, 3) == 0.0
assert round(p_value, 3) == 0.5

0 comments on commit ec38ea3

Please sign in to comment.