李芝龙 před 5 roky
rodič
revize
3c086e47c2
3 změnil soubory, kde provedl 71 přidání a 61 odebrání
  1. 2 2
      README.md
  2. 20 10
      ipynb_importer.py
  3. 49 49
      prettyPicture.py

+ 2 - 2
README.md

@@ -1,3 +1,3 @@
-# Intro to Machine Learning
-
+# Intro to Machine Learning
+
 This course is from Udacity Ud120.

+ 20 - 10
ipynb_importer.py

@@ -1,10 +1,15 @@
-import io, os,sys,types
+import io
+import os
+import sys
+import types
 from IPython import get_ipython
 from nbformat import read
 from IPython.core.interactiveshell import InteractiveShell
 
+
 class NotebookFinder(object):
     """Module finder that locates Jupyter Notebooks"""
+
     def __init__(self):
         self.loaders = {}
 
@@ -22,6 +27,7 @@ class NotebookFinder(object):
             self.loaders[key] = NotebookLoader(path)
         return self.loaders[key]
 
+
 def find_notebook(fullname, path=None):
     """find a notebook, given its fully qualified name and an optional path
 
@@ -41,8 +47,10 @@ def find_notebook(fullname, path=None):
         if os.path.isfile(nb_path):
             return nb_path
 
+
 class NotebookLoader(object):
     """Module Loader for Jupyter Notebooks"""
+
     def __init__(self, path=None):
         self.shell = InteractiveShell.instance()
         self.path = path
@@ -51,13 +59,12 @@ class NotebookLoader(object):
         """import a notebook as a module"""
         path = find_notebook(fullname, self.path)
 
-        print ("importing Jupyter notebook from %s" % path)
+        print("importing Jupyter notebook from %s" % path)
 
         # load the notebook object
         with io.open(path, 'r', encoding='utf-8') as f:
             nb = read(f, 4)
 
-
         # create the module and add it to sys.modules
         # if name in sys.modules:
         #    return sys.modules[name]
@@ -73,13 +80,16 @@ class NotebookLoader(object):
         self.shell.user_ns = mod.__dict__
 
         try:
-          for cell in nb.cells:
-            if cell.cell_type == 'code':
-                # transform the input to executable Python
-                code = self.shell.input_transformer_manager.transform_cell(cell.source)
-                # run the code in themodule
-                exec(code, mod.__dict__)
+            for cell in nb.cells:
+                if cell.cell_type == 'code':
+                    # transform the input to executable Python
+                    code = self.shell.input_transformer_manager.transform_cell(
+                        cell.source)
+                    # run the code in themodule
+                    exec(code, mod.__dict__)
         finally:
             self.shell.user_ns = save_user_ns
         return mod
-sys.meta_path.append(NotebookFinder())
+
+
+sys.meta_path.append(NotebookFinder())

+ 49 - 49
prettyPicture.py

@@ -1,50 +1,50 @@
-#!/usr/bin/python
-  
-import matplotlib.pyplot as plt
-import numpy as np
-import pylab as pl
-
-
-def prettyPicture(clf, X_test, y_test):
-    x_min = 0.0; x_max = 1.0
-    y_min = 0.0; y_max = 1.0
-    
-    # Plot the decision boundary. For that, we will assign a color to each
-    # point in the mesh [x_min, m_max]x[y_min, y_max].
-    h = .01  # step size in the mesh
-    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
-    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
-
-    # Put the result into a color plot
-    Z = Z.reshape(xx.shape)
-    plt.xlim(xx.min(), xx.max())
-    plt.ylim(yy.min(), yy.max())
-
-    plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)
-
-    # Plot also the test points
-    grade_sig = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==0]
-    bumpy_sig = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==0]
-    grade_bkg = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==1]
-    bumpy_bkg = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==1]
-
-    plt.scatter(grade_sig, bumpy_sig, color = "b", label="fast")
-    plt.scatter(grade_bkg, bumpy_bkg, color = "r", label="slow")
-    plt.legend()
-    plt.xlabel("bumpiness")
-    plt.ylabel("grade")
-
-    #plt.savefig("test.png")
-
-import base64
-import json
-
-
-def output_image(name, format, bytes):
-    image_start = "BEGIN_IMAGE_f9825uweof8jw9fj4r8"
-    image_end = "END_IMAGE_0238jfw08fjsiufhw8frs"
-    data = {}
-    data['name'] = name
-    data['format'] = format
-    data['bytes'] = base64.encodestring(bytes)
+#!/usr/bin/python
+  
+import matplotlib.pyplot as plt
+import numpy as np
+import pylab as pl
+
+
+def prettyPicture(clf, X_test, y_test):
+    x_min = 0.0; x_max = 1.0
+    y_min = 0.0; y_max = 1.0
+    
+    # Plot the decision boundary. For that, we will assign a color to each
+    # point in the mesh [x_min, m_max]x[y_min, y_max].
+    h = .01  # step size in the mesh
+    xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
+    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
+
+    # Put the result into a color plot
+    Z = Z.reshape(xx.shape)
+    plt.xlim(xx.min(), xx.max())
+    plt.ylim(yy.min(), yy.max())
+
+    plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)
+
+    # Plot also the test points
+    grade_sig = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==0]
+    bumpy_sig = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==0]
+    grade_bkg = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==1]
+    bumpy_bkg = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==1]
+
+    plt.scatter(grade_sig, bumpy_sig, color = "b", label="fast")
+    plt.scatter(grade_bkg, bumpy_bkg, color = "r", label="slow")
+    plt.legend()
+    plt.xlabel("bumpiness")
+    plt.ylabel("grade")
+
+    #plt.savefig("test.png")
+
+import base64
+import json
+
+
+def output_image(name, format, bytes):
+    image_start = "BEGIN_IMAGE_f9825uweof8jw9fj4r8"
+    image_end = "END_IMAGE_0238jfw08fjsiufhw8frs"
+    data = {}
+    data['name'] = name
+    data['format'] = format
+    data['bytes'] = base64.encodestring(bytes)
     print(image_start+json.dumps(data)+image_end)