[英]Machine Learning - Why am i getting a ValueError?
我目前在《 Python for Machine Learning》一书的第3章中。 在计算机上从书中实现算法时,尽管我以与书中所述相同的方式实现代码,但仍收到ValueError指出“不允许对负整数进行整数运算”。 这里有人知道我为什么会遇到价值错误并帮助我解决它吗?
码:
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(C=1000.0, random_state = 0)
lr.fit(X_train_std, y_train)
plot_decision_regions(X_combined_std, y_combined, classifier = lr, test_idx = range(105,150))
plt.xlabel('petal length [standardized]')
plt.ylabel('petal width [standardized')
plt.legend(loc = 'upper left')
plt.show()
weights, params = [], []
for c in np.arange(-5,5):
lr = LogisticRegression(C=10**c, random_state = 0)
lr.fit(X_train_std, y_train)
weights.append(lr.coef_[1])
params.append(10**c)
weights = np.array(weights)
plt.plot(params, weights[:,0], label = 'petal length')
plt.plot(params, weights[:,1], linestyle = '--', label = 'petal width')
plt.ylabel('weight coefficient')
plt.xlabel('C')
plt.legend(loc = 'upper left')
plt.xscale('log')
plt.show()
错误:
lr = LogisticRegression(C = 10 ** c,random_state = 0)
ValueError:不允许对负整数幂进行整数运算。
[完成于6.1s]
for c in np.arange (-5, 5,dtype = float):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.