Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
commit 6670ca88e33eb238e668b875d86014347feac939 2 parents 8b2b13a + 729d766
@sp0rus authored
View
6,894 numpy/aapl.csv
6,894 additions, 0 deletions not shown
View
45 numpy/compare_MSFT_AAPL.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+# Read the data of AAPL and MSFT
+AAPL = np.loadtxt("aapl.csv", delimiter=',', skiprows=1, usecols=[6])
+MSFT = np.loadtxt("msft.csv", delimiter=',', skiprows=1, usecols=[6])
+
+# In both datasets, the data is in order from NEWEST to OLDEST.
+# To make things plot from OLDEST to NEWEST, we reverse the older.
+AAPL = AAPL[::-1]
+MSFT = MSFT[::-1]
+
+# Pass the data through a linear transformation.
+AAPL_linear = (AAPL - min(AAPL)) / (max(AAPL) - min(AAPL))
+MSFT_linear = (MSFT - min(MSFT)) / (max(MSFT) - min(MSFT))
+
+plt.plot(AAPL, 'b-')
+plt.plot(MSFT, 'g-')
+plt.show()
+
+raw_input()
+
+# Now center the starting points at Zero
+AAPL_linear -= AAPL_linear[0]
+MSFT_linear -= MSFT_linear[0]
+
+plt.plot(AAPL_linear, 'b-')
+plt.plot(MSFT_linear, 'g-')
+plt.show()
+
+raw_input()
+
+# Compute the CDF
+# This must be done manually
+AAPL_CDF = np.cumsum(AAPL)
+MSFT_CDF = np.cumsum(MSFT)
+
+AAPL_CDF = (AAPL_CDF - min(AAPL_CDF)) / (max(AAPL_CDF) - min(AAPL_CDF))
+MSFT_CDF = (MSFT_CDF - min(MSFT_CDF)) / (max(MSFT_CDF) - min(MSFT_CDF))
+
+plt.plot(AAPL_CDF, 'b-')
+plt.plot(MSFT_CDF, 'g-')
+plt.show()
View
6,512 numpy/msft.csv
6,512 additions, 0 deletions not shown
View
11 numpy/quartet.csv
@@ -0,0 +1,11 @@
+10.0 8.04 10.0 9.14 10.0 7.46 8.0 6.58
+8.0 6.95 8.0 8.14 8.0 6.77 8.0 5.76
+13.0 7.58 13.0 8.74 13.0 12.74 8.0 7.71
+9.0 8.81 9.0 8.77 9.0 7.11 8.0 8.84
+11.0 8.33 11.0 9.26 11.0 7.81 8.0 8.47
+14.0 9.96 14.0 8.10 14.0 8.84 8.0 7.04
+6.0 7.24 6.0 6.13 6.0 6.08 8.0 5.25
+4.0 4.26 4.0 3.10 4.0 5.39 19.0 12.50
+12.0 10.84 12.0 9.13 12.0 8.15 8.0 5.56
+7.0 4.82 7.0 7.26 7.0 6.42 8.0 7.91
+5.0 5.68 5.0 4.74 5.0 5.73 8.0 6.89
View
54 numpy/quartet.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+# Simple Linear Regression using the least squares approach.
+def linreg(X, Y):
+ assert len(X)==len(Y)
+ n = len(X)
+ EX = sum(X)
+ EY = sum(Y)
+ EX2 = sum([x*x for x in X])
+ EXY = sum([ X[i] * Y[i] for i in range(n)])
+ m = (n*EXY - EX*EY) / (n*EX2 - EX*EX)
+ b = (EY - m*EX) / n
+ return (m, b)
+
+# Read the data of AAPL and MSFT
+# [ax, ay, bx, by, cx, cy, dx, dy] = np.loadtxt("quartet.csv", delimiter=' ')
+A = np.loadtxt("quartet.csv", delimiter=' ')
+
+ax = A[:, 0]
+ay = A[:, 1]
+bx = A[:, 2]
+by = A[:, 3]
+cx = A[:, 4]
+cy = A[:, 5]
+dx = A[:, 6]
+dy = A[:, 7]
+
+print linreg(ax, ay)
+print linreg(bx, by)
+print linreg(cx, cy)
+print linreg(dx, dy)
+
+(m, b) = linreg(ax, ay)
+X = np.linspace(0., 15., 100)
+Y = X*m + b
+
+plt.plot(X, Y, 'b-')
+plt.plot(ax, ay, 'r+')
+plt.show()
+
+plt.plot(X, Y, 'b-')
+plt.plot(bx, by, 'r+')
+plt.show()
+
+plt.plot(X, Y, 'b-')
+plt.plot(cx, cy, 'r+')
+plt.show()
+
+plt.plot(X, Y, 'b-')
+plt.plot(dx, dy, 'r+')
+plt.show()
Please sign in to comment.
Something went wrong with that request. Please try again.