Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Scikit学习:调整列车尺寸还是测试尺寸?_Python_Python 3.x_Machine Learning_Scikit Learn_Training Data - Fatal编程技术网

Python Scikit学习:调整列车尺寸还是测试尺寸?

Python Scikit学习:调整列车尺寸还是测试尺寸?,python,python-3.x,machine-learning,scikit-learn,training-data,Python,Python 3.x,Machine Learning,Scikit Learn,Training Data,这是一个关于sklearn最佳实践的问题 在使用sklearn库中提供的iris数据集进行支持向量机实验时。在使用train_test_split时,我想知道应该调整哪个参数以避免过度拟合。我被教导调整测试大小(大约为~0.3),但有一个训练大小参数。调整列车尺寸以避免过度安装是否有意义,或者我在这里误解了什么 无论调整哪个参数,我都会得到类似的结果,但我不知道是否总是这样 谢谢你的帮助。谢谢 以下是我目前使用的代码: import numpy as np import pandas as pd

这是一个关于sklearn最佳实践的问题

在使用sklearn库中提供的iris数据集进行支持向量机实验时。在使用train_test_split时,我想知道应该调整哪个参数以避免过度拟合。我被教导调整测试大小(大约为~0.3),但有一个训练大小参数。调整列车尺寸以避免过度安装是否有意义,或者我在这里误解了什么

无论调整哪个参数,我都会得到类似的结果,但我不知道是否总是这样

谢谢你的帮助。谢谢

以下是我目前使用的代码:

import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns

from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split as tts
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix, classification_report

iris = load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)

scaler = StandardScaler()
scaler.fit(df)
scaled_df = scaler.transform(df)
df = pd.DataFrame(data=scaled_df, columns=iris.feature_names)

x = df
y = iris.target

#test_size is used here, but is swapped with train_size to experiment
x_train, x_test, y_train, y_test = tts(x, y, test_size=0.33)

c_param = np.arange(1, 100, 10)
gamma_param = np.arange(0.0001, 1, 0.001)
params = {'C':c_param, 'gamma':gamma_param}

grid = GridSearchCV(estimator=SVC(), param_grid=params, verbose=0)
grid_fit = grid.fit(x_train, y_train)
grid_pred = grid.predict(x_test)
print(grid.best_params_)
print('\n')
print("Number of training records: ",  len(x_train))
print("Number of test records: ", len(x_test))
print('\n')
print(classification_report(y_true=y_test, y_pred=grid_pred))
print('\n')
print(confusion_matrix(y_true=y_test, y_pred=grid_pred))

这个决定实际上不是关于是否过度拟合(尽管更多的列车数据有帮助),而是关于识别/评估可能的过度拟合(权衡)。更有趣的是SVM参数。我还认为,
train\u test\u split
通常应该在以下假设下工作:
train\u size+test\u size==1.0
。是否可以在所有估算器中推广,拥有比测试集更大的训练集更可取?谢谢