use*_*113 1 python csv statistics numpy scikit-learn
我正在尝试对CSV文件中的数据执行PCA分析,但是当我尝试扩展数据时,我不断收到一个奇怪的警告.
def prepare_data(filename):
df=pd.read_csv(filename,index_col=0)
df.dropna(axis=0,how='any',inplace=True)
return df
def perform_PCA(df):
threshold = 0.3
component = 1 #Second of two right now
pca = decomposition.PCA(n_components=2)
print df.head()
scaled_data = preprocessing.scale(df)
#pca.fit(scaled_data)
#transformed = pca.transform(scaled_data)
#pca_components_df = pd.DataFrame(data = pca.components_,columns = df.columns.values)
Run Code Online (Sandbox Code Playgroud)
这是我不断得到的警告.
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\utils\validation.py:498: UserWarning: The scale function assumes floating point values as input, got int64
"got %s" % (estimator, X.dtype))
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:145: DeprecationWarning: Implicitly casting between incompatible kinds. In a future numpy release, this will raise an error. Use casting="unsafe" if this is intentional.
Xr -= mean_
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:153: UserWarning: Numerical issues were encountered when centering the data and might not be solved. Dataset may contain too large values. You may need to prescale your features.
warnings.warn("Numerical issues were encountered "
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:158: DeprecationWarning: Implicitly casting between incompatible kinds. In a future numpy release, this will raise an error. Use casting="unsafe" if this is intentional.
Xr -= mean_1
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:160: DeprecationWarning: Implicitly casting between incompatible kinds. In a future numpy release, this will raise an error. Use casting="unsafe" if this is intentional.
Xr /= std_
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:169: UserWarning: Numerical issues were encountered when scaling the data and might not be solved. The standard deviation of the data is probably very close to 0.
warnings.warn("Numerical issues were encountered "
C:\Users\mbellissimo\AppData\Local\Continuum\Anaconda\lib\site-packages\sklearn\preprocessing\data.py:174: DeprecationWarning: Implicitly casting between incompatible kinds. In a future numpy release, this will raise an error. Use casting="unsafe" if this is intentional.
Xr -= mean_2
Run Code Online (Sandbox Code Playgroud)
CSV文件中的所有值都是数字.这是头部的样子
TOOLS/TEST EQUIPMENT WIN PRODUCTIVITY/UTILITY \
HouseholdID
144748819 0 0
144764123 0 0
144765100 0 0
144765495 2 0
144765756 0 2
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么我会收到此警告以及如何解决此问题?
我想到了.我不得不将我的Dataframe转换为numpy Matrix,然后将类型定义为float.
numpyMatrix = df.as_matrix().astype(float)
scaled_data = preprocessing.scale(numpyMatrix)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5074 次 |
| 最近记录: |