简体   繁体   中英

Machine Learning - Why am i getting a ValueError?

I am currently on chapter 3 on the python for Machine Learning book. While implementing a algorithm from the book on the computer, I am getting a ValueError stating that 'Integers to negative integers are not allowed', even though I been implementing the code same way described on the book. Do anyone here know why I am getting a valueerror and help me to fix it?

Code:

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()

Error:

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):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM