Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved problem in [66] ndarray DecisionTreeRegressor page 81. #160

Open
RodrigoJoaquimAlmeida opened this issue Aug 12, 2022 · 0 comments
Open

Comments

@RodrigoJoaquimAlmeida
Copy link

I found many notebooks with same error, but no one gave me back a solution to this issue:

X_train = data_train.date[:, np.newaxis]

"Support for multi-dimensional indexing (e.g. obj[:, None]) is deprecated and will be removed in a future version."

So, after looking for some answers i found this:

instead using ndarray, use just an array and them reshape it from an 1D array to 2D array with array.reshape(-1, 1) and it will be done

from sklearn.tree import DecisionTreeRegressor

data_train = ram_prices[ram_prices.date < 2000]
data_test = ram_prices[ram_prices.date >= 2000]

X_train = np.array(data_train.date)
X_train = X_train.reshape(-1, 1)
y_train = np.log(data_train.price)

tree = DecisionTreeRegressor().fit(X_train, y_train)
linear_reg = LinearRegression().fit(X_train, y_train)

X_all = np.array(ram_prices.date)
X_all = X_all.reshape(-1, 1)

pred_tree = tree.predict(X_all)
pred_lr = linear_reg.predict(X_all)

price_tree = np.exp(pred_tree)
price_lr = np.exp(pred_lr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant