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

@@ -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():

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

View File

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