I have the following sample code, where I need to draw 2 lines, as shown in the plot below:
anomalies = anomaly_df.loc[anomaly_df['anomaly'] == True]#Plot anomaliessns.lineplot(x=anomaly_df['Date'], y=scaler.inverse_transform(anomaly_df['Close']))sns.scatterplot(x=anomalies['Date'], y=scaler.inverse_transform(anomalies['Close']), color='r')
But when i run this code i got error :
ValueError Traceback (most recent call last)Cell In[16], line 4 1 anomalies = anomaly_df.loc[anomaly_df['anomaly'] == True] 3 #Plot anomalies----> 4 sns.lineplot(x=anomaly_df['Date'], y=scaler.inverse_transform(anomaly_df['Close'])) 5 sns.scatterplot(x=anomalies['Date'], y=scaler.inverse_transform(anomalies['Close']), color='r')File c:\Users\hemic\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\preprocessing\_data.py:1085, in StandardScaler.inverse_transform(self, X, copy) 1082 check_is_fitted(self) 1084 copy = copy if copy is not None else self.copy-> 1085 X = check_array( 1086 X, 1087 accept_sparse="csr", 1088 copy=copy, 1089 dtype=FLOAT_DTYPES, 1090 force_all_finite="allow-nan", 1091 ) 1093 if sparse.issparse(X): 1094 if self.with_mean:File c:\Users\hemic\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\utils\validation.py:1035, in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 1028 else: 1029 msg = ( 1030 f"Expected 2D array, got 1D array instead:\narray={array}.\n"... 1039 "dtype='numeric' is not compatible with arrays of bytes/strings." 1040 "Convert your data to numeric values explicitly instead." 1041 )ValueError: Expected a 2-dimensional container but got <class 'pandas.core.series.Series'> instead. Pass a DataFrame containing a single row (i.e. single sample) or a single column (i.e. single feature) instead.Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
I tried putting x and y at original['Date'], and original['Close'] but I got empty result.