0
我試圖爲不同深度的決策樹計算測試和訓練錯誤。不同長度的決策樹錯誤
train_error = []
test_error = []
for i in range (3,21):
X_train, X_test, y_train, y_test = train_test_split(womendata, womeny, test_size=0.4, random_state=1)
decitiontree = tree.DecisionTreeClassifier(criterion='gini', splitter='best', max_depth=i, class_weight = 'balanced', min_samples_split=i)
clf = decitiontree.fit(X_train, y_train)
train_error.append(1 - clf.score(X_train, y_train) )
test_error.append(1 - clf.score(X_test, y_test) )
在Python 3我得到的錯誤:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/local/lib/python3.4/dist-packages/sklearn/tree/tree.py", line 154, in fit
X = check_array(X, dtype=DTYPE, accept_sparse="csc")
File "/usr/local/lib/python3.4/dist-packages/sklearn/utils/validation.py", line 398, in check_array
_assert_all_finite(array)
File "/usr/local/lib/python3.4/dist-packages/sklearn/utils/validation.py", line 54, in _assert_all_finite
" or a value too large for %r." % X.dtype)
ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
兩個womendata EN女性y是相同的長度,而且有在集中沒有丟失的數據。
這是適合你的嗎?設法解決它? – ShmulikA