def plot(data, weights):
    data_mat = array(df['density', 'radio_suger'].values[:,:])
    label_mat = mat(df['label'].values[:]).transpose()
    m = shape(data_mat)[0]
    xcord1 = []
    ycord1 = []
    xcord2 = []
    ycord2 = []
    for i in xrange(m):
        if label_mat[i] == 1:
            xcord1.append(data_mat[i])
            ycore1.append(label_mat[i])
        else:
            xcord2.append(data_mat[i])
            ycord2.append(label_mat[i])
    plt.figure(1)
    ax = plt.subplot(111)
    ax.scatter(xcord1, ycord1, s=30, c='red', marker='s')
    ax.scatter(xcord2, ycord2, s=30, c='greeen')
    x = arange(-0.2, 0.8, 1)
    y = array((-w[0,0]*x)/w[0,1])
    print shape(x)
    print shape(y)
    plt.sca(ax)
    
    plt.plot(x,y)
    plt.xlabel('density')
    plt.ylabel('radio_suger')
    plt.title('LDA')
    plt.show()
Beispiel #2
0
def visualize_data():
  """"""
  df = pd.read_csv('sp500_joined_closes.csv')
  df_corr = df.corr()
  
  data = df_corr.values
  fig = plt.figure()
  ax = fig.add_subplot(1, 1, 1) # An one by one plot.
  
  heatmap = ax.pcolor(data, cmap = plt.cm.RdYlGn)
  fig.colorbar(heatmap)
  ax.set_xticks(np.arange(data.shape[0])+ 0.5, minor=False)
  ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)
  ax.inverst_yaxis()
  ax.xaxis.tick_top()
  
  column_labels = df_corr.columns
  row_labels = df_corr.index
  
  ax.set_xticklables(column_labels)
  ax.set_yticklabels(row_labels)
  plt.xticks(rotation=90)
  heatmap.set_clim(-1, 1)
  plt.tight_layout()
  plt.show()
def predict_price(dates,prices,x):
    dates = np.reshape(dates,len(dates),1)
	
	svr_len = SVR(kernel='linear',c=1e3)
	svr_poly = SVR(kernel='poly',c=1e3,degree=2)
	svr_len = SVR(kernel='rbf',c=1e3,gamma=0.1)
	svr_lin.fit(dates,prices)
	svr_poly.fit(dates,prices)
	svr_rbf.fit(dates,prices)
	
	plt.scatter(dates,prices,color='black', label='Data')
	plt.plot(dates, svr_rbf.predict(dates), color='red', label='RBF model')
	plt.plot(dates, svr_lin.predict(dates), color='green', label='Linear model')
	plt.plot(dates, svr_ply.predict(dates), color='blue', label='Ploynomial model')
	plt.xlabel('Date')
	plt.ylabel('Price')
	plt.title('Support Vector Regration')
	plt.legend()
	plt.show()
	
	return svr_rbf.predict(x)[0],svr_lin.predict(x)[0], ,svr_poly.predict(x)[0]
Beispiel #4
0
def plot_the_loss_curve(epochs, mae_training, mae_validation):
  """Plot a curve of loss vs. epoch."""

  plt.figure()
  plt.xlabel("Epoch")
  plt.ylabel("Root Mean Squared Error")

  plt.plot(epochs[1:], mae_training[1:], label="Training Loss")
  plt.plot(epochs[1:], mae_validation[1:], label="Validation Loss")
  plt.legend()
  
  # We're not going to plot the first epoch, since the loss on the first epoch
  # is often substantially greater than the loss for other epochs.
  merged_mae_lists = mae_training[1:] + mae_validation[1:]
  highest_loss = max(merged_mae_lists)
  lowest_loss = min(merged_mae_lists)
  delta = highest_loss - lowest_loss
  print(delta)

  top_of_y_axis = highest_loss + (delta * 0.05)
  bottom_of_y_axis = lowest_loss - (delta * 0.05)
   
  plt.ylim([bottom_of_y_axis, top_of_y_axis])
  plt.show()  
Beispiel #5
0
import numpy as np
import matplot.pyplot as plt

x = linspace(0, 1, 100)
y = sin(6 * np.pi * y)
ffty = np.fft(y)
plt.plot(x, y)
plt.show()
Beispiel #6
0
verts = []
for row in csv_reader:
	verts.append(row)
	if float(row[0]) > bigx:
		bigx = float(row[0]
		if float(row[1]) > bigy:
			bigy = float(row[1]
			if float(row[0]) > smallx:
				smallx = float(row[0]
				if float(row[1]) > smally:
					smally = float(row[1]
verts.sort()
x_arr = []
y_arr = []
for vert in verts:
	x_arr.append(vert[0])
	y_arr.append(vert[1])

fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8)

ax.set_xlabel('x data')
ax.set_ylabel('y data')
ax.set_xlim(smallx,bigx)
ax.set_ylim(smally,bigy)

ax.plot(x_arr,y_arr,color='blue',lw=2)
plt.show()
fig.savefig('test.png')