title: Fixing TypeError in Sklearn Model
body: <p>I've used <code>sklearn</code>'s <code>linear_model.Ridge()</code> numerous times. However, this time I got this error when fitting the model: </p>
  
  <p><code>TypeError: ufunc 'subtract' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''</code></p>
  
  <p>I believe the error has to do with the <code>sample_weights</code> data type. Below is my code.</p>
  
  <pre><code>X = df[['X']]
  Y = df[['Y']]
  weights = df[['Wgt']]
  weights = weights.values
  weights = weights.ravel()
  lr_rg = linear_model.Ridge(alpha=2700)
  lr_rg.fit(X, Y, sample_weight=weights)
  </code></pre>
  
  <p>Is something wrong with the weights set up? I have done a similar set up for the model previously and never had any trouble. Fitting the model without <code>sample_weights</code> works perfectly.</p>
  
  <p>I looked at this <a href="https://stackoverflow.com/questions/12588986/typeerror-generated-when-using-inplace-operations-on-numpy-arrays">question</a> but couldn't figure out how to apply it to my problem. Any help would be much appreciated.</p>