私は、機械学習をPythonで学習し始めました。numpy.dot()はTypeErrorを返します: 'float'型のnon-intでシーケンスを掛けることはできません
TypeError: can't multiply sequence by non-int of type 'float'
class Perceptron(object):
def __init__(self, eta=0.01, n_iter=10):
self.eta = eta # Learning Rate
self.n_iter = n_iter # Number of iteration over the training dataset
def fit(self, x, y):
self.w_ = np.zeros(1 + x.shape[1]) # Initialize Weights to zero initially # x = {array-like} : shape[no_of_samples, no_of_features]
self.errors_ = [] # No errors in the beginning of the computation
for _ in range(self.n_iter):
errors = 0
for xi, target in zip(x, y):
update = self.eta * (target - self.predict(xi))
self.w_[1:] += update * xi
self.w_[0] += update
errors += int(update != 0.0)
self.errors_.append(errors)
return self
def net_input(self, x):
return np.dot(x, self.w_[1:]) + self.w_[0]
def predict(self, x):
return np.where(self.net_input(x) >= 0.0, 1, -1)
は私が(np.dotでnet_input()メソッドでは、エラーを取得しています):私は、エラーを与える以下のクラスを書かれています。 私は以下のデータセットを使用しています: https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv
は正しい寸法の「x」ですか? [documentation](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html)を参照してください。 – Carlos