The code I'm working on is with a dataset which contains like numbers in alphabets, So I want to convert it into string to feed to into a Multivariate Model.
!pip install word2number
import pandas as pd
import math
from sklearn import linear_model
import word2number as w2n
print("sucessfully imported all the libraries")
df = pd.read_csv('hiring.csv')
df
print(w2n.word_to_num('one'))
This is my code and the error I'm getting is
AttributeError Traceback (most recent call last)
c:\Users\tanus\Desktop\Machine Learning\Regression\Multivariate Regression\Multivariate_Regression.ipynb Cell 2 in <cell line: 4>()
1 df = pd.read_csv('hiring.csv')
2 df
----> 4 print(w2n.word_to_num('one'))
AttributeError: module 'word2number' has no attribute 'word_to_num'
you have to import w2n module from word2number
from word2number import w2n
print(w2n.word_to_num('two point three'))
You are directly using word_to_num from the module i assume.
Please check the import statement.
The error is possible if you use below import.
import word2number as w2n
Hope this helps
Related
I am working on healthcare image dataset for image segmentation. More specific, it is "Spinal Cord Gray Matter Segmentation Using PyTorch". When I am trying to install libraries initially using this code:
!pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-linux_x86_64.whl
!pip3 install torchvision
!pip install medicaltorch
!pip3 install numpy==1.14.1
it is showing some errors in between required satisfied like this:
1st screenshot
2nd screenshot
After that I am importing libraries:
from collections import defaultdict
import time
import os
import numpy as np
from tqdm import tqdm
from medicaltorch import datasets as mt_datasets
from medicaltorch import models as mt_models
from medicaltorch import transforms as mt_transforms
from medicaltorch import losses as mt_losses
from medicaltorch import metrics as mt_metrics
from medicaltorch import filters as mt_filters
import torch
from torchvision import transforms
from torch.utils.data import DataLoader
from torch import autograd, optim
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torchvision.utils as vutils
cudnn.benchmark = True
import matplotlib.pyplot as plt
%matplotlib inline
This importing is throwing an error like this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-80b8c583d1fe> in <module>()
20
21
---> 22 from medicaltorch import datasets as mt_datasets
23 from medicaltorch import models as mt_models
24 from medicaltorch import transforms as mt_transforms
/usr/local/lib/python3.7/dist-packages/medicaltorch/datasets.py in <module>()
11 from torch.utils.data import Dataset
12 import torch
---> 13 from torch._six import string_classes, int_classes
14
15 from PIL import Image
ImportError: cannot import name 'int_classes' from 'torch._six' (/usr/local/lib/python3.7/dist-packages/torch/_six.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
can someone help me resolve this?
In pytorch 1.9 int_classes variable in torch._six was removed. facebookresearch/TimeSformer#47
Use this code instead.
from torch._six import string_classes
int_classes = (bool, int)
See source here: https://github.com/visionml/pytracking/issues/272
I'm getting this error while trying to import the imputer module
from sklearn.preprocessing import Imputer
Error:
ImportError Traceback (most recent call last)
<ipython-input-10-40d42fb5b303> in <module>
1 # Import the Imputer module
----> 2 from sklearn.preprocessing import Imputer
3 from sklearn.svm import SVC
4
5 # Setup the Imputation transformer: imp
ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (C:\Users\MOSTAFA\anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html
New in version 0.20: SimpleImputer replaces the previous sklearn.preprocessing.Imputer estimator which is now removed.
So, beginning with sklearn 0.20 you need to use SimpleImputer instead.
try: from sklearn.impute import SimpleImputer
I have a python file bucket.py. I'm trying to import it in to a jupyter notebook using the code below. I'm then trying to use one of the functions in it "exp1" to explore a dataframe. I'm getting the error below. Can someone please tell me how to import a file from a directory so I can use the functions in it, in my jupyter notebook?
code:
import importlib.util
spec = importlib.util.spec_from_file_location("module.name", '/Users/stuff/bucket/bucket.py')
foo = importlib.util.module_from_spec(spec)
foo.exp1(df)
error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-e1cc80f06e24> in <module>
----> 1 foo.exp1(harborsideoakland_df)
AttributeError: module 'module.name' has no attribute 'exp1'
bucket.py file:
# import libraries
import numpy as np
import pandas as pd
from time import time
import scipy.stats as stats
from IPython.display import display # Allows the use of display() for DataFrames
# # Pretty display for notebooks
# %matplotlib inline
###########################################
# Suppress matplotlib user warnings
# Necessary for newer version of matplotlib
import warnings
warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib")
#
# Display inline matplotlib plots with IPython
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
###########################################
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import warnings
warnings.filterwarnings('ignore')
import seaborn as sns
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
from sklearn.preprocessing import MinMaxScaler
from sklearn.decomposition import PCA
### HELPER FUNCTIONS:
# Initial Exploration
def exp1(df):
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
# shape of data
print('rows and columns: {}'.format(df.shape))
# head data
# display(df.head())
print('')
# data types and columns in data
print('data types and columns in data:')
print('')
#display(df.info())
print(df.info())
print('')
# unique values in each column
print('unique values in each column:')
#display(df.nunique())
print(df.nunique())
print('')
# percentage duplicates
print('percentage duplicates : {}'.format(1-(float(df.drop_duplicates().shape[0]))/df.shape[0]))
print('')
## Percentage of column with missing values
print('Percentage of column with missing values:')
print('')
missingdf=df.apply(lambda x: float(sum(x.isnull()))/len(x))
#display(missingdf.head(n=missingdf.shape[0]))
print(missingdf.head(n=missingdf.shape[0]))
print('')
print('Data snapshot:')
print('')
print(df[:5])
this worked:
import sys
sys.path.append(r'/Users/stuff/bucket/bucket')
import bucket as Lb
I've some code like:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('StudentsPerformance.csv')
#print(data.isnull().sum()) // checking if there are some missing values or not
#print(data.dtypes)checking datatypes of the dataset
# ANALYSÄ°S VALUES OF THE COLUMN'S
"""print(data['gender'].value_counts())
print(data['parental level of education'].value_counts())
print(data['race/ethnicity'].value_counts())
print(data['lunch'].value_counts())
print(data['test preparation course'].value_counts())"""
# Adding column total and average to the dataset
data['total'] = data['math score'] + data['reading score'] + data['writing score']
data['average'] = data ['total'] / 3
sns.distplot(data['average'])
I would like to see distplot of average for visualization but I run the program that gives me an error like
Traceback (most recent call last): File
"C:/Users/usersample/PycharmProjects/untitled1/sample.py", line 22, in
sns.distplot(data['average']) AttributeError: module 'seaborn' has no attribute 'distplot'
I've tried to reinstall and install seaborn and upgrade the seaborn to 0.9.0 but it doesn't work.
head of my data female,"group B","bachelor's
degree","standard","none","72","72","74" female,"group C","some
college","standard","completed","69","90","88" female,"group
B","master's degree","standard","none","90","95","93" male,"group
A","associate's degree","free/reduced","none","47","57","44"
this might be due to removal of paths in environment variables section. Try considering to add your IDE scripts and python folder. I am using pycharm IDE, and did the same and its working fine.
I am working corpus analysis for non english text, but I am facing several problem like clustering with k-means
Now I am facing problem in generating wordcloud in python 3.5.2 jupyter notebook
I installed wordcloud with command pip install wordcloud than process following code
# Simple WordCloud
from os import path
from scipy.misc import imread
import matplotlib.pyplot as plt
import random
from wordcloud import WordCloud, STOPWORDS
text = 'all your base are belong to us all of your base base base'
wordcloud = WordCloud(font_path='/Library/Fonts/Verdana.ttf',
relative_scaling = 1.0,
stopwords = 'to of'
).generate(text)
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
But got following error
ImportError Traceback (most recent call last)
in ()
5 import random
6
----> 7 from wordcloud import WordCloud, STOPWORDS
8
9 text = 'all your base are belong to us all of your base base base'
ImportError: No module named 'wordcloud'
plz help me in this concern.