ModuleNotFoundError: no module named 'scipy' - python-3.x

Hi I am bit of newby tinkering around with some machine learning, and I am getting an error in the python shell for scipy. I did a pip install for scipy in the windows command prompt and there are some odd looking errors when pip attempts to install. This is the simple little code I am using, any ideas to try for the scipy error?
import pandas as pd
import math
import numpy as np
import scipy
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\test_SP data\\testElectData.csv')
df = df[['kWhDay','CDDbase55',]]
print(df.head())
# forecast_col = 'kWhDay'
X = np.array(df.drop(['kWhDay'],1))
y = np.array(df.drop(['CDDbase55'],1))

I figured this out on how to install python modules thru wheels. Good U tube video to make it work
https://www.youtube.com/watch?v=YXIlclFQZVU

Related

Cannot import name 'plot_precision_recall_curve' from 'sklearn.metrics'

Hello i got trouble to import my package?cannot import name from sklearn
cannot import name 'plot_precision_recall_curve' from 'sklearn.metrics' (\Programs\Python\Python311\Lib\site-packages\sklearn\metrics_init_.py)
i try uninstall and install again pip install scikit-learn still not working at VScode
jupyter, python, scikit-learn
That function is from an old version of scikit-learn.
You can try using scikit-plot
Installation
pip install scikit-plot
Import library
# Import scikit-plot
import scikitplot as skplt
import matplotlib.pyplot as plt
skplt.metrics.plot_precision_recall(y, y_pred)
plt.show()
Documentation: https://scikit-plot.readthedocs.io/en/stable/metrics.html#scikitplot.metrics.plot_precision_recall
Or you can use precision_recall_curve in the current version of sklearn as mentioned by Dr. Snoopy
from sklearn.metrics import precision_recall_curve

Ordinal Logistic Regression in python and Google Colab

I have been trying to import statmodels (https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html#Probit-ordinal-regression:) to google colab without success.
I tried pip install statmodels which worked but then when I tried to import the ordinal model following the code from the above website:
import numpy as np
import pandas as pd
import scipy.stats as stats
from statsmodels.miscmodels.ordinal_model import OrderedModel
The following error message came up:
ModuleNotFoundError: No module named 'statsmodels.miscmodels.ordinal_model'
I have tried to follow the instruction from https://www.statsmodels.org/devel/install.html but I am not sure what went wrong, please help, thank you so much
The module location has changed to from statsmodels.discrete.discrete_model import OrderedModel

AttributeError: module 'numpy.random' has no attribute 'BitGenerator' in python 3.8.10

I'm trying to import the xarray module into python 3.8.10 but I get this error:
AttributeError: module 'numpy.random' has no attribute 'BitGenerator'
In order to allow you to reproduce the error: First of all, I created a new environment with conda and by importing at the same time the modules I need (to avoid the problems of incompatible dependencies) :
conda create -n Myenv Python=3.8 matplotlib numpy time xarray netCDF4 termcolor
Then, I try to import in ipython3 all modules I need to run my code:
import matplotlib as mpl
mpl.use('agg')
import numpy as np
import os
import time
import glob
import sys
from datetime import datetime,date,timedelta
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.colors as colors
# from operator import itemgetter
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap, shiftgrid
from termcolor import colored
import xarray as xr
and, at this moment, I get the error...
I searched the documentation to see if the BitGenerator Attribute exists in my version of numpy (1.22.3), and it does. So I don't understand why this error occurs.
Someone can help me to understand please ?
Thank u !
If you want more informations about my environnement, I can provide.
I solved mine with pip install --upgrade numpy

Ubuntu Linux python plot from emacs, cannot import name '_imaging' from 'PIL'

I just got Ubuntu and I'm trying to experiment abit with emacs. Wrote a simple python code that was supposed to make a plot, but when I try to run the code I get this message;
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/init.py)
And also I get alot of other random stuff, but I think this is the actual error.
I generally want to run the code from the terminal window, and then get out the plot.
Here is the code:
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0,2.0,0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t,s)
plt.show()
I fixed the issue! Just used
pip install --upgrade --force-reinstall Pillow

Why my python do not work with seaborn

import pandas as pd
import numpy as np
import sklearn
from scipy import stats
import matplotlib.pyplot as plt
import os
import seaborn as sns
sns.set(); np.random.seed(0)
x = np.random.randn(100)
sns.distplot(x)
I just copy the example from the documention,but I get such error,I have try to change the enviroment such in shell to run it .But fail too.
Traceback (most recent call last):
File "/Users/Betterwittyman/Desktop/job_25/别人的/pdf_model2.py", line 13, in <module>
sns.distplot(x)
TypeError: slice indices must be integers or None or have an __index__ method
Can you tell me the numpy and statsmodel version that you use ?
You can try the following:
1) Update the statsmodel package using
pip install -U statsmodels
2) can you try to run the following and let me if it works?
sns.distplot(x, bins=50, kde=False)
plt.show()
P.S: your code works for me using: numpy: 1.11.3, scipy: 0.18.1, statsmodels: 0.6.1
May be the version is not up to date.so follow the below command it worked.
sudo pip install --upgrade seaborn
This may solve your error:
import pandas as pd
import numpy as np
import sklearn
from scipy import stats
import matplotlib.pyplot as plt
import os
import seaborn as sns
sns.set()
np.random.seed(0)
x = np.random.randn(100)
sns.distplot(x)

Resources