I am trying to follow a youtube machine learning tutorial from sentdex.Link
When I try to plot the graph using
df['forecast'].plot()
I get the error -TypeError: no numeric data to plot
However,
df['Adj. Close'].plot()
renders perfectly.
My code is-
'''
df=quandl.get("WIKI/GOOGL")
df=df[['Adj. Open', 'Adj. High', 'Adj. Low', 'Adj. Close', 'Adj. Volume']]
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Close']) / df['Adj. Close'] *100
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open'] *100
forecast_col='Adj. Close'
df.fillna(-99999, inplace=True)
forecast_out = int(math.ceil(0.01*len(df)))
print(len(df) ,forecast_out)
df['label'] = df[forecast_col].shift(-forecast_out)
X=np.array(df.drop(['label'], axis=1 ))
X=preprocessing.scale(X)
X=X[:-forecast_out]
X_lately=X[-forecast_out:]
df.dropna(inplace=True)
y=np.array(df[['label']])
algo=LinearRegression(n_jobs=-1)
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.2)
algo.fit(X_train,y_train)
y_pred =algo.predict(X_lately)
df['forecast']=np.nan
last_date=df.iloc[-1].name
last_unix=last_date.timestamp()
one_day = 86400
next_unix = last_unix +one_day
for i in y_pred:
next_date =datetime.datetime.fromtimestamp(next_unix)
next_unix += one_day
df.loc[next_date]= [np.NaN for _ in range(len(df.columns)-1)] + [i]
df['Adj. Close'].plot()
df['forecast'].plot()
plt.show()
'''
question from:
https://stackoverflow.com/questions/65844323/getting-error-typeerror-no-numeric-data-to-plot-even-while-following-a-tutor 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…