gpt4 book ai didi

python - 机器学习 - 为什么我会收到 ValueError?

转载 作者:行者123 更新时间:2023-11-30 09:25:10 24 4
gpt4 key购买 nike

我目前正在阅读《Python 机器学习》一书的第 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: Integers to negative integer powers are not allowed.
[Finished in 6.1s]

最佳答案

for c in np.arange (-5, 5,dtype  = float):

关于python - 机器学习 - 为什么我会收到 ValueError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45899874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com