Calculating Pearson correlation and significance in Python

You can have a look at scipy.stats: from pydoc import help from scipy.stats.stats import pearsonr help(pearsonr) >>> Help on function pearsonr in module scipy.stats.stats: pearsonr(x, y) Calculates a Pearson correlation coefficient and the p-value for testing non-correlation. The Pearson correlation coefficient measures the linear relationship between two datasets. Strictly speaking, Pearson’s correlation requires that each … Read more

Find p-value (significance) in scikit-learn LinearRegression

This is kind of overkill but let’s give it a go. First lets use statsmodel to find out what the p-values should be import pandas as pd import numpy as np from sklearn import datasets, linear_model from sklearn.linear_model import LinearRegression import statsmodels.api as sm from scipy import stats diabetes = datasets.load_diabetes() X = diabetes.data y … Read more

Multiple linear regression in Python

sklearn.linear_model.LinearRegression will do it: from sklearn import linear_model clf = linear_model.LinearRegression() clf.fit([[getattr(t, ‘x%d’ % i) for i in range(1, 8)] for t in texts], [t.y for t in texts]) Then clf.coef_ will have the regression coefficients. sklearn.linear_model also has similar interfaces to do various kinds of regularizations on the regression.

PHP algorithm to generate all combinations of a specific size from a single set

I would use a recursive function. Here’s a (working) example with comments. Hope this works for you! function sampling($chars, $size, $combinations = array()) { # if it’s the first iteration, the first set # of combinations is the same as the set of characters if (empty($combinations)) { $combinations = $chars; } # we’re done if … Read more