我目前正在关于机器学习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:不允许整数到负整数幂 [在6.1s完成]
答案 0 :(得分:-2)
for c in np.arange (-5, 5,dtype = float):