Skip to content

Model.fit value error #17118

Closed
Closed
@ramapati166

Description

@ramapati166

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').

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions