I am trying to use machine learning Random Forest for regression problem. I am using python 3.x, and the packages numpy, matplotlib and pandas are already installed on my computer.
I am using the exact same 11 first lines of the video (https://www.youtube.com/watch?v=miI9rwH4Y4g).
My code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('testFile.csv')
X = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values
I am having the following errors:
Traceback (most recent call last):
File "D:\Cours\****************************************\RandomForestRegressionTest.py", line 9, in <module>
y = dataset.iloc[:, 2].values
File "C:\Users\******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1367, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1737, in _getitem_tuple
self._has_valid_tuple(tup)
File "C:\Users\******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 204, in _has_valid_tuple
if not self._has_valid_type(k, i):
File "C:\Users\******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1672, in _has_valid_type
return self._is_valid_integer(key, axis)
File "C:\Users\******\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1713, in _is_valid_integer
raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
Any help ???
Thank you
The problem was in the csv file. I edited the csv file using Notepad++, and changed all the ";" to "," and it works. It is weird because every csv file use ";" separator not ",".
I am surprised, but also happy because I found the error (wierd error).