Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't multiply sequence by non-int of type 'float' #63

Open
sprakashsingh opened this issue Aug 18, 2017 · 2 comments
Open

Comments

@sprakashsingh
Copy link

I am getting this error at the np.dot for the Iris data set. Can you explain the solution ?

Following is traceback :
Traceback (most recent call last):
File "Perceptron.py", line 61, in
ppn.train(x, y)
File "Perceptron.py", line 24, in train
update = self.eta * (target - self.predict(xi))
File "Perceptron.py", line 35, in predict
return np.where(self.net_input(X) >= 0.0, 1, -1)
File "Perceptron.py", line 32, in net_input
return np.dot(X, self.w_[1:]) + self.w_[0]

@Lijantropique
Copy link

Hello,

Glad to see you're trying the algorithms described in the book. However, I would recommend adding more context to your questions: page? chapter? section? class? method?? what input values did you use (if any)? and even better, the actual script you used.

Based on the traceback, I assume you are in chapter 2, "Implementing a perceptron learning algorithm in Python". I implemented that one some time ago and it worked just fine. Therefore, my first assumption is that you have some typo in your script (we would only know if you provide your actual code).

The type of error you mentioned is typical of trying to multiply by a string (e.g., '1.0' * 1.). Check your code and post more questions (and more context) if required.

Cheers!

@rasbt
Copy link
Owner

rasbt commented Aug 18, 2017

I agree with @Lijantropique : a bit more information would help, and I suspect a typo somewhere in the code. I just checked the code notebook and it seems to work fine with the most recent NumPy version.

If you don't like to use Jupyter Notebooks, you can also run the code from https://github.com/rasbt/python-machine-learning-book/blob/master/code/optional-py-scripts/ch02.py

I.e., in your terminal, you can run

python3 python-machine-learning-book/code/optional-py-scripts/ch02.py

and check if that works. Then, I would recommend comparing the Perceptron code in ch02.py with your script to find out any differences that may be causing your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants