Created
July 28, 2015 15:15
Drawing a evaluate function for Quantile Regression.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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