Exemple #1
0
def visualisation(vt0, vt1):
	fig = plt.figure()
	ax = plt.axes(xlim=(0, 250000), ylim=(3000, 9000))
	line, = ax.plot([], [], lw=2)
	datas = lexer.datas()
	plt.xlabel("mileage (km)")
	plt.ylabel("price (€)")
	ttl = ax.text(0.32, 1.05, '', transform = ax.transAxes, va='center')
	for data in datas:
		plt.plot(data[0], data[1], 'ro')
	def init():
	    ttl.set_text('')
	    line.set_data([], [])
	    return line, ttl

	def animate(i):
	    ttl.set_text("number of iterations: " + str(i))
	    t0 = vt0[i]
	    t1 = vt1[i]
	    x = np.linspace(0,240000,100000)
	    y = t1 * x + t0
	    line.set_data(x, y)
	    return line, ttl
	anim = animation.FuncAnimation(fig, animate, init_func=init,
	                               frames=len(vt0), interval=20, blit=False)
	plt.show()
Exemple #2
0
def visualisation():
	
	datas = lexer.datas()
	for data in datas:
		plt.plot(data[0], data[1], 'ro')

	
	theta = lexer.thetas()
	if theta[0] != 0 and theta[1] != 0:
		x = np.linspace(0,240000,100000)
		y = theta[0] * x + theta[1]
		plt.plot(x, y, '-r')

	plt.grid()
	plt.xlabel("km")
	plt.ylabel("price")
	plt.show()
	plt.close()
Exemple #3
0
def describe(argv):
    try:
        datas = lexer.datas(sys.argv[1])
    except:
        print("Failed to read the file.")
        exit()

    tab = init_tab(datas)
    tab, count_f = count_features(datas, tab)
    tab, mean_f = mean_features(datas, tab, count_f)
    tab, var_f, s_var_f = variance_features(datas, tab, count_f, mean_f)
    tab = std_features(datas, tab, var_f, s_var_f)
    tab, min_f = min_features(datas, tab)
    tab, tf_f, sf_f = perce_features(datas, tab, count_f)
    tab, max_f = max_features(datas, tab)
    tab = range_features(datas, tab, min_f, max_f)
    tab = iqr_features(datas, tab, tf_f, sf_f)
    print(tab)
Exemple #4
0
def precision():
    datas = lexer.datas()
    theta = lexer.thetas()

    my = 0
    for i, line in enumerate(datas):
        n = i + 1
        my += line[1]
    my /= n

    sse = 0
    ssr = 0
    for i, line in enumerate(datas):
        fy = theta[0] + line[0] * theta[1]
        sse += (fy - my) * (fy - my)
        ssr += (line[1] - fy) * (line[1] - fy)
    sst = sse + ssr
    r2 = sse / sst
    print("the precision of the algorithm is:", r2)
Exemple #5
0
def minimisation(alpha0, alpha1, error):
    datas = lexer.datas()
    theta = lexer.thetas()
    dt0, dt1 = 10, 10
    t0, t1 = theta[0], theta[1]
    vt0 = []
    vt1 = []
    while abs(dt0) > 0.01 and abs(dt1) > 0.01:
        DT = update_thetas(datas, t0, t1)
        dt0, dt1 = DT[0], DT[1]
        t0 = t0 - alpha0*dt0
        t1 = t1 - alpha1*dt1
        if math.isnan(t0) or math.isnan(t1):
        	if error:
        		exit()
        	minimisation(alpha1, alpha0, 1)
        vt0.append(t0)
        vt1.append(t1)
    ft_write(t0, t1)
    visualisation(vt0, vt1)
Exemple #6
0
def histogram(argv):
    try:
        datas = lexer.datas(sys.argv[1])
    except:
        print("Failed to read the file.")
        exit()
#	min_f = min_features(datas)
#	max_f = max_features(datas)
#	print (min_f[11])
#	print (max_f[11])
    f_h = feature_house(datas, 17)
    #	display (feat_house, datas[0][17], min_f[11], max_f[11])

    print(plt.style.available[:6])

    # Notez la taille de la figure
    fig = plt.figure(figsize=(12, 8))
    for i in range(6):
        # On peut ajouter des sous graphes ainsi
        fig.add_subplot(3, 2, i + 1)
        #		display(f_h,datas[0][17])
        plt.style.use(plt.style.available[i])
        plt.plot(x, y)
        # Pour ajouter du texte
        plt.text(s=plt.style.available[i], x=5, y=2, color='red')


#	i = 6
#	while i < 19:
#		i += 1
#		feat_house = feature_house(datas, i)

# ax = [0, 1, 2, 3, 4, 5, 6]
# np.random.seed(0)
# n_bins = 10
# x = np.random.randn(1000, 3)
# fh = feature_house(datas, 18)

# fig, axes = plt.subplots(nrows=5, ncols=4)
# ax = axes.flatten()

# colors = ['red', 'tan', 'lime']
# #ax0.hist(x, n_bins, normed=1, histtype='bar', color=colors, label=colors)
# ax[0].hist(fh[0], histtype = 'stepfilled', color = 'green', alpha = 0.25, label = 'Gryff')
# ax[0].hist(fh[1], histtype = 'stepfilled', color = 'blue', alpha = 0.25, label = 'Slith')
# ax[0].hist(fh[2], histtype = 'stepfilled', color = 'red', alpha = 0.25, label = 'Huffle')
# ax[0].hist(fh[3], histtype = 'stepfilled', color = 'yellow', alpha = 0.25, label = 'Ravenc')
# ax[0].legend(prop={'size': 10})
# ax[0].set_title('Histogram of '+ datas[0][18])

# ax[1].hist(x, n_bins, normed=1, histtype='bar', stacked=True)
# ax[1].set_title('stacked bar')

# ax[2].hist(x, n_bins, histtype='step', stacked=True, fill=False)
# ax[2].set_title('stack step (unfilled)')

# # Make a multiple-histogram of data-sets with different length.
# x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
# ax[3].hist(x_multi, n_bins, histtype='bar')
# ax[3].set_title('different sample sizes')

# fig.tight_layout()
# plt.show()

# x1 = np.linspace(0.0, 5.0)
# y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)

# x2 = np.linspace(0.0, 2.0)
# y2 = np.cos(2 * np.pi * x2)

# x3 = np.linspace(0.0, 4.0)
# y3 = np.cos(2 * np.pi * x3)

# x4 = np.linspace(-2.0, 2.0)
# y4 = np.cos(2 * np.pi * x4)

# x5 = np.linspace(-10.0, 20.0)
# y5 = np.cos(2 * np.pi * x5)

# i = 6
# while i < 7:
# 	#p = i - 5
# 	fh = feature_house(datas, i)
# 	plt.subplot(8, 4, i)

# 	plt.hist(fh[0], histtype = 'stepfilled', color = 'green', alpha = 0.25, label = 'Gryff')
# 	plt.hist(fh[1], histtype = 'stepfilled', color = 'blue', alpha = 0.25, label = 'Slith')

# 	#plt.legend(prop={'size': 10})
# 	plt.title('Histogram of '+ datas[0][i])
# 	i += 1

# plt.subplot(432)
# plt.plot(x2, y2, '.-')
# plt.xlabel('time (s)')
# plt.ylabel('Undamped')

# plt.subplot(433)
# plt.plot(x3, y4, '.-')
# plt.xlabel('3 (s)')
# plt.ylabel('3 ---------- stop')

    plt.show()