当前位置: 代码迷 >> GIS >> 【机器学习实战】Logistic回归(一)
  详细解决方案

【机器学习实战】Logistic回归(一)

热度:377   发布时间:2016-05-05 06:05:31.0
【机器学习实战】Logistic回归(1)

直接调用源码。调试过程如下

1.在Python Shell下调用open函数打开txt文件的文件路径写法:

f=open("d:/tmp.txt")或f=open("d://tmp.txt")或f=open("d:\\tmp.txt")

包含中文的路径:

srcfile = r"D:/测试路径/测试文件.txt"f = open(srcfile.decode('utf8').encode('gbk'))注意路径是用'/'。

2.在shell中导入py源码

>>> import sysort sys>>> sys.path.append('F:\temp')>>> import logRegres

error1 :

No module named logRegres

error1 cleared by:

>>>sys.path.append('F:\\temp')

new error2 occured:

SyntaxError: Non-ASCII character '\xe8' in file F:\temp\logRegres.py on line 14, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

error2 cleared by:

去除第14行的中文注释。

go on:

>>>dataArr,labelMat=logRegres.loadDataSet()

error3 occured:

IOError: [Errno 2] No such file or directory: 'testSet.txt'

error3 cleared by:

读 testSet.txt 的原代码:

fr = open(‘testSet.txt’)

改为:

dataMat = []; labelMat = []
BASE_DIR = os.path.dirname(file)
print BASE_DIR
file_path = os.path.join(BASE_DIR, ‘testSet.txt’)
fr = open(file_path)

记得在开头增加一句:import os

tips:

改动过py文件中的代码后,在shell中调试新版本代码应该先运行一句:

reload(py文件名不带后缀)

版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案