Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Model.fit value error #17118

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

Closed
ramapati166 opened this issue May 4, 2020 · 5 comments
Closed

Model.fit value error #17118

ramapati166 opened this issue May 4, 2020 · 5 comments

Comments

@ramapati166
Copy link

Any idea what could be causing this error? I've been trying to solve this for a week. Thanks in advance
main program is:
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
music = pd.read_csv('sun1.csv')
X = music.drop(columns=['genre'])
y= music['genre']

model = DecisionTreeClassifier()
model.fit(X, y)
predictions=model.predict([ [21,1], [22, 0] ])
predictions

ValueError Traceback (most recent call last)
in
6
7 model = DecisionTreeClassifier()
----> 8 model.fit(X, y)
9 time.sleep(0.1)
10 predictions=model.predict([ [21,1], [22, 0] ])

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
875 sample_weight=sample_weight,
876 check_input=check_input,
--> 877 X_idx_sorted=X_idx_sorted)
878 return self
879

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
147
148 if check_input:
--> 149 X = check_array(X, dtype=DTYPE, accept_sparse="csc")
150 y = check_array(y, ensure_2d=False, dtype=None)
151 if issparse(X):

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
576 if force_all_finite:
577 _assert_all_finite(array,
--> 578 allow_nan=force_all_finite == 'allow-nan')
579
580 if ensure_min_samples > 0:

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in _assert_all_finite(X, allow_nan, msg_dtype)
58 msg_err.format
59 (type_err,
---> 60 msg_dtype if msg_dtype is not None else X.dtype)
61 )
62 # for object dtype data, we only check for NaNs (GH-13254)

ValueError: Input contains NaN, infinity or a value too large for dtype('float32').

@iobtl
Copy link

iobtl commented May 5, 2020

X = music.drop(columns=['genre'])

What kind of values do you have for this variable?

@ramapati166
Copy link
Author

numerical value not string...x represent a table consists of two columns and 20 rows. contained numerical values.

@avigupta2612
Copy link
Contributor

Make Sure to clean the dataset first. Remove or replace all the missing values. Make sure that all the values in the column is of same data type.

@alfaro96
Copy link
Member

Hey @ramapati166!

I will close this issue since it has not been updated in a long time and we are not able to reproduce it.

Feel free to re-open it if you disagree.

@ramapati166
Copy link
Author

ramapati166 commented Aug 25, 2020 via email

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

4 participants