随机森林数据降维代码python
时间: 2023-09-11 09:04:02 浏览: 138
随机森林的python代码
Sure, I can help you with that! Here is a sample code for reducing the dimensions of data using Random Forest in Python:
```python
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectFromModel
# Load iris dataset
iris = load_iris()
# Create a Random Forest classifier
clf = RandomForestClassifier(n_estimators=100, random_state=0)
# Select features using threshold
sfm = SelectFromModel(clf, threshold=0.3)
sfm.fit(iris.data, iris.target)
print("Selected features:", iris.feature_names[sfm.get_support()])
```
This code selects the important features from the iris dataset using Random Forest and prints which features were selected. You can modify this code to suit your own needs.
阅读全文