AttributeError with my code about data attributes - python

I decided to simulate a function in a tutorial and I wonder why I am getting the error "AttributeError: 'numpy.ndarray' object has no attribute 'logpdf'"
import numpy as np
from scipy import stats
pL = stats.norm(loc=-1, scale=1).rvs(5)
pR = stats.norm(loc=1, scale=1).rvs(5)
PT = pL.logpdf(pL) - pL.logpdf(pR)

NumPy has decided not to clear the FP exception after calling fmod.
https://github.com/numpy/numpy/pull/17547#issuecomment-714310892

Related

How to add a function into utils module on titanic data set?

When I run the following code. I am having an error saying AttributeError: module 'python_utils' has no attribute 'clean_data', but I know know how to fix it.
import python_utils
import pandas as pd
from sklearn import linear_model
def clean_data(data):
data["Fare"]=data["Fare"].fillna(data["Fare"].dropna().median())
data["Age"]=data["Age"].fillna(data["age"].dropna().median())
data.loc[data["Sex"]=="male", "Sex"]=0
data.loc[data["Sex"]=="female", "Sex"]=1
data["Embarked"]=data["Embarked"].fillna("S")
data.loc[data["Embarked"]=="S",Embarked]=0
data.loc[data["Embarked"]=="C",Embarked]=1
data.loc[data["Embarked"]=="Q",Embarked]=2
train=pd.read_csv('train.csv')
python_utils.clean_data(train)
target=train["Survived"].values
features=train[["Pclass","Age","Sex","SibSp","Parch"]].values
classifier=linear_model.logisticRegression()
classifier=classifier.fit(features,target)
print(classifier_.score(features,target))

error : 'module' object is not callable when using logmmse

I am trying to reduce noise in my audio_file and want to have an output file which doesn't contain noise, and I use the logmmse library:
I use this code:
import wavio
import numpy as np
from logmmse import logmmse_from_file
import logmmse
r = wavio.read('03-01-02-02-01-01-01(read).wav')
y,sr = librosa.load('03-01-02-02-01-01-01(read).wav')
#print(y)
import numpy as np
A = np.asarray(y)
but I have this error:
TypeError: 'module' object is not callable!
can you help me please?
#print(A)
logmmse(A, r.rate, output_file = 'log.wav')
As the error states, you are trying to call the module itself. I suppose what you're trying to do is use the logmmse function inside the logmmse module, so you should do:
logmmse.logmmse(A, r.rate, output_file = 'log.wav')

AttributeError for sarimax from statsmodels.tsa.statespace

I am trying to use
model_S = statespace.sarimax.SARIMAX(df['lnpd'], trend='n', order=(12,1,12), seasonal_order=(1,1,1,12))
Shows error:
AttributeError: 'module' object has no attribute 'sarimax'
I just updated statsmodels to 0.8.0 and had no problem importing statspace. Does anyone have the same problem?
Thanks.
import statsmodels.api as sm
sm.tsa.statespace.SARIMAX(..)

AttributeError: type object 'MinimalFeatureExtractionSettings' has no attribute 'n_processes'

I'm trying to extract features using tsfresh package and extract_features() function.
tsfresh Version: 0.4.0.post0.dev1+ng19fa136
However, I get the following error:
AttributeError: type object 'MinimalFeatureExtractionSettings' has no
attribute 'n_processes'
Code:
import numpy as np
import pandas as pd
column_names = ['time_series1', 'time_series2','time_series3']
ts = np.random.rand(6,3)
df_to_extract = pd.DataFrame(data=ts, columns = column_names)
df_to_extract['id'] = 1
df_to_extract['time'] = np.arange(1,7)
#print(df_to_extract)
import tsfresh
from tsfresh import extract_features
from tsfresh import select_features
from tsfresh.utilities.dataframe_functions import impute
from tsfresh import extract_relevant_features
from tsfresh.feature_extraction import extract_features, MinimalFeatureExtractionSettings
from tsfresh.feature_extraction.settings import *
from tsfresh.feature_extraction.settings import FeatureExtractionSettings
import tsfresh.feature_extraction.settings
from tsfresh import utilities
from tsfresh import feature_extraction
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= MinimalFeatureExtractionSettings)
Package source code: https://github.com/blue-yonder/tsfresh/blob/master/tsfresh/feature_extraction/extraction.py
I'm using Python 3.5 (Anaconda) on Win10.
I suppose it could be some kind of import error.
How to solve that issue?
Problem solved
To make it work add:
settings= MinimalFeatureExtractionSettings()
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= settings)
There is no MinimalFeatureExtractionSettings object anymore. It is called MinimalFCParameters now. Thus, you would have to write the following code:
from tsfresh.feature_extraction import extract_features, MinimalFCParameters
...
minimalFCParametersForTsFresh = MinimalFCParameters()
extracted_features = extract_features(df_to_extract,column_id="id",default_fc_parameters = minimalFCParametersForTsFresh)

AttributeError: 'module' object has no attribute 'genfromtxt'

I tried running the following program
import numpy as np
data = np.genfromtxt('data.csv', delimiter = ',')
which gives
AttributeError: 'module' object has no attribute 'genfromtxt'
Help much appreciated
You must import matplotlib and it will work
copy and past next code
import numpy as np
from matplotlib import pyplot as plt
data = np.genfromtxt('data.csv', delimiter = ',')

Categories

Resources