train_test_split() got an unexpected keyword argument 'n_samples'
时间: 2023-10-13 22:06:47 浏览: 66
The error message suggests that the `train_test_split()` function is not expecting a keyword argument `n_samples`. This could be due to a version mismatch or a typo in the argument name.
In the current version of scikit-learn, `train_test_split()` does not have a parameter called `n_samples`. Instead, it takes the following parameters:
```
train_test_split(*arrays, **options)
```
You can specify the size of the test set using the `test_size` parameter or the number of samples in the test set using the `train_size` parameter.
If you want to split your data into a specific number of samples, you can use the `random_state` parameter to ensure that the split is reproducible and then use the `shape` attribute of the resulting arrays to get the number of samples.
For example:
```
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
n_train_samples = X_train.shape[0]
n_test_samples = X_test.shape[0]
print("Number of training samples:", n_train_samples)
print("Number of test samples:", n_test_samples)
```
Hope this helps!