title: Matplotlib histogram corrupting sklearn linear regression
body: <p>I am fitting a linear regression model with scikit-learn. The training of the model works fine on its own and runs without errors. The problem is that, if I plot a histogram of the dataset using matplotlib before I train the model, this leads to an error when training the model. I have already figured out that plotting any matplotlib histogram before training the model leads to an error so it has nothing to do with manipulating the dataset when creating the histogram.</p>
  <p>Here are my library version numbers:</p>
  <pre><code>numpy 1.19.0
  scikit-learn 0.23.0
  matplotlib 3.1.0
  pandas 1.0.5 
  </code></pre>
  <p>Minimum reproducible example (adapted from an official sklearn <a href="https://scikit-learn.org/stable/auto_examples/linear_model/plot_ols.html" rel="nofollow noreferrer">example</a>)</p>
  <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt
  import numpy as np
  from sklearn import datasets, linear_model
  
  plt.hist([1, 2, 3])
  plt.show()
  
  diabetes_X, diabetes_y =datasets.load_diabetes(return_X_y=True)
  diabetes_X = diabetes_X[:, np.newaxis, 2]
  diabetes_X_train = diabetes_X[:-20]
  diabetes_X_test = diabetes_X[-20:]
  diabetes_y_train = diabetes_y[:-20]
  diabetes_y_test = diabetes_y[-20:]
  regr = linear_model.LinearRegression()
  regr.fit(diabetes_X_train, diabetes_y_train)
  </code></pre>
  <p>Resulting Error:</p>
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
  File &quot;test2.py&quot;, line 15, in &lt;module&gt; regr.fit(diabetes_X_train, diabetes_y_train)
  File &quot;base.py&quot;, line 547, in fit linalg.lstsq(X, y)
  File &quot;basic.py&quot;, line 1226, in lstsq
  % (-info, lapack_driver))
  ValueError: illegal value in 4-th argument of internal None
  </code></pre>
  <p>Minimum example from my code:</p>
  <pre class="lang-py prettyprint-override"><code>from sklearn import datasets
  import sklearn.model_selection as ms
  import pandas as pd
  import matplotlib.pyplot as plt
  import numpy as np
  from sklearn.linear_model import LinearRegression
  
  
  plt.hist([1,2,3,4,5,6,7,8,9])
  plt.show()
  
  dataset_boston = datasets.load_boston(return_X_y=False)
  
  indices = list(range(0, len(dataset_boston.data)))
  dataframe = pd.DataFrame(data=dataset_boston.data, index=indices, columns=dataset_boston.feature_names)
  targets = pd.DataFrame(data=dataset_boston.target,  index=indices, columns=['target'])
  
  dataframe['target'] = targets
  dataframe = dataframe.replace([np.inf, -np.inf], np.nan)
  dataframe = dataframe.dropna()
  train_set_ex4, test_set_ex4 = ms.train_test_split(dataframe, test_size=0.2, random_state=42, shuffle=True)
  train_examples = train_set_ex4.loc[:, train_set_ex4.columns != 'target']
  train_targets = train_set_ex4['target']
  
  reg = LinearRegression()
  reg.fit(train_examples, train_targets)
  </code></pre>
  <p>Resulting Error:</p>
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
  File &quot;test.py&quot;, line 25, in &lt;module&gt; reg.fit(train_examples, train_targets)
  File &quot;base.py&quot;, line 547, in fit linalg.lstsq(X, y)
  File &quot;basic.py&quot;, line 1223, in lstsq
  raise LinAlgError(&quot;SVD did not converge in Linear Least Squares&quot;)
  numpy.linalg.LinAlgError: SVD did not converge in Linear Least Squares
  </code></pre>
  <p>Both of these examples run without any error when the histogram plot is removed. Am I doing something wrong or is there perhaps a bug in one of the libraries used?</p>