mirror of
https://github.com/apachecn/ailearning.git
synced 2026-02-09 21:36:27 +08:00
update some code
This commit is contained in:
@@ -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():
|
||||
|
||||
28
src/python/05.Logistic/__init__.py
Normal file
28
src/python/05.Logistic/__init__.py
Normal file
@@ -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
|
||||
28
src/python/05.Logistic/core/__init__.py
Normal file
28
src/python/05.Logistic/core/__init__.py
Normal file
@@ -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
|
||||
28
src/python/05.Logistic/core/com/__init__.py
Normal file
28
src/python/05.Logistic/core/com/__init__.py
Normal file
@@ -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
|
||||
28
src/python/05.Logistic/core/com/apachecn/__init__.py
Normal file
28
src/python/05.Logistic/core/com/apachecn/__init__.py
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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函数
|
||||
|
||||
@@ -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..."
|
||||
27
src/python/05.Logistic/test/__init__.py
Normal file
27
src/python/05.Logistic/test/__init__.py
Normal file
@@ -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
|
||||
@@ -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的矩阵值
|
||||
|
||||
28
src/python/__init__.py
Normal file
28
src/python/__init__.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user