[英]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.