ValueError: X has 60 features, but MinMaxScaler is expecting 1 features as input.
时间: 2024-05-15 11:19:54 浏览: 325
Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2(char 1)
5星 · 资源好评率100%
This error occurs when you try to fit a MinMaxScaler object on a dataset with multiple features, but you pass it only one feature or column.
To solve this error, you need to make sure that you pass the entire dataset with all the features to the scaler object.
Here's an example of how to use MinMaxScaler correctly:
```python
from sklearn.preprocessing import MinMaxScaler
import pandas as pd
# create a sample dataset with 3 features
data = {'feature1': [10, 20, 30, 40], 'feature2': [100, 200, 300, 400], 'feature3': [1, 2, 3, 4]}
df = pd.DataFrame(data)
# create a MinMaxScaler object
scaler = MinMaxScaler()
# fit and transform the entire dataset
scaled_data = scaler.fit_transform(df)
# check the shape of the scaled data
print(scaled_data.shape) # output: (4, 3)
```
In this example, we created a sample dataset with 3 features and passed the entire dataset to the MinMaxScaler object. The `fit_transform` method scales all the features in the dataset, and the shape of the scaled data is `(4, 3)`, which means that all the features are scaled properly.
阅读全文