2
我正在學習scikit學習執行某些分類。我正在跟着我的數據集的教程。當我運行該腳本,我得到一個錯誤類型Fit函數返回TypeError:float()參數必須是字符串或數字ScikitLearn
data = pd.DataFrame({'Description': pd.Categorical(["apple", "table", "red"]), 'Labels' : pd.Categorical(["Fruit","Furniture","Color"])})
counts = CountVectorizer().fit_transform(data['Description'].values)
tf_transformer = TfidfTransformer(use_idf=False).fit(counts)
train_tf = tf_transformer.transform(tf_transformer)
錯誤,我得到
Traceback (most recent call last):
File "/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-97-9a649172d3b7>", line 10, in <module>
train_tf = tf_transformer.transform(tf_transformer)
File "/anaconda/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 1005, in transform
X = sp.csr_matrix(X, dtype=np.float64, copy=copy)
File "/anaconda/lib/python2.7/site-packages/scipy/sparse/compressed.py", line 69, in __init__
self._set_self(self.__class__(coo_matrix(arg1, dtype=dtype)))
File "/anaconda/lib/python2.7/site-packages/scipy/sparse/coo.py", line 204, in __init__
self.data = self.data.astype(dtype)
TypeError: float() argument must be a string or a number
我必須做一些非常愚蠢的,因爲我不完全理解的API。有人可以告訴我如何解鎖自己?
謝謝。
該錯誤似乎沒有追溯到您編寫的任何代碼行。您需要提供該映射。 –