Skip to content

Instantly share code, notes, and snippets.

@matsuken92
Created July 28, 2015 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuken92/11552175906633edfc69 to your computer and use it in GitHub Desktop.
Save matsuken92/11552175906633edfc69 to your computer and use it in GitHub Desktop.
Drawing a evaluate function for Quantile Regression.
%matplotlib inline
import matplotlib.pyplot as plt
import sys
import numpy as np
from matplotlib import animation as ani
plt.style.use('ggplot')
x = np.linspace(-2, 2, 500)
x2 = (1/2.)*x**2
def animate(nframe):
global num_frame
plt.clf()
tau = nframe/25.
y =[tau*xx if xx >=0 else (tau-1)*xx for xx in x]
sys.stdout.write( "({},{})".format(tau, 1-tau))
plt.title("error func of quantile regression. tau={0:.2f}".format(tau))
plt.plot(x,y)
plt.plot(x,x2)
plt.xlim(-2,2)
plt.ylim(0,2)
num_frame = 26
fig = plt.figure(figsize=(9,9))
anim = ani.FuncAnimation(fig, animate, frames=num_frame, blit=True)
anim.save('err_func_quantile_reg.gif', writer='imagemagick', fps=3, dpi=64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment