def feature_Kmeans(data,label): mms = MinMaxScaler() feats = [f for f in data.columns if f not in ['loan_id', 'user_id', 'isDefault']] data = data[feats] mmsModel = mms.fit_transform(data.loc[data['class'] == label]) clf = KMeans(5, random_state=2021) pre = clf.fit(mmsModel) test = pre.labels_ final_data = pd.Series(test, index=data.loc[data['class'] == label].index) if label == 1: /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:74: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:75: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:76: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
时间: 2024-04-02 19:37:29 浏览: 173
自适应k均值matlab代码-OpenCv-Adaptive_Kmeans_Clustering:用C++编写的自适应Kmeans聚类
这段代码中出现了 `SettingWithCopyWarning` 警告,警告的原因是在对 DataFrame 进行切片操作之后,对切片对象进行了赋值操作,这可能会导致原 DataFrame 的值也被改变,进而导致错误的结果。建议使用 `.loc` 或 `.iloc` 进行切片并进行赋值操作,以避免这个警告的出现。你可以使用如下代码来避免这个警告:
```python
if label == 1:
final_data = pd.DataFrame({'class': final_data})
data.loc[data['class'] == label, 'class'] = final_data['class']
```
阅读全文