- Introduction to Python
- Getting started with Python and the IPython notebook
- Functions are first class objects
- Data science is OSEMN
- Working with text
- Preprocessing text data
- Working with structured data
- Using SQLite3
- Using HDF5
- Using numpy
- Using Pandas
- Computational problems in statistics
- Computer numbers and mathematics
- Algorithmic complexity
- Linear Algebra and Linear Systems
- Linear Algebra and Matrix Decompositions
- Change of Basis
- Optimization and Non-linear Methods
- Practical Optimizatio Routines
- Finding roots
- Optimization Primer
- Using scipy.optimize
- Gradient deescent
- Newton’s method and variants
- Constrained optimization
- Curve fitting
- Finding paraemeters for ODE models
- Optimization of graph node placement
- Optimization of standard statistical models
- Fitting ODEs with the Levenberg–Marquardt algorithm
- 1D example
- 2D example
- Algorithms for Optimization and Root Finding for Multivariate Problems
- Expectation Maximizatio (EM) Algorithm
- Monte Carlo Methods
- Resampling methods
- Resampling
- Simulations
- Setting the random seed
- Sampling with and without replacement
- Calculation of Cook’s distance
- Permutation resampling
- Design of simulation experiments
- Example: Simulations to estimate power
- Check with R
- Estimating the CDF
- Estimating the PDF
- Kernel density estimation
- Multivariate kerndel density estimation
- Markov Chain Monte Carlo (MCMC)
- Using PyMC2
- Using PyMC3
- Using PyStan
- C Crash Course
- Code Optimization
- Using C code in Python
- Using functions from various compiled languages in Python
- Julia and Python
- Converting Python Code to C for speed
- Optimization bake-off
- Writing Parallel Code
- Massively parallel programming with GPUs
- Writing CUDA in C
- Distributed computing for Big Data
- Hadoop MapReduce on AWS EMR with mrjob
- Spark on a local mahcine using 4 nodes
- Modules and Packaging
- Tour of the Jupyter (IPython3) notebook
- Polyglot programming
- What you should know and learn more about
- Wrapping R libraries with Rpy
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
I/O Bound problems
Sometimes the issue is that you need to load or save massive amounts of data, and the transfer to and from the hard disk is the bootleneck. Possible solutions include 1) use of binary rather than text data, 2) use of data compression, 3) use of specialized data structures such as HDF5.
If you are working wiht huge amounts of data, conisder the use of 1) relational databases if there are many rleations to manage, 2) HDF5 if a hiearchical structure is natural, and 3) NoSQL databases such as Redis if the data relatons are simple and you need to transfer over the network.
Pandas also offers convenient access to multiple storage and retrieval options via its DataFramee object.
def io1(xs): """Using loops to write.""" with open('foo1.txt', 'w') as f: for x in xs: f.write('%d\t' % x) def io2(xs): """Join before writing.""" with open('foo2.txt', 'w') as f: f.write('\t'.join(map(str, xs))) def io3(xs): """Numpy savetxt is surprisingly slow.""" np.savetxt('foo3.txt', xs, delimiter='\t') def io4(xs): """NUmpy save is better if binary format is OK.""" np.save('foo4.npy', xs) def io5(xs): """Using HDF5.""" import h5py with h5py.File("mytestfile1.h5", "w") as f: ds = f.create_dataset("xs", (len(xs),), dtype='i') ds[:] = xs def io6(xs): """Using HDF5 with compression.""" import h5py with h5py.File("mytestfile2.h5", "w") as f: ds = f.create_dataset("xs", (len(xs),), dtype='i', compression="lzf") ds[:] = xs n = 1000*1000 xs = range(n) %timeit -r1 -n1 io1(xs) %timeit -r1 -n1 io2(xs) %timeit -r1 -n1 io3(xs) %timeit -r1 -n1 io4(xs) %timeit -r1 -n1 io5(xs) %timeit -r1 -n1 io6(xs)
1 loops, best of 1: 1.64 s per loop 1 loops, best of 1: 320 ms per loop 1 loops, best of 1: 6.7 s per loop 1 loops, best of 1: 108 ms per loop 1 loops, best of 1: 154 ms per loop 1 loops, best of 1: 122 ms per loop
def io11(xs): """Using basic python.""" with open('foo1.txt', 'r') as f: xs = map(int, f.read().strip().split('\t')) return xs def io12(xs): """Using pandsa.""" xs = pd.read_table('foo2.txt').values.tolist() return xs def io13(xs): """Numpy loadtxt.""" xs = np.loadtxt('foo3.txt',delimiter='\t') return xs def io14(xs): """Numpy load.""" xs = np.load('foo4.npy') return xs def io15(xs): """Using HDF5.""" import h5py with h5py.File("mytestfile1.h5", 'r') as f: xs = f['xs'][:] return xs def io16(xs): """Using HDF5 with compression.""" import h5py with h5py.File("mytestfile2.h5", 'r') as f: xs = f['xs'][:] return xs n = 1000*1000 xs = range(n) %timeit -r1 -n1 io11(xs) %timeit -r1 -n1 io12(xs) %timeit -r1 -n1 io13(xs) %timeit -r1 -n1 io14(xs) %timeit -r1 -n1 io15(xs) %timeit -r1 -n1 io16(xs)
1 loops, best of 1: 805 ms per loop 1 loops, best of 1: 51.3 s per loop 1 loops, best of 1: 5.56 s per loop 1 loops, best of 1: 15.2 ms per loop 1 loops, best of 1: 9.69 ms per loop 1 loops, best of 1: 16 ms per loop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论