News for hackers. Stuff that matters.
Re:Introduction to Statistics using NumPy by bckygldstn on Saturday September 09, 2017 @02:19PM (#15208387)
The formula you give for variance is the sample variance, with N - 1 as the divisor. It gives an unbiased estimate of the variance of a population, assuming X is a sample of that much larger population.

However, by default numpy gives you population variance, with N as the divisor. This assumes X is the entire population, which is different from R and Matlab.

As a result, the answer in your code is different from the formula just above it.

  np.var(X)
gives 207, while

  np.sum((np.array(X) - np.mean(X))**2) / (len(X) - 1)
gives 236. If you want the N-1 corrected sample variance from numpy you'd use

  np.var(X, ddof=1)
Re:Introduction to Statistics using NumPy by aisofteng on Saturday September 09, 2017 @07:45PM (#15209699)
Re:Introduction to Statistics using NumPy by dragandj on Saturday September 09, 2017 @10:48AM (#15207319)
The problem with these kind of extremely short texts is that they jump into explaining technical concepts without even mentioning basic things such as random variable for example.

Then, readers learn that statistics is about applying a few summing and averaging procedures, and trust the numbers they get as a result.

Re:Introduction to Statistics using NumPy by RA_Fisher on Saturday September 09, 2017 @11:34AM (#15207558)
I totally agree. It's much better to start with probability and then move to statistics. It gives both a foundation and the motivation for statistics.
Re:Introduction to Statistics using NumPy by analog31 on Saturday September 09, 2017 @11:39AM (#15207576)
Indeed, and I think Python could be great for learning about probability too. It comes with an endless supply of random numbers. ;-)
Re:Introduction to Statistics using NumPy by melling on Saturday September 09, 2017 @12:03PM (#15207668)
Anyone have any recommendations on where to start? In particular, I’ve been looking for a good book on probability.
Re:Introduction to Statistics using NumPy by maroonblazer on Saturday September 09, 2017 @12:08PM (#15207693)
I like Norvig's Jupyter notebook on Probability using Python.

http://nbviewer.jupyter.org/url/norvig.com/ipython/Probabili...

Re:Introduction to Statistics using NumPy by RA_Fisher on Saturday September 09, 2017 @01:57PM (#15208248)
I recommend Think Stats by Allen Downey http://greenteapress.com/thinkstats/
Re:Introduction to Statistics using NumPy by dragandj on Saturday September 09, 2017 @12:07PM (#15207681)
William Bolstad - Introduction to Bayesian Statistics

Or E.T. Jaynes - Probability Theory, The Logic of Science (but this one is much more detailed and has lots of philosophy)

Or Ian Hacking - An Introduction to Probability and Inductive Logic (this is the light approach written for philosophy students)

Re:Introduction to Statistics using NumPy by joshvm on Saturday September 09, 2017 @12:07PM (#15207680)
Jaynes is the usual 'standard' probability text, and it's well written and not too dry. It's mathsy though.
Re:Introduction to Statistics using NumPy by mubaris on Saturday September 09, 2017 @01:09PM (#15207953)
I'll be posting a separate blog post about probability soon. Anyway, thanks for the suggestion.
Re:Introduction to Statistics using NumPy by nafizh on Saturday September 09, 2017 @01:24PM (#15208035)
Calculating mean, median, and average in Numpy. How is this in the first page of hacker news?
Re:Introduction to Statistics using NumPy by branchless on Saturday September 09, 2017 @05:07PM (#15209164)
It's taking space that could be taken by yet another article about confidence/burnout/fitness/sleeping/nutrition!
Re:Introduction to Statistics using NumPy by lettuce on Saturday September 09, 2017 @04:45PM (#15209076)
For such basic functionality, is there any reason not to just use Python 3's `statistics` module?

  from statistics import mean, median, stdev, variance
Re:Introduction to Statistics using NumPy by jzwinck on Saturday September 09, 2017 @07:16PM (#15209620)
Two reasons. First is that NumPy works in Python 2 as well as 3.

Second is that everyone uses NumPy for this. It is proven, it is fast, and using it for simple things is a great way to get started on a path toward using it for more complex things. For example I use NumPy for tabular text processing sometimes, as it is much faster than the built-in stuff if you have a lot of data.

Re:Introduction to Statistics using NumPy by cristoperb on Saturday September 09, 2017 @02:20PM (#15208392)
It's a little bit confusing that the article defines variance as "the averaged squared deviation of each data from your dataset" but then the formula shown is the unbiased estimation of the variance (with n-1 in the denominator) without explanation.
Re:Introduction to Statistics using NumPy by mubaris on Saturday September 09, 2017 @02:22PM (#15208408)
I fixed this issue.
Re:Introduction to Statistics using NumPy by gshubert17 on Saturday September 09, 2017 @11:44AM (#15207591)
Nice example. But two typos,

Missing a close paren to open(); and splitlines() is misspelled. Code should be:

with open('salary.txt') as f: X = f.read().splitlines()

Re:Introduction to Statistics using NumPy by mubaris on Saturday September 09, 2017 @01:32PM (#15208087)
Thanks. Fixed typos
Re:Introduction to Statistics using NumPy by pencilcode on Saturday September 09, 2017 @01:58PM (#15208256)
Where did you get the dataset from? Adding a link to the source would be nice
Re:Introduction to Statistics using NumPy by mubaris on Saturday September 09, 2017 @02:05PM (#15208294)
There was an Ask HN post about earning in Europe.

https://news.ycombinator.com/item?id=15088840

Original Responses - https://docs.google.com/spreadsheets/d/1cjwB_s4ya57auTjIw-OV...

Then I went on to refine the data for my purposes - https://docs.google.com/spreadsheets/d/1AAJmOWOE-zYydNR_HzLU...

Re:Introduction to Statistics using NumPy by paprikawuerzung on Saturday September 09, 2017 @01:02PM (#15207917)
Nice, thanks! One question: where do you have the dataset from? The gender is encoded as 0,1,2 - which is which? Is this dataset from the Excel that was posted here some time ago? Could you share the link please?

I started to look at the dataset a little, if someone is interested: https://github.com/davidgengenbach/developer-salary-statisti...