Quantile-Quantile Plot using SciPy

Update: As folks have pointed out this answer is not correct. A probplot is different from a quantile-quantile plot. Please see those comments and other answers before you make an error in interpreting or conveying your distributions’ relationship. I think that scipy.stats.probplot will do what you want. See the documentation for more detail. import numpy … Read more

How to plot ROC curve in Python

Here are two ways you may try, assuming your model is an sklearn predictor: import sklearn.metrics as metrics # calculate the fpr and tpr for all thresholds of the classification probs = model.predict_proba(X_test) preds = probs[:,1] fpr, tpr, threshold = metrics.roc_curve(y_test, preds) roc_auc = metrics.auc(fpr, tpr) # method I: plt import matplotlib.pyplot as plt plt.title(‘Receiver … Read more

How to use the ‘sweep’ function

sweep() is typically used when you operate a matrix by row or by column, and the other input of the operation is a different value for each row / column. Whether you operate by row or column is defined by MARGIN, as for apply(). The values used for what I called “the other input” is … Read more

How to calculate probability in a normal distribution given mean & standard deviation?

There’s one in scipy.stats: >>> import scipy.stats >>> scipy.stats.norm(0, 1) <scipy.stats.distributions.rv_frozen object at 0x928352c> >>> scipy.stats.norm(0, 1).pdf(0) 0.3989422804014327 >>> scipy.stats.norm(0, 1).cdf(0) 0.5 >>> scipy.stats.norm(100, 12) <scipy.stats.distributions.rv_frozen object at 0x928352c> >>> scipy.stats.norm(100, 12).pdf(98) 0.032786643008494994 >>> scipy.stats.norm(100, 12).cdf(98) 0.43381616738909634 >>> scipy.stats.norm(100, 12).cdf(100) 0.5 [One thing to beware of — just a tip — is that the parameter … Read more

Rolling median algorithm in C

I have looked at R’s src/library/stats/src/Trunmed.c a few times as I wanted something similar too in a standalone C++ class / C subroutine. Note that this are actually two implementations in one, see src/library/stats/man/runmed.Rd (the source of the help file) which says \details{ Apart from the end values, the result \code{y = runmed(x, k)} simply … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)