Python data not being converted

Viewed 59

I created a decision tree model in python by training the data set but found the data conversion did not happen from string to float. Even though after trying to convert the float manually still prompts some arrays cannot be converted to float. any solutions?

enter image description here enter image description here enter image description here

3 Answers

Your x_train or y_train are not supposed to be strings. They should be of type numpy.ndarray. Can you check or provide us the code for the place where you are splitting the data?

This is occurring due something which was done wrong previously. Need more insight to the code.

I have practiced with this dataset before and I think what is going wrong for you, is trying to shift days before you are getting 'Close' column as a dataframe. Try:

df = df[['Close']]

before you shift days (Which is the 45th execution of your screenshots). It could do the trick.

(Next time, please add code in text instead of screenshots.)

Your string data needs some pre-processing before it can be converted to float. You can convert your data to categorial variables(if you haven't already done so). For example, if using pandas:

x_train = pd.get_dummies(x_train)
tree = DecisionTreeRegressor().fit(x_train, y_train)
# more actions

Furthermore, I can see from the error, that you have datetime data. You should convert these to a timestamp.

x_train['Date'] = pd.to_datetime(x_train['Date'])

The rest of the preprocessing is up to you. There is a plethora of relevant tutorials.

Related