When running from python console the following code works fine'
However when trying to use the same code in a myxxx.py it does not:
from sklearn import datasets
iris = datasets.load_iris()
print(iris.xx)
when testing sklearn it reports no failures
however when testing numpy I get 16 or so failures.
I don't know if these failures are related to my error or not.
This is on a windoes8.1 x64 machine.
So why would the code typed directly into the python console work but not from the file ( meaning it fails in spyder and python myfile.py)?
the error states something like unable to import numpy datasets. Sounds like some type of name clash or scope issue.
Thanks in advance
Related
I am currently trying to run a U-Net model in Keras, using PyCharm and Anaconda on Windows. My first attempts kept on working well. However, now I'm getting an error when I try to acces keras:
My imports:
from unet_model import multi_unet_model
from keras.utils import normalize
import os
import glob
import cv2
import numpy as np
from matplotlib import pyplot as plt
The error:
AttributeError: module 'tensorflow.python.client.pywrap_tf_session' has no attribute 'cxx_version'
Maybe one of you encountered the same problem and can give me a hint how to solve it.
The problem occured after trying to move the model from cpu to gpu. Now the model can't be processed at all. Maybe I changed some references without knowing it.
I am trying to follow this tutorial on PyPi (See Example -> Train Model): https://pypi.org/project/top2vec/
Very short amount of code, following it line by line:
from top2vec import Top2Vec
from sklearn.datasets import fetch_20newsgroups
newsgroups = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))
model = Top2Vec(documents=newsgroups.data, speed="learn", workers=8)
I've tried running multiple times on different datasets, yet I keep running into the following error when training/building the model:
UFuncTypeError: ufunc 'correct_alternative_cosine' did not contain a loop with signature matching types <class 'numpy.dtype[float32]'> -> None
Has anyone encountered this error before and if so how have you fixed it? Otherwise, if anyone can run this same code please let me know if you run into the same error.
Thanks
Solved this by moving from a Jupyter notebook in favor for a typical .py file, as well as cloning the library, installing the requirements to a fresh virtualenv and running the setup.py file.
I am having trouble with a Jupyter script that I am using for a class at university. Useful information: I am using a MacBook Air (first time), macOS Monterey 12.0.1, M1 Apple chip, and I am working in a conda virtual environment with conda 4.11.0 and Python 3.9.7. This is the first part of the script:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from tensorflow import keras <--
import tensorflow as tf <--
from sklearn.utils import shuffle
from sklearn import preprocessing
from keras import regularizers <--
import random
from keras.utils.vis_utils import plot_model <--
import time
from IPython.display import Image
When I run it, I get this message:
The kernel appears to have died. It will restart automatically.
I tried commenting each row, and apparently, the problem is due to the ones that I highlighted with the arrow. So there is something wrong with TensorFlow. As suggested by my professor, I went on the terminal, typed ipython, then this:
In [1]: import tensorflow
zsh: illegal hardware instruction ipython
I looked it up on the internet, and I understood that there are some incompatibilities between some Python packages and the M1 Apple chip. I tried to follow this https://github.com/apple/tensorflow_macos, but when I use the command written there, this is what happens
(phdcourse) alessandroruggieri#Alessandros-MacBook-Air ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"
ERROR: TensorFlow with ML Compute acceleration is only available on macOS 11.0 and later.
This is pretty weird, considering I have macOS 12.0.1 (as said at the beginning).
To conclude, I have seen some posts about similar issues on the internet, but they all look rather confusing, so I would really appreciate an easy and clear help.
When I run this code, this "Using TensorFlow backend" always pops up.
Even after I tried
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore)
I wonder whether I can get rid of it to make my notebook look cleaner.
Starting with tf-2.0 Keras is now the official high-level API of TensorFlow packaged within it. Not sure if it is a possibility in your case, but using tf-2.0 should remove this error. Here's a Quick Start guide if needed.
For most of the simple cases, just changing the import statement to import tensorflow.keras as keras gets it going.
I try to do some PCA and TSNE analyses. I want to use sklearn to import the PCA and TSNE package.
Internet says that I should use these imports
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html
However, I get this message when I try to import those.
ImportError: cannot import name 'PCA' from 'sklearn.decomposition' (unknown location)
I did install sklearn and am able to import sklearn.decomposition and sklearn.manifold. However, If I I try to do this:
import sklearn.decomposition as decom
decom.PCA
I get the same ImportError. I tried reinstalling sklearn and updating it, but that doesn't solve the problem. Does one of you have a clue of what I'm doing wrong? I'm using Python 3.7.8 and use jupyter lab with MiniConda.
The documentation of sklearn is version 23.2 and that is the same version as my scikit-learn is.
EDIT: I created a totally new virtual environment and now my dir(decom) is totally different. And those packages for PCA and TSNE are working. Could somebody enlighten me why those are not working in the my current environment? Does it have to do with incompatible packages? I did not get any warning for it. It is sort of solved, yet I'm curious what the reason is and how I can fix it in the future.