1
import pandas as pd
import quandl 
import math
import numpy as np
from sklearn import preprocessing, model_selection,svm
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split 
import matplotlib.pyplot as plt
quandl.ApiConfig.api_key = "FVeuw21FAe86ux3J3ePr"
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['DL_PCT']=(df['Adj. Close']-df['Adj. Open'])/df['Adj. Open']*100
df=df[['Adj. Close','HL_PCT','DL_PCT','Adj. Volume']]
forcast_col='Adj. Close'
df.fillna(-9999,inplace=True)
forcast_out=int(math.ceil(0.01*len(df))) 
print(forcast_out)
df['label']=df[forcast_col].shift(-forcast_out)
df.dropna(inplace=True)
X=np.array(df.drop(['label'],1))
y=np.array(df['label'])
X=preprocessing.scale(X)

y=np.array(df['label'])
print (len(X),len(y))
X.shape[0]!=y.shape[0]
X_train,X_text,y_test,y_train=train_test_split(X,y,test_size=0.2)
plt.xlabel('area(m^2)')
plt.ylabel('price(Rs)')
plt.plot(X_train,y_train,color='blue',marker='.')
plt.show()
reg=LinearRegression()
reg.fit(X_train,y_train)
accuracy=reg.score(X_test,y_test)
print(accuracy)

error image the error i got while running this code

Traceback (most recent call last):
  File "c:/Users/user/Desktop/projetcs/machine learning/mc1.py", line 31, in <module>
    plt.plot(X_train,y_train,color='blue',marker='.')
  File "C:\Users\user\python11\lib\site-packages\matplotlib\pyplot.py", line 2824, in plot
    return gca().plot(
  File "C:\Users\user\python11\lib\site-packages\matplotlib\axes\_axes.py", line 1743, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "C:\Users\user\python11\lib\site-packages\matplotlib\axes\_base.py", line 273, in __call__
    yield from self._plot_args(this, kwargs)
  File "C:\Users\user\python11\lib\site-packages\matplotlib\axes\_base.py", line 399, in _plot_args
    raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, 
ti7
  • 16,375
  • 6
  • 40
  • 68
  • Welcome to SO! I embedded some of your post more neatly (don't worry, you can embed images with a little more reputation), but your traceback seems cut off! – ti7 Sep 04 '20 at 15:27
  • Does this answer your question? [Matplotlib: ValueError: x and y must have same first dimension](https://stackoverflow.com/questions/26690480/matplotlib-valueerror-x-and-y-must-have-same-first-dimension) – ti7 Sep 04 '20 at 15:28
  • Watch out; you have also posted your quandl API key and should change it! – ti7 Sep 04 '20 at 15:30
  • i think len(X) and len(y) has same value that why this code show this error but – abhishek sachan Sep 04 '20 at 19:57

0 Answers0