Created
March 5, 2017 21:00
-
-
Save eric-tramel/ea48eae6d68c570b8c2d622bedc955a9 to your computer and use it in GitHub Desktop.
Test code for MLPhys Python 3 Environment
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
import scipy as sci | |
## Check Python Version | |
import sys | |
assert sys.version.find('3.6') > -1 | |
## Check numpy | |
import numpy as np | |
from math import sqrt | |
n = 1024 | |
A = np.random.randn(n, n) / sqrt(n) | |
x = np.random.randn(n) | |
y = np.dot(A,x) | |
xhat = np.linalg.solve(A,y) | |
mse = np.mean((xhat - x)**2) | |
assert mse < 1e-10 | |
## Check Matplotlib | |
import matplotlib.pyplot as plt | |
plt.figure(figsize=(5,5)) | |
x = np.random.randn(n) | |
y = 3*x + np.random.randn(n) | |
plt.plot(x,y,'.b') | |
plt.show() | |
## Check Pandas | |
import pandas as pd | |
df = pd.DataFrame( | |
{'a' : [4, 5, 6], | |
'b' : [3, 4, 2], | |
'c' : [1, 2, 3]}, | |
index = [1,2,3]) | |
## Check Scikit-Learn | |
from sklearn import datasets | |
from sklearn import svm | |
iris = datasets.load_iris() | |
clf = svm.SVC(gamma=0.001, C=100) | |
clf.fit(iris.data[:-1], iris.target[:-1]) | |
clf.predict(iris.data[-1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment