try: %matplotlib inline except: %pylab inline import matplotlib.pyplot as plt #when you import scipy, you do NOT import all the sub packages import scipy scipy.i scipy.linspace(10,11, num=10) # you need to import a subpackage to have access scipy.io import scipy.io as io io? ## note about namespaces #import scipy.linalg from scipy import linalg linalg. from scipy import interpolate interpolate from numpy import r_, sin from scipy.signal import cspline1d, cspline1d_eval x = r_[0:10] #matlab like range creation print x dx = x[1]-x[0] newx = r_[-3:13:0.1] # notice outside the original domain y = sin(x) ## find cubic spline coefficients for a 1D signal cj = cspline1d(y) ## Evaluate spline on a new set of points ### dx is old sampling space, x0 was old sample origin newy = cspline1d_eval(cj, newx, dx=dx,x0=x[0]) plt.plot(newx, newy, x, y, 'o') ## example r_ r_[1:2:.1] import numpy as np from sklearn import mixture n_samples = 300 # generate random sample, two components np.random.seed(0) C = np.array([[0., -0.7], [3.5, .7]]) X_train = np.r_[np.dot(np.random.randn(n_samples, 2), C), np.random.randn(n_samples, 2) + np.array([20, 20])] clf = mixture.GMM(n_components=2, covariance_type='full') clf.fit(X_train) x = np.linspace(-20.0, 30.0) y = np.linspace(-20.0, 40.0) X, Y = np.meshgrid(x, y) XX = np.c_[X.ravel(), Y.ravel()] Z = np.log(-clf.score_samples(XX)[0]) Z = Z.reshape(X.shape) CS = plt.contour(X, Y, Z) CB = plt.colorbar(CS, shrink=0.8, extend='both') plt.scatter(X_train[:, 0], X_train[:, 1], .8) plt.axis('tight') import numpy as np C = np.array([[0., -0.7], [3.5, .7]]) n_samples = 300 np.dot(np.random.randn(n_samples, 2), C) np.random.randn(n_samples, 2) + np.array([20, 20]) X_train = np.r_[np.dot(np.random.randn(n_samples, 2), C), np.random.randn(n_samples, 2) + np.array([20, 20])] plt.plot(X_train[:,0], X_train[:,1], 'o') ##Basic scikit-image example from skimage import data, io, filter import matplotlib.pyplot as plt image = data.coins() # or any NumPy array! edges = filter.sobel(image) plt.figure(figsize=(10,10)) plt.subplot(121) io.imshow(image) plt.subplot(122) io.imshow(edges) #statsmodel simple example #Regression plot and loading datasets from R http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/regression_plots.html import numpy as np import pandas as pd import matplotlib.pyplot as plt import statsmodels.api as sm from statsmodels.formula.api import ols prestige = sm.datasets.get_rdataset("Duncan", "car", cache=True).data ## remember pandas, this should look familiar prestige.head() prestige_model = ols("prestige ~ income + education", data=prestige).fit() print prestige_model.summary() fig, ax = plt.subplots(figsize=(12,8)) fig = sm.graphics.influence_plot(prestige_model, ax=ax, criterion="cooks") fix, ax = plt.subplots(figsize=(12,14)) fig = sm.graphics.plot_partregress("prestige", "income", ["education"], data=prestige, ax=ax)