mlquantify 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. mlquantify/__init__.py +6 -0
  2. mlquantify/base.py +256 -0
  3. mlquantify/classification/__init__.py +1 -0
  4. mlquantify/classification/pwkclf.py +73 -0
  5. mlquantify/evaluation/__init__.py +2 -0
  6. mlquantify/evaluation/measures/__init__.py +26 -0
  7. mlquantify/evaluation/measures/ae.py +11 -0
  8. mlquantify/evaluation/measures/bias.py +16 -0
  9. mlquantify/evaluation/measures/kld.py +8 -0
  10. mlquantify/evaluation/measures/mse.py +12 -0
  11. mlquantify/evaluation/measures/nae.py +16 -0
  12. mlquantify/evaluation/measures/nkld.py +13 -0
  13. mlquantify/evaluation/measures/nrae.py +16 -0
  14. mlquantify/evaluation/measures/rae.py +12 -0
  15. mlquantify/evaluation/measures/se.py +12 -0
  16. mlquantify/evaluation/protocol/_Protocol.py +202 -0
  17. mlquantify/evaluation/protocol/__init__.py +2 -0
  18. mlquantify/evaluation/protocol/app.py +146 -0
  19. mlquantify/evaluation/protocol/npp.py +34 -0
  20. mlquantify/methods/__init__.py +40 -0
  21. mlquantify/methods/aggregative/ThreholdOptm/_ThreholdOptimization.py +62 -0
  22. mlquantify/methods/aggregative/ThreholdOptm/__init__.py +7 -0
  23. mlquantify/methods/aggregative/ThreholdOptm/acc.py +27 -0
  24. mlquantify/methods/aggregative/ThreholdOptm/max.py +23 -0
  25. mlquantify/methods/aggregative/ThreholdOptm/ms.py +21 -0
  26. mlquantify/methods/aggregative/ThreholdOptm/ms2.py +25 -0
  27. mlquantify/methods/aggregative/ThreholdOptm/pacc.py +41 -0
  28. mlquantify/methods/aggregative/ThreholdOptm/t50.py +21 -0
  29. mlquantify/methods/aggregative/ThreholdOptm/x.py +23 -0
  30. mlquantify/methods/aggregative/__init__.py +9 -0
  31. mlquantify/methods/aggregative/cc.py +32 -0
  32. mlquantify/methods/aggregative/emq.py +86 -0
  33. mlquantify/methods/aggregative/fm.py +72 -0
  34. mlquantify/methods/aggregative/gac.py +96 -0
  35. mlquantify/methods/aggregative/gpac.py +87 -0
  36. mlquantify/methods/aggregative/mixtureModels/_MixtureModel.py +81 -0
  37. mlquantify/methods/aggregative/mixtureModels/__init__.py +5 -0
  38. mlquantify/methods/aggregative/mixtureModels/dys.py +55 -0
  39. mlquantify/methods/aggregative/mixtureModels/dys_syn.py +89 -0
  40. mlquantify/methods/aggregative/mixtureModels/hdy.py +46 -0
  41. mlquantify/methods/aggregative/mixtureModels/smm.py +27 -0
  42. mlquantify/methods/aggregative/mixtureModels/sord.py +77 -0
  43. mlquantify/methods/aggregative/pcc.py +33 -0
  44. mlquantify/methods/aggregative/pwk.py +38 -0
  45. mlquantify/methods/meta/__init__.py +1 -0
  46. mlquantify/methods/meta/ensemble.py +236 -0
  47. mlquantify/methods/non_aggregative/__init__.py +1 -0
  48. mlquantify/methods/non_aggregative/hdx.py +71 -0
  49. mlquantify/model_selection.py +232 -0
  50. mlquantify/plots/__init__.py +2 -0
  51. mlquantify/plots/distribution_plot.py +109 -0
  52. mlquantify/plots/protocol_plot.py +157 -0
  53. mlquantify/utils/__init__.py +2 -0
  54. mlquantify/utils/general_purposes/__init__.py +8 -0
  55. mlquantify/utils/general_purposes/convert_col_to_array.py +13 -0
  56. mlquantify/utils/general_purposes/generate_artificial_indexes.py +29 -0
  57. mlquantify/utils/general_purposes/get_real_prev.py +9 -0
  58. mlquantify/utils/general_purposes/load_quantifier.py +4 -0
  59. mlquantify/utils/general_purposes/make_prevs.py +23 -0
  60. mlquantify/utils/general_purposes/normalize.py +20 -0
  61. mlquantify/utils/general_purposes/parallel.py +10 -0
  62. mlquantify/utils/general_purposes/round_protocol_df.py +14 -0
  63. mlquantify/utils/method_purposes/__init__.py +6 -0
  64. mlquantify/utils/method_purposes/distances.py +21 -0
  65. mlquantify/utils/method_purposes/getHist.py +13 -0
  66. mlquantify/utils/method_purposes/get_scores.py +33 -0
  67. mlquantify/utils/method_purposes/moss.py +16 -0
  68. mlquantify/utils/method_purposes/ternary_search.py +14 -0
  69. mlquantify/utils/method_purposes/tprfpr.py +42 -0
  70. mlquantify-0.0.1.dist-info/METADATA +23 -0
  71. mlquantify-0.0.1.dist-info/RECORD +73 -0
  72. mlquantify-0.0.1.dist-info/WHEEL +5 -0
  73. mlquantify-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,13 @@
1
+ import numpy as np
2
+
3
+ def getHist(scores, nbins):
4
+
5
+ breaks = np.linspace(0, 1, int(nbins)+1)
6
+ breaks = np.delete(breaks, -1)
7
+ breaks = np.append(breaks,1.1)
8
+
9
+ re = np.repeat(1/(len(breaks)-1), (len(breaks)-1))
10
+ for i in range(1,len(breaks)):
11
+ re[i-1] = (re[i-1] + len(np.where((scores >= breaks[i-1]) & (scores < breaks[i]))[0]) ) / (len(scores)+ 1)
12
+
13
+ return re
@@ -0,0 +1,33 @@
1
+ import pandas as pd
2
+ import numpy as np
3
+ from sklearn.model_selection import StratifiedKFold
4
+
5
+ def get_scores(X, y, learner, folds:int=10, learner_fitted:bool=False) -> tuple:
6
+ if isinstance(X, np.ndarray):
7
+ X = pd.DataFrame(X)
8
+ if isinstance(y, np.ndarray):
9
+ y = pd.Series(y)
10
+
11
+ if learner_fitted:
12
+ probabilities = learner.predict_proba(X)
13
+ y_label = y
14
+ else:
15
+
16
+ skf = StratifiedKFold(n_splits=folds)
17
+ probabilities = []
18
+ y_label = []
19
+
20
+ for train_index, valid_index in skf.split(X,y):
21
+
22
+ tr_data = pd.DataFrame(X.iloc[train_index]) #Train data and labels
23
+ tr_label = y.iloc[train_index]
24
+
25
+ valid_data = pd.DataFrame(X.iloc[valid_index]) #Validation data and labels
26
+ valid_label = y.iloc[valid_index]
27
+
28
+ learner.fit(tr_data, tr_label)
29
+
30
+ probabilities.extend(learner.predict_proba(valid_data)) #evaluating scores
31
+ y_label.extend(valid_label)
32
+
33
+ return np.asarray(y_label), np.asarray(probabilities)
@@ -0,0 +1,16 @@
1
+ import numpy as np
2
+
3
+ def MoSS(n:int, alpha:float, m:float):
4
+
5
+ n_pos = int(n*alpha)
6
+ n_neg = int((1-alpha)*n)
7
+
8
+ x_pos = np.arange(1, n_pos, 1)
9
+ x_neg = np.arange(1, n_neg, 1)
10
+
11
+ syn_plus = np.power(x_pos/(n_pos+1), m)
12
+ syn_neg = 1 - np.power(x_neg/(n_neg+1), m)
13
+
14
+ #moss = np.union1d(syn_plus, syn_neg)
15
+
16
+ return syn_plus, syn_neg
@@ -0,0 +1,14 @@
1
+ def ternary_search(left, right, f, eps=1e-4):
2
+ """This function applies Ternary search"""
3
+
4
+ while True:
5
+ if abs(left - right) < eps:
6
+ return(left + right) / 2
7
+
8
+ leftThird = left + (right - left) / 3
9
+ rightThird = right - (right - left) / 3
10
+
11
+ if f(leftThird) > f(rightThird):
12
+ left = leftThird
13
+ else:
14
+ right = rightThird
@@ -0,0 +1,42 @@
1
+ import numpy as np
2
+
3
+
4
+ def compute_table(y, y_pred, classes):
5
+ TP = np.logical_and(y == y_pred, y == classes[1]).sum()
6
+ FP = np.logical_and(y != y_pred, y == classes[0]).sum()
7
+ FN = np.logical_and(y != y_pred, y == classes[1]).sum()
8
+ TN = np.logical_and(y == y_pred, y == classes[0]).sum()
9
+ return TP, FP, FN, TN
10
+
11
+
12
+ def compute_tpr(TP, FN):
13
+ if TP + FN == 0:
14
+ return 0
15
+ return TP / (TP + FN)
16
+
17
+
18
+ def compute_fpr(FP, TN):
19
+ if FP + TN == 0:
20
+ return 0
21
+ return FP / (FP + TN)
22
+
23
+
24
+ def adjust_threshold(y, probabilities:np.ndarray, classes:np.ndarray) -> tuple:
25
+ unique_scores = np.linspace(0, 1, 101)
26
+
27
+ tprs = []
28
+ fprs = []
29
+
30
+ for threshold in unique_scores:
31
+ y_pred = np.where(probabilities >= threshold, classes[1], classes[0])
32
+
33
+ TP, FP, FN, TN = compute_table(y, y_pred, classes)
34
+
35
+ tpr = compute_tpr(TP, FN)
36
+ fpr = compute_fpr(FP, TN)
37
+
38
+ tprs.append(tpr)
39
+ fprs.append(fpr)
40
+
41
+ #best_tpr, best_fpr = self.adjust_threshold(np.asarray(tprs), np.asarray(fprs))
42
+ return (unique_scores, np.asarray(tprs), np.asarray(fprs))
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.1
2
+ Name: mlquantify
3
+ Version: 0.0.1
4
+ Summary: Quantification Library
5
+ Home-page: https://github.com/luizfernandolj/QuantifyML/tree/master
6
+ Maintainer: Luiz Fernando Luth Junior
7
+ Keywords: python,machine learning,quantification,quantify
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: Unix
12
+ Classifier: Operating System :: MacOS :: MacOS X
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: scikit-learn
16
+ Requires-Dist: numpy
17
+ Requires-Dist: scipy
18
+ Requires-Dist: joblib
19
+ Requires-Dist: tqdm
20
+ Requires-Dist: pandas
21
+ Requires-Dist: xlrd
22
+ Requires-Dist: matplotlib
23
+
@@ -0,0 +1,73 @@
1
+ mlquantify/__init__.py,sha256=BGxGCeZhlNsTYZkLoJJ-zcpVDRU4jBFVsz9ZmEZCtvs,166
2
+ mlquantify/base.py,sha256=XpI7vynnn-f126Ykkw_YuuZI0CtuRMkPt0oBbDDZ7yY,8371
3
+ mlquantify/model_selection.py,sha256=zN-qkrCe35GoJ8u1_Ab3EKXvrnAppk68Fj5kQVi61nU,8617
4
+ mlquantify/classification/__init__.py,sha256=zxE6_ouh3kJVL56aJAhpFh36EBWKq9U4IcID4noROPQ,26
5
+ mlquantify/classification/pwkclf.py,sha256=K1XBgI9FIh1Yu571bzdw8PM-TJXFGOQAzP4ewDV9b3Y,2323
6
+ mlquantify/evaluation/__init__.py,sha256=_7orbRyYuJydD_W9o5l9Ko_-EopGGhewekoEhR82S3Q,48
7
+ mlquantify/evaluation/measures/__init__.py,sha256=JvxIm3k31EFBzm-4Guj9Huh--B7u-o3gvln3VSFK2nk,761
8
+ mlquantify/evaluation/measures/ae.py,sha256=eY8oKfj7TIpbNCsEfbkbeVVduSAaiKE5Vxy7xACwrL8,363
9
+ mlquantify/evaluation/measures/bias.py,sha256=AmTZ9dP5XW6ZR-gdBfOF008IzVFeBNeL2SIuSLkABQc,497
10
+ mlquantify/evaluation/measures/kld.py,sha256=f443cf31Sm904zEwk0q1093XwvEEQbroHUzNLKJj-BI,341
11
+ mlquantify/evaluation/measures/mse.py,sha256=VS38G83ygVz_qxtsjqa-tTGbPVERQOraY_aga5JmVuo,408
12
+ mlquantify/evaluation/measures/nae.py,sha256=D5W2qiD1EC53uy7AILRHvdZNvAcAQkLTuFNFNmHjkEs,499
13
+ mlquantify/evaluation/measures/nkld.py,sha256=UsTDZP-CjiEgQjfyoKynZntpFV8msYPrEma3GtHK1-s,491
14
+ mlquantify/evaluation/measures/nrae.py,sha256=iTxEG7k6DQRieSbwKrHfcynmbRR-qCviudDecoRkmdk,574
15
+ mlquantify/evaluation/measures/rae.py,sha256=KYa9HY7k5w3acMp5yUSMVuwZIdzeUB9CzkSA-jpXn7Y,416
16
+ mlquantify/evaluation/measures/se.py,sha256=aScxX56dmbSj1HxubD8Dlq4gTmbNrA-H3AdE145wgDI,396
17
+ mlquantify/evaluation/protocol/_Protocol.py,sha256=XsLsu-sDQxHVyRqc-vGAs4407H5IJGSYAuH4sWAYQL8,7752
18
+ mlquantify/evaluation/protocol/__init__.py,sha256=RO3fHIvhAK95t8EUaD67JfJV2WeLb17HMqbXo3LcUSI,42
19
+ mlquantify/evaluation/protocol/app.py,sha256=WJ2OaYe49R8JqCoZDy6gMN50eIQ7jThPDT5W5lSRlK0,5713
20
+ mlquantify/evaluation/protocol/npp.py,sha256=c287_9LmxYvv72hh2iwoCwSkwqTeFvknKOWWG4Jq0QY,1117
21
+ mlquantify/methods/__init__.py,sha256=rvpN5T6vXdfX1bOHKYGC0aKZMc5bHSPb-pCVQ3mlb08,627
22
+ mlquantify/methods/aggregative/__init__.py,sha256=rBtSfgTsTIjbH5rJhQ9V05n68o-9hm9QNZzxRCh2VME,209
23
+ mlquantify/methods/aggregative/cc.py,sha256=HXFgcLqyM35CTszBn5UmUmT60Z1J1Ow0i4lZf5BctH8,1123
24
+ mlquantify/methods/aggregative/emq.py,sha256=3N4PQhTlBu6vBwOaEpcNZf2QYNBF2XC8cCH3qsyKt9Y,3208
25
+ mlquantify/methods/aggregative/fm.py,sha256=RgXVwsdoZsWV_DanvzcsRmll_e2Etvl27PNI7iYM9Nw,2912
26
+ mlquantify/methods/aggregative/gac.py,sha256=gTIRqMN0S7teheSOgrk2NB80UxfC-KfbNuk0A1tflh8,3640
27
+ mlquantify/methods/aggregative/gpac.py,sha256=VcDCcEYXiknEOTwVDGOXWeZCJS9T6vd4YFqEbnUB3YU,3531
28
+ mlquantify/methods/aggregative/pcc.py,sha256=8WuiWFrYvskx0Xd2wTDgcn-GyswwB5hv-VH6HaRkilY,1251
29
+ mlquantify/methods/aggregative/pwk.py,sha256=JCUzS8hrsiFMacLh00FR4Xhk7zhe4Vy4za-0QeFr-l8,1466
30
+ mlquantify/methods/aggregative/ThreholdOptm/_ThreholdOptimization.py,sha256=amgklOfPe-htQIhuDb3l4usqj-cVkGFa7z0KXYmibUM,2433
31
+ mlquantify/methods/aggregative/ThreholdOptm/__init__.py,sha256=ALB-ZEl9M_DyHr3U9PEw6E9XSMFfwci_aSwbpyzvp0E,155
32
+ mlquantify/methods/aggregative/ThreholdOptm/acc.py,sha256=tgcMhYW9cD66j0T6mWDulaxP9-FA1mNozvlaKMQV2UQ,1082
33
+ mlquantify/methods/aggregative/ThreholdOptm/max.py,sha256=A-_0RQ-HAiTE2FfeNvcInqauXpzn8xtSf0LDiuC5wDk,824
34
+ mlquantify/methods/aggregative/ThreholdOptm/ms.py,sha256=BpVrDaiCZa8xe1_YX9qhGCsOAcCXZ_3EQF5ZCHWRCn8,739
35
+ mlquantify/methods/aggregative/ThreholdOptm/ms2.py,sha256=Pxxc4p_41KLcNUaN0fhjih3mSVMJhoZrm-KUy45paT4,852
36
+ mlquantify/methods/aggregative/ThreholdOptm/pacc.py,sha256=zfRQhklB8NuvQAn8-a1hJ9sm6iG6yRGIWh-xlLTnU3M,1432
37
+ mlquantify/methods/aggregative/ThreholdOptm/t50.py,sha256=-zWNDXdGpW7CR-9O6MUQYOBqMuH15lLV-uK0u8nIAYA,728
38
+ mlquantify/methods/aggregative/ThreholdOptm/x.py,sha256=Lwn5MtaL9tb4eRFMrFxerUjmumh2US90KvDfdNQxvF8,759
39
+ mlquantify/methods/aggregative/mixtureModels/_MixtureModel.py,sha256=pcnCN0IArb_AJ71AyUnIt0uVPhN9IWnXZF9ad1d0g8c,3336
40
+ mlquantify/methods/aggregative/mixtureModels/__init__.py,sha256=F7QvGhVkG7NEHjnau_fNm7T9MLCUUDwfrrNvncqPpPI,117
41
+ mlquantify/methods/aggregative/mixtureModels/dys.py,sha256=JC3h_gdIYG-5pphl7C6Ez8Kbp0UPbccqX8ZVcsTAI3g,2356
42
+ mlquantify/methods/aggregative/mixtureModels/dys_syn.py,sha256=GGt9TOXGUBBD9PdiozT6QpC-IGa6QvLf1QAGEI7El8s,3906
43
+ mlquantify/methods/aggregative/mixtureModels/hdy.py,sha256=JykK4Fg5yPKmEuL1aAqsG9wnrmTbXNuxbK4ugI1XNBo,1986
44
+ mlquantify/methods/aggregative/mixtureModels/smm.py,sha256=2r82umOXqOrffVO-SdnyUzsJKg6hz5_z82HzNsn7GRY,1050
45
+ mlquantify/methods/aggregative/mixtureModels/sord.py,sha256=Kz5YAXd3RezeTI66wfrnXxY_AXDos44WS8N2fYE4oxA,3166
46
+ mlquantify/methods/meta/__init__.py,sha256=uj--leWdOrpBs0u_djhCYlLCrQo3GIxg0AoJyAkHC-c,30
47
+ mlquantify/methods/meta/ensemble.py,sha256=rX9fyGi6xMYVUo0jm_rttnSDTDt_XokvzZJUWDPxQTM,10396
48
+ mlquantify/methods/non_aggregative/__init__.py,sha256=HD34lwNmAkw26qlEA5PDHay9V6ShgFiQvlPipOsrDAs,20
49
+ mlquantify/methods/non_aggregative/hdx.py,sha256=vwodV_Z89_be8HBOSriX3lsFhzmPZVLdOgKewa6la-E,2420
50
+ mlquantify/plots/__init__.py,sha256=IDnv_KVALIsVuohiudclnIMSM5F1dNRxUFpjygLblBI,118
51
+ mlquantify/plots/distribution_plot.py,sha256=8l22Lq6LhlOd3yv6gHX6wg2p1MTozYASyNzPcLlPHzk,4038
52
+ mlquantify/plots/protocol_plot.py,sha256=DoVg_oDO_8HcFHMmWBVY2TM9HR-sgw20EqPQAOVRKj4,5513
53
+ mlquantify/utils/__init__.py,sha256=VKplOsrL4ONf0-9anhcWFOxXjvGSQTH0Kh922s_hGb0,63
54
+ mlquantify/utils/general_purposes/__init__.py,sha256=-Pwx1t2M_rGCEHxIc2TyomSe92w6U5Bdp6wtpsdcMZI,380
55
+ mlquantify/utils/general_purposes/convert_col_to_array.py,sha256=Pq6_U6BdsIAl4Vr_836_vM-g2iRQAJ1b4kGOsYoFukI,560
56
+ mlquantify/utils/general_purposes/generate_artificial_indexes.py,sha256=L_Sb1hBYGllCxDbYKRNY_qqjCfSbbkXo6E1XuaWxQMs,1049
57
+ mlquantify/utils/general_purposes/get_real_prev.py,sha256=nHSXaxAdp-rznyhauN7ta_1QCDrlfCZSJWxxQQ4_pvE,266
58
+ mlquantify/utils/general_purposes/load_quantifier.py,sha256=6BfObUBVJ7_v-pzP-cQlMpblmg6ygpvDRTimOhMWepw,77
59
+ mlquantify/utils/general_purposes/make_prevs.py,sha256=lamVz-MTRDP4bqDjS4xm2SMa3YpnMcL__1OF6ZpEX2I,661
60
+ mlquantify/utils/general_purposes/normalize.py,sha256=kIRG22249IkBuDBGP-qQbLsH-edPFC8gPnJS_huxLhY,785
61
+ mlquantify/utils/general_purposes/parallel.py,sha256=vkert2m-A5Rs_VKhLUk84nZ0scIVPFadvVsTF2bItaU,218
62
+ mlquantify/utils/general_purposes/round_protocol_df.py,sha256=74zS7ws7mgzjObv6xoQi7rvH2xskschHF93czoFaVFY,474
63
+ mlquantify/utils/method_purposes/__init__.py,sha256=MFB3LtYTsWuETmyFokn8EZoK2wwPZspCknIMdutLLCo,276
64
+ mlquantify/utils/method_purposes/distances.py,sha256=l5neBoqLN_Npyf2L9VB19V_RHpB2w9AJuddTQ2pFzxU,428
65
+ mlquantify/utils/method_purposes/getHist.py,sha256=dgO57Wo-Sbix6h1ixbT2XIKuRU0p-lZNLGI0ZGwadkM,402
66
+ mlquantify/utils/method_purposes/get_scores.py,sha256=qdIVYUS8xd8Vt86k19yETDNfibTXaTur5pCrMA1b254,1151
67
+ mlquantify/utils/method_purposes/moss.py,sha256=CVDDMHxPBnl_U2hz7Aqvne7jhB2mBUsVzTTsaiLQhOc,352
68
+ mlquantify/utils/method_purposes/ternary_search.py,sha256=JpNrfJsA5kWuanVW_hyMucy7rQ9UzTSgazFpTRi9jMI,416
69
+ mlquantify/utils/method_purposes/tprfpr.py,sha256=VKniG5aK8IwAA2fXEhkdHtwnx1zHH12qhwS4kKW5Dlo,1181
70
+ mlquantify-0.0.1.dist-info/METADATA,sha256=hT32pA_BUXMWzHfQ12L9LmVzlc1plpWG8rVPSYSxPwE,774
71
+ mlquantify-0.0.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
72
+ mlquantify-0.0.1.dist-info/top_level.txt,sha256=tGEkYkbbFElwULvqENjam3u1uXtyC1J9dRmibsq8_n0,11
73
+ mlquantify-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.41.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ mlquantify