tansaku / py-coursera

Python framework for Coursera PGM and ML homeworks
49 stars 63 forks source link

continuing to work on ML #8

Closed ibatugow closed 12 years ago

ibatugow commented 12 years ago

Hi Sam,

you might want to review the changes before accepting the code; it probably breaks some of your solutions. The main reason is that I made sure vectors are represented as 1D arrays, not (n,1) matrices.

I also renamed the directory to a valid Python package name, so I can write "from mlclass_ex1 import *" and such

Ioura

tansaku commented 12 years ago

Hi Ioura,

Many thanks - I guess I'm not sure how to review changes without actually merging them :-) I'll have to look that up.

Also, we have the general issue of wanting a suite of unit tests that check the system is working without exposing the answers to the solutions ...

CHEERS> SAM

On 9/4/12 10:42 PM, ibatugow wrote:

Hi Sam,

you might want to review the changes before accepting the code; it probably breaks some of your solutions. The main reason is that I made sure vectors are represented as 1D arrays, not (n,1) matrices.

I also renamed the directory to a valid Python package name, so I can write "from mlclass_ex1 import *" and such

Ioura


    You can merge this Pull Request by running:

git pull https://github.com/ibatugow/py-coursera master

Or view, comment on, or merge it at:

https://github.com/tansaku/py-coursera/pull/8

    Commit Summary
  • renamed directory to a valid python module name, ex1.py completed
  • adding ex1_multi
  • Oops.. hardcoded password removed
  • discovered column_stack
  • initial code for ex2

    File Changes
  • D ML/mlclass-ex1/ex1data1.txt (97)
  • A ML/mlclass_ex1/init.py (9)
  • A ML/mlclass_ex1/computeCost.py (0)
  • A ML/mlclass_ex1/computeCostMulti.py (0)
  • R ML/mlclass_ex1/ex1.py (58)
  • A ML/mlclass_ex1/ex1_multi.py (162)
  • A ML/mlclass_ex1/ex1data1.txt (97)
  • A ML/mlclass_ex1/featureNormalize.py (0)
  • A ML/mlclass_ex1/gradientDescent.py (0)
  • A ML/mlclass_ex1/gradientDescentMulti.py (0)
  • A ML/mlclass_ex1/normalEqn.py (0)
  • A ML/mlclass_ex1/plotData.py (0)
  • R ML/mlclass_ex1/submit.py (10)
  • A ML/mlclass_ex1/test_warmUpExercise.py (0)
  • A ML/mlclass_ex1/warmUpExercise.py (0)
  • A ML/mlclass_ex2/init.py (7)
  • A ML/mlclass_ex2/costFunction.py (31)
  • A ML/mlclass_ex2/costFunctionReg.py (0)
  • A ML/mlclass_ex2/ex2.py (81)
  • A ML/mlclass_ex2/ex2data1.txt (100)
  • A ML/mlclass_ex2/ex2data2.txt (118)
  • A ML/mlclass_ex2/plotData.py (22)
  • A ML/mlclass_ex2/plotDecisionBoundary.py (0)
  • A ML/mlclass_ex2/predict.py (0)
  • A ML/mlclass_ex2/sigmoid.py (19)
  • A ML/mlclass_ex2/submit.py (185)

    Patch Links
  • https://github.com/tansaku/py-coursera/pull/8.patch
  • https://github.com/tansaku/py-coursera/pull/8.diff

— Reply to this email directly or view it on GitHub https://github.com/tansaku/py-coursera/pull/8.

Sam's Technical Blog http://linklens.blogspot.com

tansaku commented 12 years ago

Hi Sam,

On Wednesday, September 5, 2012 10:22:04 AM UTC+2, Sam Joseph wrote:

Many thanks - I guess I'm not sure how to review changes without actually merging them :-) I'll have to look that up.

I don't know either; I had never used git a few days ago... I guess you can merge, test, and revert to a previous revision if you don't like it ?

Also, we have the general issue of wanting a suite of unit tests that check the system is working without exposing the answers to the solutions ...

I'm now working on ex2, but I'll try to add some tests later...

Ioura

tansaku commented 12 years ago

Hi Ioura,

On 9/6/12 8:43 PM, Ioura Batugowski wrote:

On Wednesday, September 5, 2012 10:22:04 AM UTC+2, Sam Joseph wrote:

Many thanks - I guess I'm not sure how to review changes without
actually merging them :-) I'll have to look that up.

I don't know either; I had never used git a few days ago... I guess you can merge, test, and revert to a previous revision if you don't like it ? I guess I can - I will go and check when I get a spare moment :-)

Also, we have the general issue of wanting a suite of unit tests
that check the system is working without exposing the answers to
the solutions ...

I'm now working on ex2, but I'll try to add some tests later... It occurs to me that the tests used in the submission script could be harnessed as a test suite to run the code against, although we still don't want to expose the solutions - perhaps we could have a battery of tests checking that incorrect solutions are failing properly ...

CHEERS> SAM

Sam's Technical Blog http://linklens.blogspot.com

tansaku commented 12 years ago

Hi Ioura,

apologies for the delay - just starting working through this, but am having trouble with imports, e.g. in ipython --pylab

In [8]: import ex1_multi

ImportError Traceback (most recent call last) /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ in () ----> 1 import ex1_multi

/Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1_multi.py in

() 28 from matplotlib.pyplot import * 29 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 30 from mlclass_ex1 import * 31 32 ## Initialization and direct running: unknownc8bcc8da38b2:mlclass_ex1 samueljoseph$ python ex1_multi.py Traceback (most recent call last): File "ex1_multi.py", line 30, in from mlclass_ex1 import * ImportError: No module named mlclass_ex1 unknownc8bcc8da38b2:mlclass_ex1 samueljose I tried removing the from mlclass_ex1 import \* statements, but then I get errors like "NameError: name 'featureNormalize' is not defined" I had been trying to automate pulling in the necessary files by adding the following to **init**.py: import os import glob **all** = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(os.path.abspath(**file**))+"/*.py")] # from http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python # AND # http://stackoverflow.com/questions/7783308/os-path-dirname-file-returns-empty but this turned out to be ineffective and at the moment the only way I can move forward is explicitly adding statements like from featureNormalize import featureNormalize directly to ex1_multi.py etc. it seems like the only way to get **init**.py to run is to move back up the directory tree one step and do import mlclass_ex1 or from mlclass_ex1 import * but for me at least in ipython import mlclass_ex1 generates no output and from mlclass_ex1 import \* gives me this error: NameError: name 'warmUpExercise' is not defined I tried putting back in the original from mlclass_ex1 import \* statements, but that gives me this error: ## In [13]: from mlclass_ex1 import * AttributeError Traceback (most recent call last) /Users/samueljoseph/Code/py-coursera/ML/ in () ----> 1 from mlclass_ex1 import * /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1.py in () 29 from matplotlib.pyplot import * 30 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 31 from mlclass_ex1 import * 32 33 # is there any equivalent to "clear all; close all; clc"? /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1_multi.py in () 28 from matplotlib.pyplot import * 29 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 30 from mlclass_ex1 import * 31 32 ## Initialization AttributeError: 'module' object has no attribute 'ex1' So I'm not sure I've achieved much apart from exposing my general poor python skills. My main question is this. How are you running these files, or intending these files to be run? Many thanks in advance CHEERS> SAM On 9/6/12 8:43 PM, Ioura Batugowski wrote: > Hi Sam, > > On Wednesday, September 5, 2012 10:22:04 AM UTC+2, Sam Joseph wrote: > > ``` > Many thanks - I guess I'm not sure how to review changes without > actually merging them :-) I'll have to look that up. > ``` > > I don't know either; I had never used git a few days ago... I guess > you can merge, test, and revert to a previous revision if you don't > like it ? > > ``` > Also, we have the general issue of wanting a suite of unit tests > that check the system is working without exposing the answers to > the solutions ... > ``` > > I'm now working on ex2, but I'll try to add some tests later... > > ## Ioura > > You received this message because you are subscribed to the Google > Groups "py-coursera" group. > To post to this group, send email to py-coursera@googlegroups.com. > To unsubscribe from this group, send email to > py-coursera+unsubscribe@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msg/py-coursera/-/If5KWI_lOnsJ. > For more options, visit https://groups.google.com/groups/opt_out. ## Sam's Technical Blog http://linklens.blogspot.com
tansaku commented 12 years ago

Hi Sam,

Sorry for the confusion. I usually work in Python with my project directory as a package located somewhere on the Python path. I find it easier, because whatever my "current directory" is, I can easily import modules in the interactive interpreter, and the init.py allows me to define "things to import by default".

To add a directory to the Python path, I usually create a file ending in .pth in the Python site-package directory. It should be a text file that contains only the path of the parent directory where the package resides (i.e., the "ML" directory of the project tree). I'm on Windows, but I guess on *nix you can also symlink the package directory in site-package.

But I'll replace the "from mlclass_ex1 import ..." by individual imports, so that it should work for everyone... Wait for another pull request; in the meantime I also started to added a few tests to ex1.

Ioura

On Wednesday, September 12, 2012 7:05:20 AM UTC+2, Sam Joseph wrote:

Hi Ioura,

apologies for the delay - just starting working through this, but am having trouble with imports, e.g. in ipython --pylab

In [8]: import ex1_multi

ImportError Traceback (most recent call last) /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ in () ----> 1 import ex1_multi

/Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1_multi.py in

() 28 from matplotlib.pyplot import * 29 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 30 from mlclass_ex1 import * 31 32 ## Initialization and direct running: unknownc8bcc8da38b2:mlclass_ex1 samueljoseph$ python ex1_multi.py Traceback (most recent call last): File "ex1_multi.py", line 30, in from mlclass_ex1 import * ImportError: No module named mlclass_ex1 unknownc8bcc8da38b2:mlclass_ex1 samueljose I tried removing the from mlclass_ex1 import \* statements, but then I get errors like "NameError: name 'featureNormalize' is not defined" I had been trying to automate pulling in the necessary files by adding the following to **init**.py: import os import glob **all** = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(os.path.abspath(**file**))+"/*.py")] # from http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python # AND # http://stackoverflow.com/questions/7783308/os-path-dirname-file-returns-empty but this turned out to be ineffective and at the moment the only way I can move forward is explicitly adding statements like from featureNormalize import featureNormalize directly to ex1_multi.py etc. it seems like the only way to get **init**.py to run is to move back up the directory tree one step and do import mlclass_ex1 or from mlclass_ex1 import * but for me at least in ipython import mlclass_ex1 generates no output and from mlclass_ex1 import \* gives me this error: NameError: name 'warmUpExercise' is not defined I tried putting back in the original from mlclass_ex1 import \* statements, but that gives me this error: ## In [13]: from mlclass_ex1 import * AttributeError Traceback (most recent call last) /Users/samueljoseph/Code/py-coursera/ML/ in () ----> 1 from mlclass_ex1 import * /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1.py in () 29 from matplotlib.pyplot import * 30 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 31 from mlclass_ex1 import * 32 33 # is there any equivalent to "clear all; close all; clc"? /Users/samueljoseph/Code/py-coursera/ML/mlclass_ex1/ex1_multi.py in () 28 from matplotlib.pyplot import * 29 from mpl_toolkits.mplot3d import axes3d, Axes3D ---> 30 from mlclass_ex1 import * 31 32 ## Initialization AttributeError: 'module' object has no attribute 'ex1' So I'm not sure I've achieved much apart from exposing my general poor python skills. My main question is this. How are you running these files, or intending these files to be run? Many thanks in advance CHEERS> SAM On 9/6/12 8:43 PM, Ioura Batugowski wrote: Hi Sam, On Wednesday, September 5, 2012 10:22:04 AM UTC+2, Sam Joseph wrote: > Many thanks - I guess I'm not sure how to review changes without > actually merging them :-) I'll have to look that up. I don't know either; I had never used git a few days ago... I guess you can merge, test, and revert to a previous revision if you don't like it ? > Also, we have the general issue of wanting a suite of unit tests that > check the system is working without exposing the answers to the solutions > ... I'm now working on ex2, but I'll try to add some tests later... ## Ioura You received this message because you are subscribed to the Google Groups "py-coursera" group. To post to this group, send email to py-co...@googlegroups.com . To unsubscribe from this group, send email to py-coursera...@googlegroups.com . To view this discussion on the web visit https://groups.google.com/d/msg/py-coursera/-/If5KWI_lOnsJ. For more options, visit https://groups.google.com/groups/opt_out. ## Sam's Technical Blog http://linklens.blogspot.com