I'm trying to perform a test utilizing Support Vector Regression model. I inputted the data and performed the feature scaling of my dataset, however when I tried to run it to produce a graph it gives me the error "x and y isn't the same size", even though both values end on the same point in the excel dataset (row 363). The dataset contains 4 columns in this order: Date, Average Gas Price, Number of Sales and Average USD price and all the data included in this table are taken from 1st of January 2022 to 31st of October 2022. I'm trying to select 2nd column, The Average Gas Price, as my independent variable and 3rd column, the number of sales, as my dependent variable.
I'm utilizing jupyter notebook for my test.
I'll appreciate any help.
Here's what I have done so far:
import pandas as pd
> import numpy as np
> import matplotlib.pyplot as plt
>
> dataset=pd.read_excel(r'C:\\Users\\Sammy\\OneDrive - International Campus, Zhejiang University\\Desktop\\Data\\BAYC Data.xlsx')
>
> print(dataset)
>
> x=dataset.iloc\[:,1:2\].values
> y=dataset.iloc\[:,2:\].values
> from sklearn.preprocessing import StandardScaler
> st_x=StandardScaler()
> st_y=StandardScaler()
> X=st_x.fit_transform(x)
> Y=st_y.fit_transform(y)
> fig=plt.figure()
> ax=fig.add_axes(\[0,0,1,1\])
> ax.scatter(X,Y,color='r')
The value error itself:
ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_16880\3976820160.py in <module>
1 fig=plt.figure()
2 ax=fig.add_axes([0,0,1,1])
----> 3 ax.scatter(X,Y,color='r')
~\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1410 def inner(ax, *args, data=None, **kwargs):
1411 if data is None:
-> 1412 return func(ax, *map(sanitize_sequence, args), **kwargs)
1413
1414 bound = new_sig.bind(ax, *args, **kwargs)
~\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
4360 y = np.ma.ravel(y)
4361 if x.size != y.size:
-> 4362 raise ValueError("x and y must be the same size")
4363
4364 if s is None:
ValueError: x and y must be the same size
CodePudding user response:
The data might be the same size but you are selecting different sizes from it `
x=dataset.iloc[:,1:2].values
y=dataset.iloc[:,2:].values `
Make sure the iloc values are the same