update some code

This commit is contained in:
yangjifei
2017-03-04 22:21:24 +08:00
parent 0c43981c76
commit c10d797c58
13 changed files with 251 additions and 8 deletions

View 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

View 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

View 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

View 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

View 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

View File

@@ -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函数

View File

@@ -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..."

View 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