Skip to content

Latest commit

 

History

History
118 lines (90 loc) · 3.6 KB

frequency-counts.md

File metadata and controls

118 lines (90 loc) · 3.6 KB
jupyter
jupytextkernelspecplotly
notebook_metadata_filtertext_representation
all
extensionformat_nameformat_versionjupytext_version
.md
markdown
1.1
1.1.1
display_namelanguagename
Python 2
python
python2
descriptiondisplay_ashas_thumbnaillanguagelayoutnameorderpage_typepermalinkthumbnail
Learn how to perform frequency counts using Python.
statistics
false
python
base
Frequency Counts
2
example_index
python/frequency-counts/
/images/static-image

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

Imports

The tutorial below imports numpy, pandas, and scipy

importplotly.plotlyaspyimportplotly.graph_objsasgofromplotly.toolsimportFigureFactoryasFFimportnumpyasnpimportpandasaspdimportscipy

Make the Data

We are generating a 1D dataset from a Weibull Distribution which has the distribution

$$ \begin{align*} X = \log(U)^{\frac{1}{a}} \end{align*} $$

where $U$ is drawn from the Uniform Distribution.

x=np.random.weibull(1.25, size=1000) print(x[:10])

Histogram

By using a histogram, we can properly divide a 1D dataset into bins with a particular size or width, so as to form a discrete probability distribution

trace=go.Histogram(x=x, xbins=dict(start=np.min(x), size=0.25, end=np.max(x)), marker=dict(color='rgb(0, 0, 100)')) layout=go.Layout( title="Histogram Frequency Counts" ) fig=go.Figure(data=go.Data([trace]), layout=layout) py.iplot(fig, filename='histogram-freq-counts')

Larger Bins

We can experiment with our bin size and the histogram by grouping the data into larger intervals

trace=go.Histogram(x=x, xbins=dict(start=np.min(x), size=0.75, end=np.max(x)), marker=dict(color='rgb(0, 0, 100)')) layout=go.Layout( title="Histogram Frequency Counts" ) fig=go.Figure(data=go.Data([trace]), layout=layout) py.iplot(fig, filename='histogram-freq-counts-larger-bins')
fromIPython.displayimportdisplay, HTMLdisplay(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />')) display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">')) ! pipinstallgit+https://github.com/plotly/publisher.git--upgradeimportpublisherpublisher.publish( 'python-Frequency-Counts.ipynb', 'python/frequency-counts/', 'Frequency Counts | plotly', 'Learn how to perform frequency counts using Python.', title='Frequency Counts in Python. | plotly', name='Frequency Counts', language='python', page_type='example_index', has_thumbnail='false', display_as='statistics', order=2, ipynb='~notebook_demo/111')
close