Root Cause: missing code :
# add this code
weights = logRegres.gradAscent(dataArr,labelMat)
Issue 2:
如果是矩阵会报错:
x and y must have same first dimension, but have shapes (60,) and (1, 60)
x = arange(-3.0, 3.0, 0.1),len(x) = [3-(-3)]/0.1 = 60
weights是矩阵的话,y = (-weights[0]-weights[1]*x)/weights[2],len(y) = 1
Modified Code as below:
# Plotting the logistic regression best-fit line and dataset.
def plotBestFit(weights):
import matplotlib.pyplot as plt
dataMat, labelMat = loadDataSet()
dataArr = np.array(dataMat)
n = np.shape(dataArr)[0]
xcord1 = []; ycord1 = []
xcord2 = []; ycord2 = []
for i in range(n):
if int(labelMat[i]) == 1:
xcord1.append(dataArr[i, 1]); ycord1.append(dataArr[i, 2])
else:
xcord2.append(dataArr[i, 1]); ycord2.append(dataArr[i, 2])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(xcord1, ycord1, s=30, c='red', marker='s')
ax.scatter(xcord2, ycord2, s=30, c='green')
x = np.arange(-3.0, 3.0, 0.1)
y = (-weights[0] - weights[1] * x) / weights[2]
y = y.reshape((60,1)) # add this code to fix this issue
ax.plot(x, y)
plt.title('BestFit')
plt.xlabel('X1'); plt.ylabel('X2')
plt.show()
Display:
import logRegres
import imp
imp.reload(logRegres)
weights = logRegres.gradAscent(dataArr,labelMat)
logRegres.plotBestFit(weights)
最近在使用python过重遇到这个问题,NameError: name 'xxx' is not defined,在学习python或者在使用python的过程中这个问题大家肯定都遇到过,在这里我就这个问题总结以下几种情况:
错误NameError: name ‘xxx’ is not defined总结情况一:要加双引号(” “)或者(’ ‘)而没加情况二:字符缩进格式的问题情况三:`if __name__==’__main__’ :` 没有和`class类`进行对齐情况四:NameError: name ‘file’ is not defined情况五:NameError: name ‘模
python中关于 name ‘self’ is not defined 这种错误解决方法
当你遇到类似下面图片出现的这种问题时,首先你先要明白python中的方法用“self“到底是什么意思?有什么作用和必要性?
推荐大家一个链接它里面会告诉你答案:
点击打开链接:TypeError:缺少1个必需的位置参数:‘self’
描述:gradAscent()编译通不过
报错:NameError: name 'mat' is not defined
解决办法:在所有代码前引入numpy包,即插入代码:from numpy import *
原因:未引入numpy包,但使用了numpy包中的mat、shape、ones函数,导致出错
来源:逻辑斯蒂回归——画出...
return 1.0/(1+math.exp(-intX))
TypeError: only length-1 arrays can be converted to Python scalars
将math.exp改为numpy的方法numpy.exp
import numpy a...
这个错误通常是由于没有正确导入所需的库或模块导致的。在这种情况下,似乎您正在使用ResNet50模型,但是没有正确导入该模型所在的库。您需要从Keras.applications中导入ResNet50模型,具体方法如下:
from keras.applications import ResNet50
# 然后您可以使用ResNet50模型
model = ResNet50(weights='imagenet')
如果您已经正确导入了ResNet50模型库,但仍然遇到此错误,请确保您正在正确地调用模型,如上所示。
How to fix ValueError: Setting a random_state has no effect since shuffle is False.
-蔡明璇-:
ORACLE 优化---回表(TABLE ACCESS BY INDEX ROWID)
GUESS_WHO_I_AM:
【数据库管理】⑩数据字典
刍藁增二:
Go for Return Day1 20230919
白话机器学习:
Go for Return Day1 20230919
白话机器学习: