mirror of
https://github.com/apachecn/ailearning.git
synced 2026-02-12 14:55:51 +08:00
update some code
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user