简体   繁体   English

AttributeError:类型对象'object'没有属性'dtype'

[英]AttributeError: type object 'object' has no attribute 'dtype'

I'm trying to replicate the results described in How to Determine the Best Fitting Data Distribution Using Python .我正在尝试复制如何使用 Python 确定最佳拟合数据分布中描述的结果。 I used then the following code:然后我使用了以下代码:

import numpy as np
from distfit import distfit

# Generate 10000 normal distribution samples with mean 0, std dev of 3 
X = np.random.normal(0, 3, 10000)

# Initialize distfit
dist = distfit()

# Determine best-fitting probability distribution for data
dist.fit_transform(X)

Anyway, I obtained the following error:无论如何,我得到了以下错误:

[distfit] >fit..
[distfit] >transform..
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-02f73e7f157d> in <module>
      9 
     10 # Determine best-fitting probability distribution for data
---> 11 dist.fit_transform(X)

~\Anaconda3\lib\site-packages\distfit\distfit.py in fit_transform(self, X, verbose)
    275         self.fit(verbose=verbose)
    276         # Transform X based on functions
--> 277         self.transform(X, verbose=verbose)
    278         # Store
    279         results = _store(self.alpha,

~\Anaconda3\lib\site-packages\distfit\distfit.py in transform(self, X, verbose)
    214         if self.method=='parametric':
    215             # Compute best distribution fit on the empirical X
--> 216             out_summary, model = _compute_score_distribution(X, X_bins, y_obs, self.distributions, self.stats, verbose=verbose)
    217             # Determine confidence intervals on the best fitting distribution
    218             model = _compute_cii(self, model, verbose=verbose)

~\Anaconda3\lib\site-packages\distfit\distfit.py in _compute_score_distribution(data, X, y_obs, DISTRIBUTIONS, stats, verbose)
    906     model['params'] = (0.0, 1.0)
    907     best_score = np.inf
--> 908     df = pd.DataFrame(index=range(0, len(DISTRIBUTIONS)), columns=['distr', 'score', 'LLE', 'loc', 'scale', 'arg'])
    909     max_name_len = np.max(list(map(lambda x: len(x.name), DISTRIBUTIONS)))
    910 

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy)
    346                                  dtype=dtype, copy=copy)
    347         elif isinstance(data, dict):
--> 348             mgr = self._init_dict(data, index, columns, dtype=dtype)
    349         elif isinstance(data, ma.MaskedArray):
    350             import numpy.ma.mrecords as mrecords

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _init_dict(self, data, index, columns, dtype)
    449                     nan_dtype = dtype
    450                 v = construct_1d_arraylike_from_scalar(np.nan, len(index),
--> 451                                                        nan_dtype)
    452                 arrays.loc[missing] = [v] * missing.sum()
    453 

~\Anaconda3\lib\site-packages\pandas\core\dtypes\cast.py in construct_1d_arraylike_from_scalar(value, length, dtype)
   1194     else:
   1195         if not isinstance(dtype, (np.dtype, type(np.dtype))):
-> 1196             dtype = dtype.dtype
   1197 
   1198         # coerce if we have nan for an integer dtype

AttributeError: type object 'object' has no attribute 'dtype'

(I'm using Jupyter.) (我正在使用 Jupyter。)

How can I fix this problem?我该如何解决这个问题?

The solution to the above error, as can be seen in the comments of the question, was to upgrade pandas .从问题的评论中可以看出,上述错误的解决方案是升级pandas This issue appears in versions 1.0.4 and lower.此问题出现在版本 1.0.4 及更低版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: &#39;int&#39; 对象没有属性 &#39;dtype&#39; - AttributeError: 'int' object has no attribute 'dtype' AttributeError:“ TensorSliceDataset”对象没有属性“ dtype” - AttributeError: 'TensorSliceDataset' object has no attribute 'dtype' AttributeError:“ NoneType”对象没有属性“ dtype” - AttributeError: 'NoneType' object has no attribute 'dtype' AttributeError: 'df' object 没有属性 'dtype' - AttributeError: 'df' object has no attribute 'dtype' AttributeError:“列表”对象没有属性“ dtype” - AttributeError: 'list' object has no attribute 'dtype' AttributeError:&#39;CommandQueue&#39;对象没有属性&#39;dtype&#39; - AttributeError: 'CommandQueue' object has no attribute 'dtype' AttributeError: 'float' object 没有属性 'dtype' - AttributeError: 'float' object has no attribute 'dtype' AttributeError: type object &#39;object&#39; has no attribute &#39;dtype&#39; ,升级 pandas 没有解决 - AttributeError: type object 'object' has no attribute 'dtype' , upgrading pandas didn't solve it AttributeError类型的对象没有属性 - AttributeError type object has no attribute 估算器API:AttributeError:&#39;NoneType&#39;对象没有属性&#39;dtype&#39; - Estimator API: AttributeError: 'NoneType' object has no attribute 'dtype'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM