From c10d797c5807995405eeb7e22f0f014e186d41c0 Mon Sep 17 00:00:00 2001 From: yangjifei <1714004716@qq.com> Date: Sat, 4 Mar 2017 22:21:24 +0800 Subject: [PATCH] update some code --- .idea/MachineLearning.iml | 2 +- src/__init__.py | 28 +++++++++++++++++++ src/python/03.DecisionTree/DTSklearn.py | 6 ++++ src/python/05.Logistic/__init__.py | 28 +++++++++++++++++++ src/python/05.Logistic/core/__init__.py | 28 +++++++++++++++++++ src/python/05.Logistic/core/com/__init__.py | 28 +++++++++++++++++++ .../05.Logistic/core/com/apachecn/__init__.py | 28 +++++++++++++++++++ .../core/com/apachecn/logistic/__init__.py | 28 +++++++++++++++++++ .../com/apachecn/logistic/logRegression.py | 8 +++++- .../apachecn/logistic}/test_logRegression.py | 18 ++++++++---- src/python/05.Logistic/test/__init__.py | 27 ++++++++++++++++++ src/python/Logistic.py | 2 +- src/python/__init__.py | 28 +++++++++++++++++++ 13 files changed, 251 insertions(+), 8 deletions(-) create mode 100644 src/__init__.py create mode 100644 src/python/05.Logistic/__init__.py create mode 100644 src/python/05.Logistic/core/__init__.py create mode 100644 src/python/05.Logistic/core/com/__init__.py create mode 100644 src/python/05.Logistic/core/com/apachecn/__init__.py create mode 100644 src/python/05.Logistic/core/com/apachecn/logistic/__init__.py rename src/python/05.Logistic/{test => core/com/apachecn/logistic}/test_logRegression.py (71%) create mode 100644 src/python/05.Logistic/test/__init__.py create mode 100644 src/python/__init__.py diff --git a/.idea/MachineLearning.iml b/.idea/MachineLearning.iml index eeeea0a4..bd0813dc 100644 --- a/.idea/MachineLearning.iml +++ b/.idea/MachineLearning.iml @@ -2,7 +2,7 @@ - + diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 00000000..b69024ca --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:34 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/03.DecisionTree/DTSklearn.py b/src/python/03.DecisionTree/DTSklearn.py index 5155b214..2629ef73 100644 --- a/src/python/03.DecisionTree/DTSklearn.py +++ b/src/python/03.DecisionTree/DTSklearn.py @@ -6,6 +6,12 @@ from sklearn import tree from sklearn.metrics import precision_recall_curve from sklearn.metrics import classification_report from sklearn.cross_validation import train_test_split +""" +需要安装依赖模块: +pip install scikit_learn-0.18-cp27-cp27m-win_amd64.whl +非常完整的网址: +http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy +""" def createDataSet(): diff --git a/src/python/05.Logistic/__init__.py b/src/python/05.Logistic/__init__.py new file mode 100644 index 00000000..b69024ca --- /dev/null +++ b/src/python/05.Logistic/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:34 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/05.Logistic/core/__init__.py b/src/python/05.Logistic/core/__init__.py new file mode 100644 index 00000000..d294a8ba --- /dev/null +++ b/src/python/05.Logistic/core/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:28 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/05.Logistic/core/com/__init__.py b/src/python/05.Logistic/core/com/__init__.py new file mode 100644 index 00000000..d294a8ba --- /dev/null +++ b/src/python/05.Logistic/core/com/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:28 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/05.Logistic/core/com/apachecn/__init__.py b/src/python/05.Logistic/core/com/apachecn/__init__.py new file mode 100644 index 00000000..d294a8ba --- /dev/null +++ b/src/python/05.Logistic/core/com/apachecn/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:28 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/05.Logistic/core/com/apachecn/logistic/__init__.py b/src/python/05.Logistic/core/com/apachecn/logistic/__init__.py new file mode 100644 index 00000000..d294a8ba --- /dev/null +++ b/src/python/05.Logistic/core/com/apachecn/logistic/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:28 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/05.Logistic/core/com/apachecn/logistic/logRegression.py b/src/python/05.Logistic/core/com/apachecn/logistic/logRegression.py index e20c6440..caa026be 100644 --- a/src/python/05.Logistic/core/com/apachecn/logistic/logRegression.py +++ b/src/python/05.Logistic/core/com/apachecn/logistic/logRegression.py @@ -3,7 +3,13 @@ from numpy import * import matplotlib.pyplot as plt import time +''' +1、需要安装模块:pip install matplotlib-1.5.0-cp27-none-win_amd64.whl +由于直接安装会出现问题,所以建议下载whl包进行安装,下载网址: +https://pypi.python.org/pypi/matplotlib/1.5.0 +2、可以看见画出的图像 +''' """ @version: @@ -14,7 +20,7 @@ import time @software: PyCharm @file: logRegression01.py @time: 2017/3/3 22:03 -@test result:not pass +@test result: ok """ # sigmoid函数 diff --git a/src/python/05.Logistic/test/test_logRegression.py b/src/python/05.Logistic/core/com/apachecn/logistic/test_logRegression.py similarity index 71% rename from src/python/05.Logistic/test/test_logRegression.py rename to src/python/05.Logistic/core/com/apachecn/logistic/test_logRegression.py index d6a8f707..31cf0a57 100644 --- a/src/python/05.Logistic/test/test_logRegression.py +++ b/src/python/05.Logistic/core/com/apachecn/logistic/test_logRegression.py @@ -1,12 +1,14 @@ #!/usr/bin/env python # encoding: utf-8 +import os import sys sys.path.append("C:\Python27") from numpy import * -import matplotlib.pyplot as plt -from core.com.apachcn.logistic import logRegression +import matplotlib.pyplot as plt + +from logRegression import * """ @version: @author: yangjf @@ -16,12 +18,18 @@ from core.com.apachcn.logistic import logRegression @software: PyCharm @file: test_logRegression.py @time: 2017/3/3 22:09 +@test result: ok """ def loadData(): train_x = [] train_y = [] - fileIn = open('testData/testSet.txt') + # 获取当前文件所在路径 + project_dir = os.getcwdu() + # 截取字符串至项目名:Test\ + project_dir = project_dir[:project_dir.find("MachineLearning\\") + 15] + print project_dir + fileIn = open("%s/testData/testSet.txt" % project_dir) for line in fileIn.readlines(): lineArr = line.strip().split() train_x.append([1.0, float(lineArr[0]), float(lineArr[1])]) @@ -37,11 +45,11 @@ test_x = train_x; test_y = train_y ##第二步: 训练数据... print "step 2: training..." opts = {'alpha': 0.01, 'maxIter': 20, 'optimizeType': 'smoothStocGradDescent'} -optimalWeights = trainLogRegres(train_x, train_y, opts) +optimalWeights = trainLogRegres(train_x, train_y, opts) ##第三步: 测试 print "step 3: testing..." -accuracy = testLogRegres(optimalWeights, test_x, test_y) +accuracy = testLogRegres(optimalWeights, test_x, test_y) ##第四步: 显示结果 print "step 4: show the result..." diff --git a/src/python/05.Logistic/test/__init__.py b/src/python/05.Logistic/test/__init__.py new file mode 100644 index 00000000..4708358a --- /dev/null +++ b/src/python/05.Logistic/test/__init__.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:27 +@test result:pass +""" + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/src/python/Logistic.py b/src/python/Logistic.py index 82ca465c..dc6bc345 100644 --- a/src/python/Logistic.py +++ b/src/python/Logistic.py @@ -117,7 +117,7 @@ def plotBestFit(dataArr, labelMat, weights): def main(): project_dir = os.path.dirname(os.path.dirname(os.getcwd())) # 1.收集并准备数据 - dataMat, labelMat = loadDataSet("%s/resources/testSet.txt" % project_dir) + dataMat, labelMat = loadDataSet("%s/testData/testSet.txt" % project_dir) # print dataMat, '---\n', labelMat # 2.训练模型, f(x)=a1*x1+b2*x2+..+nn*xn中 (a1,b2, .., nn).T的矩阵值 diff --git a/src/python/__init__.py b/src/python/__init__.py new file mode 100644 index 00000000..b69024ca --- /dev/null +++ b/src/python/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +""" +@version: +@author: yangjf +@license: ApacheCN +@contact: highfei2011@126.com +@site: https://github.com/apachecn/MachineLearning +@software: PyCharm +@file: __init__.py.py +@time: 2017/3/4 21:34 +@test result:pass +""" + + +def func(): + pass + + +class Main(): + def __init__(self): + pass + + +if __name__ == '__main__': + pass \ No newline at end of file