I trying to use sklearn and ran into an error, but I have no idea what is wrong. This is my code:
import pandas as pdd
from sklearn.tree import DecisionTreeClassifier
df = pd.read_csv('vgsales.csv')
X = df.drop(columns=['Name','Platform','Publisher','Genre'])#input
y = df['Rank']#output
model = DecisionTreeClassifier()
model.fit(X, y)
predictions = model.predict([16598],[])
predictions
This is my error:
ValueError Traceback (most recent call last)
<ipython-input-28-152586bc1b23> in <module>()
8 df = df.reset_index()
9 model = DecisionTreeClassifier()
---> 10 model.fit(X, y)
11 predictions = model.predict([16598],[])
12 predictions
/home/frankie/anaconda2/lib/python2.7/site-packages/sklearn/tree/tree.pyc in fit(self, X, y,
sample_weight, check_input, X_idx_sorted)
788 sample_weight=sample_weight,
789 check_input=check_input,
--> 790 X_idx_sorted=X_idx_sorted)
791 return self
792
/home/frankie/anaconda2/lib/python2.7/site-packages/sklearn/tree/tree.pyc in fit(self, X, y,
sample_weight, check_input, X_idx_sorted)
114 random_state = check_random_state(self.random_state)
115 if check_input:
--> 116 X = check_array(X, dtype=DTYPE, accept_sparse="csc")
117 y = check_array(y, ensure_2d=False, dtype=None)
118 if issparse(X):
/home/frankie/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.pyc in
check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd,
ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
451 % (array.ndim, estimator_name))
452 if force_all_finite:
--> 453 _assert_all_finite(array)
454
455 shape_repr = _shape_repr(array.shape)
/home/frankie/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.pyc in
_assert_all_finite(X)
42 and not np.isfinite(X).all()):
43 raise ValueError("Input contains NaN, infinity"
---> 44 " or a value too large for %r." % X.dtype)
45
46
ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
Any help would be greatly appreciated and I am typing this stuff because stackoverflow is saying I need more text