title: ValueError: operands could not be broadcast together with shapes (38563,54) (38563,) while using curve_fit()
body: <p><strong>Note</strong>: This question is not a multiplication one and please ignore some of the import statements.
  Now the details are as follows, I am using a curve_fit() to fit a periodic pandas dataset. 
  Code:</p>
  
  <pre><code>import pandas as pd
  from sklearn.model_selection import train_test_split
  import numpy as np
  import datetime as dt
  from sklearn.linear_model import LinearRegression
  from sklearn import linear_model
  from sklearn.model_selection import train_test_split
  from sklearn.metrics import r2_score
  from sklearn import metrics
  from sklearn.preprocessing import StandardScaler
  from sklearn.preprocessing import PolynomialFeatures
  from scipy.optimize import leastsq
  #import matplotlib.pyplot as plt
  import pylab as plt
  from scipy.optimize import curve_fit
  
  df = pd.read_csv("Metro_Interstate_Traffic_Volume.csv")
  df['holiday'].replace(to_replace = 'None', value = '0', inplace=True)
  df.loc[df['holiday'] != '0', 'holiday'] = 1
  print(df.shape)
  
  df['date_time'] =  pd.to_datetime(df['date_time'], format='%m/%d/%Y %H:%M')
  df['date_time'] = (df['date_time']- dt.datetime(1970,1,1)).dt.total_seconds()
  
  #print(df['date_time'].head())
  
  non_dummy_cols = ['holiday','temp','rain_1h', 'snow_1h', 'clouds_all','date_time', 'traffic_volume'] 
  
  dummy_cols = list(set(df.columns) - set(non_dummy_cols))
  df = pd.get_dummies(df, columns=dummy_cols)
  print(df.shape)
  
  x = df[df.columns.values]
  x = x.drop(['traffic_volume'], axis=1)
  x = x.drop(['clouds_all'], axis = 1)
  y = df['traffic_volume']
  print(x.shape)
  print(y.shape)
  
  #plt.figure(figsize=(6,4))
  #plt.scatter(df.date_time[0:100], df.traffic_volume[0:100], color = 'blue')
  #plt.xlabel("Date Time")
  #plt.ylabel("Traffic volume")
  #plt.show()
  
  x = StandardScaler().fit_transform(x)
  
  x_train, x_test, y_train, y_test = train_test_split(x,y, test_size = 0.2, random_state= 4)
  
  def my_sin(x, freq, amplitude, phase, offset):
      return np.sin(x * freq + phase) * amplitude + offset
  
  #x_train = np.array(x_train)
  #y_train = np.array(y_train)
  
  print(x_train)
  
  popt, pcov = curve_fit(my_sin, x_train, y_train)
  y_hat = my_sin(x_test, *popt)
  </code></pre>
  
  <p><strong>Error</strong>:</p>
  
  <pre><code>ValueError: operands could not be broadcast together with shapes (38563,54) (38563,) 
  </code></pre>
  
  <p><strong>Download</strong> <a href="https://www.transfernow.net/files/?utm_source=03kof4q1ji0u&amp;utm_medium=&amp;utm_content=en" rel="nofollow noreferrer">dataset</a> URL</p>
  
  <p>The dataset before any programmatic changes is:</p>
  
  <p><a href="https://i.stack.imgur.com/HB6P6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HB6P6.png" alt="enter image description here"></a></p>
  
  <p>So how do i overcome this error? Is it not possible to use curve_fit for a m*n x_train?</p>
  
  <p>I have also tried by reshaping the y_train to m*1 or [<a href="https://i.stack.imgur.com/HB6P6.png" rel="nofollow noreferrer">2</a>,<a href="https://i.stack.imgur.com/HB6P6.png" rel="nofollow noreferrer">2</a>,....[]] like this but that's also not working. So please help me to solve this issue.</p>