我正在用python编写一个数字识别程序。基本代码如下:
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
filteredColumns = delete_useless_columns()
train = pd.read_csv('C:\Users\abchauhan\Downloads\train.csv')
trainData = train.loc[0:24998, filteredColumns]
target = train['label']
targetData = target[0:24999]
rf = RandomForestClassifier(n_estimators=150, min_samples_split=2, n_jobs=-1)
x = trainData/255 #Feature scaling
print('Fitting the data')
rf.fit(x, targetData)
特征缩放线给出错误:TypeError: Could not operate 255 with block values
。现在,如果我删除RandomForestClassifier
导入语句,则功能缩放可以正常工作,但很明显,该程序没有任何用处。为什么该部门在没有进口声明的情况下工作?
编辑:trainData.info()
如下:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 24999 entries, 0 to 24998
Columns: 708 entries, pixel12 to pixel779
dtypes: int64(708)
memory usage: 135.2 MB
None
堆栈跟踪如下:
Traceback (most recent call last):
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 965, in eval
result = get_result(other)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 949, in get_result
return self._try_coerce_result(func(values, other))
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreops.py", line 765, in na_op
op, str_rep, x, y, raise_on_error=True, **eval_kwargs)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascomputationexpressions.py", line 218, in evaluate
**eval_kwargs)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascomputationexpressions.py", line 71, in _evaluate_standard
return op(a, b)
MemoryError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/abchauhan/PycharmProjects/DigitRecognition/PreProcess/RandomForest.py", line 20, in <module>
x = trainData/255
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreops.py", line 831, in f
return self._combine_const(other, na_op)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreframe.py", line 3111, in _combine_const
new_data = self._data.eval(func=func, other=other, raise_on_error=raise_on_error)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 2478, in eval
return self.apply('eval', **kwargs)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 2457, in apply
applied = getattr(b, f)(**kwargs)
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 972, in eval
result = handle_error()
File "C:Python34libsite-packagespandas-0.15.2-py3.4-win32.eggpandascoreinternals.py", line 956, in handle_error
% (repr(other), str(detail)))
TypeError: Could not operate 255 with block values
Process finished with exit code 1
这是一个内存错误,如堆栈跟踪中的第一个错误所示。