[英]how can I fit two lists in python?
我想用 sklearn 來擬合這兩個列表,但最后它說:無法將字符串轉換為浮點數......你能幫我嗎?
from sklearn import tree
x = ['BMW', '20000miles', '2010']
y = ['12000']
clf = tree.DecisionTreeClassifier()
clf = clf.fit(x, y)
很多事情。 從文檔中:
X{array-like, sparse matrix} of shape (n_samples, n_features)
The training input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csc_matrix.
yarray-like of shape (n_samples,) or (n_samples, n_outputs)
The target values (class labels) as integers or strings.
您要適合的輸入應該是一個形狀數組(n_samples,n_features)。 您有 1 個具有 3 個特征的樣本嗎? 我想這沒關系,但擬合 1 個樣本沒有多大意義。
但是您的模型無法解釋“BMW”,它需要一個浮點數。 所以如果你有3種汽車,BMW,AUDI,MERCEDES,把它們轉換成一個數字,即1,2,3來代表它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.