34.62365962451697,78.0246928153624,0 30.28671076822607,43.89499752400101,0 35.84740876993872,72.90219802708364,0 60.18259938620976,86.30855209546826,1 79.0327360507101,75.3443764369103,1 45.08327747668339,56.3163717815305,0 61.10666453684766,96.51142588489624,1 75.02474556738889,46.55401354116538,1 76.09878670226257,87.42056971926803,1 84.43281996120035,43.53339331072109,1 95.86155507093572,38.22527805795094,0 75.01365838958247,30.60326323428011,0用随机森林进行分类,python代码实现
时间: 2023-07-27 18:14:12 浏览: 97
以下是使用sklearn库中的随机森林模型对给出的数据进行分类的Python代码:
```python
from sklearn.ensemble import RandomForestClassifier
import numpy as np
# 输入数据
X = np.array([[34.62365962451697,78.0246928153624],
[30.28671076822607,43.89499752400101],
[35.84740876993872,72.90219802708364],
[60.18259938620976,86.30855209546826],
[79.0327360507101,75.3443764369103],
[45.08327747668339,56.3163717815305],
[61.10666453684766,96.51142588489624],
[75.02474556738889,46.55401354116538],
[76.09878670226257,87.42056971926803],
[84.43281996120035,43.53339331072109],
[95.86155507093572,38.22527805795094],
[75.01365838958247,30.60326323428011]])
# 标签
y = np.array([0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0])
# 创建随机森林模型
rfc = RandomForestClassifier()
# 拟合模型
rfc.fit(X, y)
# 预测新数据
new_data = np.array([[50, 70], [70, 50]])
print(rfc.predict(new_data))
```
代码中使用`RandomForestClassifier`创建了一个随机森林分类器,并使用`fit`方法拟合了模型。然后使用`predict`方法对新数据进行预测,输出预测结果。在这个例子中,新数据包含两个样本:[50, 70]和[70, 50]。分类器会对每个样本进行分类,输出一个0或1的预测结果。
阅读全文