Python 检查是否存在非数字值,但类型错误:'<';在';浮动';和';str';?

Python 检查是否存在非数字值,但类型错误:'<';在';浮动';和';str';?,python,python-3.x,scikit-learn,Python,Python 3.x,Scikit Learn,我正在构建一个应用程序,我需要在后台将数据提供给DecisionTreeGressor。我之前已经更正了数据中的所有非数值,但是我仍然得到了这个错误,我不确定是什么导致了它 X\u列是一个np.数组 TypeError:“我在一个输入参数中出错: max\u features=None,min\u samples\u leaf=1,max\u depth=None 因此,在将它们输入方法之前,我确保将它们转换为ints def build_tree(X_train, y_train, max_f

我正在构建一个应用程序,我需要在后台将数据提供给
DecisionTreeGressor
。我之前已经更正了数据中的所有非数值,但是我仍然得到了这个错误,我不确定是什么导致了它

X\u列
是一个
np.数组


TypeError:“我在一个输入参数中出错:

max\u features=None,min\u samples\u leaf=1,max\u depth=None

因此,在将它们输入方法之前,我确保将它们转换为
int
s

def build_tree(X_train, y_train, max_features=None, min_samples_leaf=1, max_depth=None):
    """
    Build a DecisionTreeRegressor and return the tree plus its score on the training set.
    """
    if X_train.dtype not in [np.float64, np.int32]:
        raise Exception('Input array X_train is not all numerical')

    m = DecisionTreeRegressor(max_features=max_features, min_samples_leaf=min_samples_leaf, max_depth=max_depth)
    print(X_train)
    print(y_train)
    m.fit(X_train, y_train)
    score = m.score(X_train, y_train)

    return m, score
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2314, in wsgi_app
    response = self.handle_exception(e)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1760, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/philippwulff/PycharmProjects/ki-demonstrator_wba_ima/app.py", line 83, in training
    utils.training(max_features, min_samples_leaf, max_depth)
  File "/Users/philippwulff/PycharmProjects/ki-demonstrator_wba_ima/utils.py", line 207, in training
    m, train_score = build_tree(X_train, y_train, max_features=max_features, min_samples_leaf=min_samples_leaf, max_depth=max_depth)
  File "/Users/philippwulff/PycharmProjects/ki-demonstrator_wba_ima/utils.py", line 173, in build_tree
    m.fit(X_train, y_train)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/tree/tree.py", line 1142, in fit
    X_idx_sorted=X_idx_sorted)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/tree/tree.py", line 183, in fit
    if not 0. < self.min_samples_leaf <= 0.5:
TypeError: '<' not supported between instances of 'float' and 'str'
[[ 0.0169536  -0.08805932  0.01098015  0.09977134]
 [-0.06487138 -0.10560042  0.12329933 -0.01138854]
 [ 0.02986417  0.00504991 -0.02709303 -0.01711724]
 [ 0.07041037  0.10002938  0.0148242   0.05580038]
 [ 0.11275735  0.05862036  0.13604627  0.02802539]
 [-0.07503533 -0.09884016  0.02477056  0.04107268]
 [-0.07444093 -0.04283106 -0.00823001 -0.08058039]
 [ 0.06461195  0.00344482 -0.09921795  0.02464004]
 [ 0.02081699 -0.0211672  -0.15914185  0.08355756]
 [-0.05449206 -0.00654913  0.20173392 -0.05657416]
 [-0.0797517  -0.10394467 -0.07690069  0.03757174]
 [-0.11441879  0.09815233 -0.02719179  0.0170045 ]
 [ 0.01257215  0.00143332 -0.12088713 -0.05700201]
 [-0.01474469  0.03290755  0.14115483 -0.07005832]
 [ 0.04500621 -0.02532974 -0.06386085 -0.02733249]
 [ 0.01667035  0.06482712  0.00047768 -0.04107894]
 [-0.11497694 -0.02762786 -0.00691482  0.0066152 ]
 [-0.0100544   0.08682421 -0.02454839  0.04351417]
 [ 0.00761976 -0.00315951 -0.06771497 -0.06603581]
 [-0.12733748 -0.02451606  0.03798189 -0.04613308]
 [ 0.10029473  0.07845812  0.02481654  0.10874874]
 [-0.00382413  0.02595803 -0.05036677 -0.01595229]
 [-0.01757948  0.04731672 -0.03161364 -0.05347896]
 [ 0.07906726  0.0558607  -0.00224448  0.06934733]
 [ 0.05609428 -0.01965389 -0.05568623 -0.16099433]
 [ 0.05326181 -0.05136769  0.05064158  0.06540117]
 [-0.10799619 -0.04414594  0.15584107 -0.07378936]
 [-0.05558838 -0.05923677  0.01565268 -0.09157562]
 [-0.05187193 -0.03958116 -0.0130508   0.18255574]
 [-0.00180371 -0.06889328 -0.13573403  0.02601956]
 [ 0.11917411  0.06413389  0.07089945  0.01881698]
 [ 0.04903582 -0.02532934 -0.03872357  0.01189765]
 [-0.03906277 -0.00773822  0.03927602  0.06885337]
 [-0.03668846 -0.16818079  0.01012378 -0.04025736]
 [ 0.00766697  0.02820904 -0.0632495   0.02579466]
 [-0.04012959 -0.06420964  0.12587714 -0.01336803]
 [ 0.07989258  0.01899676  0.18682888  0.09909628]
 [ 0.01511564  0.01001434  0.00037716 -0.03703526]
 [-0.04578042  0.04725017  0.02115505 -0.02056691]
 [-0.07348304  0.01184346  0.07892276 -0.07570064]
 [-0.1384743   0.01777012  0.03263807 -0.00029231]
 [ 0.0824759   0.16543293  0.02023218 -0.07075471]
 [-0.02418356  0.04983713 -0.16524179  0.06553555]
 [ 0.0016946  -0.00925339 -0.00242738 -0.00934436]
 [-0.00627135 -0.04404723  0.03565713 -0.00906244]
 [ 0.06975924  0.02057113  0.00831233 -0.07278338]
 [-0.00528811  0.04602507  0.08400528  0.10419607]
 [-0.00233647  0.00929064  0.07365617 -0.00926351]
 [ 0.06895607  0.03787905 -0.07610021 -0.13529954]
 [ 0.01732228  0.083088   -0.01443073 -0.15569616]
 [-0.05255083 -0.06568386  0.1174586  -0.07378541]
 [ 0.0571341   0.12560961 -0.08843747  0.05203625]
 [-0.05241368  0.03038565 -0.12069318 -0.00038636]
 [-0.02532426 -0.00067958  0.06592816 -0.09548021]
 [-0.04590124 -0.07451366 -0.05575454  0.03839331]
 [-0.01011185  0.06886922  0.03653133  0.13503075]
 [-0.03521947  0.03113081 -0.09983171 -0.00969662]
 [-0.01610099  0.01774162 -0.00635685 -0.10258069]
 [ 0.06964612 -0.01563268  0.09420015 -0.07074895]
 [-0.03459866 -0.10650645  0.06618658  0.08106101]
 [-0.00485046 -0.0116333   0.03548072  0.17347346]
 [-0.08247856 -0.01475688  0.01824094 -0.04868899]
 [ 0.07914827  0.02489667  0.11064371  0.01846905]
 [ 0.0647873  -0.07365439 -0.07410381  0.03684509]
 [-0.10980192  0.01625051  0.08960802 -0.09414693]
 [-0.03833209  0.13277199 -0.03721675 -0.00210564]
 [ 0.06921233  0.09863564  0.04489918  0.00497802]
 [ 0.04689576  0.09955833  0.08037274 -0.09906042]
 [-0.01355843 -0.04164554  0.09628467  0.11204992]
 [-0.03745581  0.14167463 -0.06471836  0.10101439]
 [ 0.0017556  -0.04770705  0.02093827 -0.13616193]
 [-0.01017835  0.12304962  0.07454541 -0.09885254]
 [-0.10591682 -0.103596    0.12765413 -0.11030284]
 [ 0.07009058 -0.04282568  0.1645003  -0.02907495]
 [-0.01474315 -0.02357882  0.00633438 -0.05740012]
 [ 0.06521788 -0.0519743  -0.10263768  0.0145396 ]
 [ 0.00410095  0.00921156 -0.03469556 -0.03261246]
 [-0.05910988 -0.03934184  0.07996592  0.00225417]
 [ 0.05366245 -0.02431227  0.06051538  0.02247703]
 [ 0.04893779 -0.08603129 -0.09665005 -0.00670703]
 [ 0.07456419 -0.04562     0.10344949 -0.02489417]
 [ 0.0004278  -0.05892085  0.08388173  0.00789535]
 [ 0.08996532  0.03246771 -0.01552736  0.09850172]
 [ 0.07991381  0.02658829 -0.03769747 -0.04794413]
 [ 0.05610806  0.0185944   0.04925185 -0.00089582]
 [-0.02152195  0.00636687 -0.017915    0.02404792]
 [ 0.04166803 -0.04497369  0.11543109 -0.10289702]
 [ 0.02418517 -0.02181857 -0.06853666 -0.07405074]
 [-0.0682202   0.04195905  0.05548192  0.10890684]
 [ 0.06206299 -0.13086504 -0.07709455  0.06839848]
 [-0.02614285 -0.05474784  0.10221407  0.09245584]
 [ 0.02258086  0.04768348 -0.02738017  0.02783346]
 [-0.12426329  0.06404002  0.00757445  0.10388729]
 [ 0.09550579  0.04564766  0.06982732  0.03615207]
 [ 0.06203907  0.03342094 -0.07453497 -0.0796127 ]
 [ 0.10049899 -0.0006554  -0.04297727  0.11500702]
 [ 0.0509688   0.14686354  0.02558787 -0.03896651]
 [ 0.02921698  0.04509344  0.05520885  0.01272671]
 [-0.02817095 -0.01200159  0.01850316 -0.13757669]
 [ 0.00174165  0.00731388  0.06448703 -0.11180064]]
[ -0.98442304  11.35931533  -1.21103473   6.72610292  15.22890691
  -5.40256585  -3.19144355   1.46617667  -6.1430254   13.50018305
   1.37752439   2.2576576   -2.46002386  15.52846445   0.15733659
  -4.62321478  -4.03091437  -0.74868271  -7.11219909  -1.91884923
   9.68190848  -3.51876021  -3.80305104   8.60335896   1.45801245
  11.37653209  -1.77214097  -2.83499285  -1.57184524  -2.48499794
  11.79493722   1.82887244  -2.29173292  -4.1940291    1.44688764
   3.71373931  20.58387257   0.08900766  -1.8252161   -5.20584662
  -2.11299851   9.72884337 -14.93126391   1.62450714   4.1651764
   3.35185357   3.05924345   0.06589971  -9.88043571   0.90157959
  -0.3562225   -6.82952595 -10.24287959  -0.95373195  -5.14673335
   5.39924755 -10.39311523 -10.2675593    2.26526511  -1.97856955
   6.22808786  -8.65195496   8.9564913   -5.44138043   3.13241868
  -0.04282782  11.96937012   8.39592805   1.35954277  -4.92359703
   2.22049265   9.92922458   0.15635709  14.78973919  -2.03233269
  -0.18347436  -3.49410689   4.84194422   7.40855194  -3.95309603
   9.99468005   2.06516975   6.93046327   5.25886091  10.42539139
  -6.8542529    7.68121626  -6.13449684  -9.23553769  -3.08944639
   9.17482133  -0.2699851   -5.41637163  13.74685041  -8.23549275
   0.10189677   8.63720451   5.83815795   0.18048943   1.81785325]