Esempio n. 1
0
def plot_epsilon_graph():
    """
    plot an epsilon graph 
    @return: list of cluster labels
    """
    warnings.filterwarnings("ignore")

    df = pd.read_csv('houshold2007.csv')
    df = df[df['Date'].apply(lambda x: x.endswith('1/2007'))]

    preprocessing(df)

    attributes = df.columns.tolist()
    data = df.to_numpy()
    nbrs = NearestNeighbors(n_neighbors=get_min_pts(attributes),
                            algorithm='auto').fit(data)
    distances, indices = nbrs.kneighbors(data)

    temp = []
    for i in range(len(distances)):
        temp.append(distances[i][len(distances[i]) - 1])
    temp.sort(reverse=True)

    plt.plot(temp)
    plt.grid(True)
    plt.xaxis('test')
    plt.title('Epsilon Threshold')
    plt.savefig('eps_plot.png')
    plt.show()
Esempio n. 2
0
def overUnderScatter(
):  # this returns a scatter plot of an over/under simulation
    n = 500
    x = np.random.rand(n)
    y = winList
    colors = (0, 0, 0)
    plt.scatter(x, y, c=colors, alpha=0.5)
    plt.set(title="Over Under Sim Returns")
    plt.ylabel('Profit')
    plt.xaxis('U.S. Dollar (Thousands)')
    plt.show()
Esempio n. 3
0
def plot_scatter_of_body(dataframe, feature_1="Body", feature_2="Score"):
    fig, ax = plt.subplots(1, figsize=(30, 6))
    dataframe["Title_len"] = dataframe[feature_1].str.split().str.len()
    dataframe = dataframe.groupby("Title_len")[feature_2].mean().reset_index()

    x = dataframe["Title_len"]
    y = dataframe["Score"]

    sns.scatterplot(x=x, y=y, data=dataframe, legend="brief", ax=ax)
    plt.title("Average Upvote by Question Body Length")
    plt.yaxis("Average Upvote")
    plt.xaxis("Question Body Length")
    plt.plot()
Esempio n. 4
0
rangeN = range(1, numberSubIntervalls)

t, w = np.polynomial.legendre.leggauss(
    order)  # t in [-1,1], w weight, ordre 50

plt.figure()
for epsilon in [1, 2, 3]:
    print epsilon
    a1 = np.array([-epsilon, -1.0])
    b1 = np.array([-epsilon, +1.0])

    a2 = np.array([epsilon, -1.0])
    b2 = np.array([epsilon, +1.0])

    int1 = [a1, b1]
    int2 = [a2, b2]

    errSing = np.array([])
    for n in rangeN:
        errSing = np.append(errSing, calculateError(int1, int2, n, order, t,
                                                    w))

#print "coucou", calculateInt(int1, int2, order, t, w)
    print(np.log(errSing))
    plt.plot(np.log(rangeN), np.log(errSing), label=epsilon)
    plt.hold(True)
    plt.legend()
plt.title("singular function for different eps")
plt.yaxis("error")
plt.xaxis("ln(number sub intervalls)")
                 feed_dict={
                     x: trainX[start:end],
                     y: trainY[start:end]
                 })

        if ((i + 1) % 7 == 0):
            [mseloss, crossError] = sess.run([loss, crossLoss],
                                             feed_dict={
                                                 x: trainX[start:end],
                                                 y: trainY[start:end]
                                             })
            mseValues.append(mseloss)
            crossValues.append(crossError)

            [mseClass, crossClass] = sess.run([mseClassError, crossClassError],
                                              feed_dict={
                                                  x: trainX[start:end],
                                                  y: trainY[start:end]
                                              })

            mseClassValues.append(mseClass)
            crossClassValues.append(1 - crossClass)

plt.title("Accuracy of Linear vs Logistic")
plt.xaxis("epochs")
plt.yaxis("accuracy")
plt.plot(mseClassValues, label="linear")
plt.plot(crossClassValues, label="logistic")
plt.legend()
plt.show()
    print(
        i,
        sqrt(np.abs(np.mean(test_scaled[:, 1, i]**2 - predictions[:, i]**2))) /
        sqrt(np.mean(test_scaled[:, 1, i]**2)))

out = 13

#pyplot.plot(series[out])
#pyplot.show()

#pyplot.plot(train_scaled_x,train_scaled[:,0,out])
#pyplot.plot(test_scaled_x,test_scaled[:,0,out])
#pyplot.plot(test_scaled_x,predictions[:,out])
#pyplot.show()

pyplot.plot(test_scaled_x, test_scaled[:, 0, out])
pyplot.plot(test_scaled_x, predictions[:, out])
pyplot.xaxis('time (minutes)')
pyplot.yaxis('B (nT)')
pyplot.show()

#pyplot.plot(nrmse)
#pyplot.show()

# track loss vs records
# array output/prediction
# null hypothesis

# check noise in data. Take diff with stencil?
# improve data saving technique
                                                       gray.shape[::-1], None,
                                                       None)

    return mtx, dist


mtx, dist = camera_calibration()

#img = mpimg.imread('camera_cal/calibration1.jpg')
img = mpimg.imread('test_images/test1.jpg')

undist = cv2.undistort(img, mtx, dist, None, mtx)
fig = plt.figure(figsize=(20, 10))
fig.add_subplot(1, 2, 1)
plt.imshow(img)
plt.xaxis()
fig.add_subplot(1, 2, 2)
plt.imshow(undist)
#cv2.destroyAllWindows()
#fig.savefig('output_images/chessboard_undistort.jpg')
#fig.savefig('output_images/test1_undistort.jpg')

# ## Next I apply a color transform consisting of a combination of a threshhold to the gradient in the x-direction and to the s-channel

# In[3]:

# Color transform

img = mpimg.imread('test_images/test1.jpg')

data = pd.read_csv('Position_Salaries.csv')
x = data.iloc[:, 1:2].values
y = data.iloc[:, 2].values

from sklearn.preprocessing import PolynomialFeatures
p = PolynomialFeatures(degree=4)
x_poly = p.fit_transform(x)

from sklearn.linear_model import LinearRegression
r = LinearRegression()
r.fit(x_poly, y)

plt.scatter(x, y, color='red')
plt.plot(x, r.predict(p.fit_transform(x)), color='blue')
plt.title("Position v/s salaries")
plt.xaxis("positions")
plt.yaxis("salaries")
plt.show()

#making the curve more smooother
x_grid = np.arange(min(x), max(x), 0.1)
x_grid = x_grid.reshape(len(x_grid), 1)

plt.scatter(x, y, color='red')
plt.plot(x_grid, r.predict(p.fit_transform(x_grid)), color='blue')
plt.title("Position v/s salaries")
plt.xlabel("positions")
plt.ylabel("salaries")
plt.show()

x_ans = np.array(6.5)