Ниже приведен код, который я использовал:
#Divide data into train and test
p_dt_train, p_dt_test = train_test_split(p_main_df, test_size=0.2)
#Shape #(3485868, 26)
p_dt_train.shape
p_fit_DT = DecisionTreeRegressor(max_depth=2).fit(p_dt_train.iloc[:,0:26], p_dt_train.iloc[:,26])
Но когда я запускаю вышеприведенную строку кода aka p_fit_DT
, возникает следующая ошибка:
IndexError Traceback (most recent call last)
<ipython-input-59-9bbf02d21cd5> in <module>()
1 # In[1]:
2 #Decision tree for regression
----> 3 p_fit_DT = DecisionTreeRegressor(max_depth=2).fit(p_dt_train.iloc[:,0:26], p_dt_train.iloc[:,26])
4
5 #Apply model on test data
D:\My_Work\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
1470 except (KeyError, IndexError):
1471 pass
-> 1472 return self._getitem_tuple(key)
1473 else:
1474 # we by definition only have the 0th axis
D:\My_Work\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
2011 def _getitem_tuple(self, tup):
2012
-> 2013 self._has_valid_tuple(tup)
2014 try:
2015 return self._getitem_lowerdim(tup)
D:\My_Work\anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
220 raise IndexingError('Too many indexers')
221 try:
--> 222 self._validate_key(k, i)
223 except ValueError:
224 raise ValueError("Location based indexing can only have "
D:\My_Work\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
1955 return
1956 elif is_integer(key):
-> 1957 self._validate_integer(key, axis)
1958 elif isinstance(key, tuple):
1959 # a tuple should already have been caught by this point
D:\My_Work\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
2007 l = len(ax)
2008 if key >= l or key < -l:
-> 2009 raise IndexError("single positional indexer is out-of-bounds")
2010
2011 def _getitem_tuple(self, tup):
IndexError: single positional indexer is out-of-bounds
Пожалуйста, ведите меня туда, где я иду не так.Заранее спасибо.