poly_features_test = pd.DataFrame(poly_features_test, columns = poly_transformer.get_feature_names(['板温','现场温度','光照强度','风速','风向']))错误
时间: 2023-03-05 08:44:34 浏览: 99
The code you provided is incomplete, but based on what you've shared, the error might be related to the variable `poly_transformer`.
Here's an example of how to use `PolynomialFeatures` from scikit-learn to create polynomial features and then transform a test dataset with the same features:
```
import pandas as pd
from sklearn.preprocessing import PolynomialFeatures
# Create a toy test dataset with 3 numerical features
test_data = pd.DataFrame({
'feature1': [1, 2, 3],
'feature2': [4, 5, 6],
'feature3': [7, 8, 9]
})
# Instantiate PolynomialFeatures object with degree=2 (for creating 2nd degree polynomial features)
poly_transformer = PolynomialFeatures(degree=2)
# Fit and transform the training data to create polynomial features
poly_features_train = poly_transformer.fit_transform(train_data)
# Transform the test data with the same polynomial features
poly_features_test = poly_transformer.transform(test_data)
# Create column names for the new features
poly_feature_names = poly_transformer.get_feature_names(['feature1', 'feature2', 'feature3'])
# Convert the transformed test data to a pandas DataFrame with the new feature names
poly_features_test = pd.DataFrame(poly_features_test, columns=poly_feature_names)
```
Make sure that the column names passed to `get_feature_names()` match the names of the columns in your test data.