简单来说,交叉验证和网格搜索有什么区别?网格搜索如何工作?我应该首先进行交叉验证然后进行网格搜索吗?
当我使用以下代码与X大小(952,144)的数据矩阵和y大小(952)的输出向量时,mean_squared_error度量返回负值,这是意外的.你有什么主意吗?
from sklearn.svm import SVR
from sklearn import cross_validation as CV
reg = SVR(C=1., epsilon=0.1, kernel='rbf')
scores = CV.cross_val_score(reg, X, y, cv=10, scoring='mean_squared_error')
Run Code Online (Sandbox Code Playgroud)
scores然后所有的值都是负数.
从标题我想知道它们之间有什么区别
StratifiedKFold,参数shuffle = True
StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
Run Code Online (Sandbox Code Playgroud)
和
StratifiedShuffleSplit(n_splits=10, test_size=’default’, train_size=None, random_state=0)
Run Code Online (Sandbox Code Playgroud)
使用StratifiedShuffleSplit有什么好处
我正在运行GridSearch CV来优化scikit中分类器的参数.一旦完成,我想知道哪些参数被选为最佳参数.
每当我这样做,我得到一个AttributeError: 'RandomForestClassifier' object has no attribute 'best_estimator_',并且不知道为什么,因为它似乎是文档的合法属性.
from sklearn.grid_search import GridSearchCV
X = data[usable_columns]
y = data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
rfc = RandomForestClassifier(n_jobs=-1,max_features= 'sqrt' ,n_estimators=50, oob_score = True)
param_grid = {
'n_estimators': [200, 700],
'max_features': ['auto', 'sqrt', 'log2']
}
CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 5)
print '\n',CV_rfc.best_estimator_
Run Code Online (Sandbox Code Playgroud)
产量:
`AttributeError: 'GridSearchCV' object has no attribute 'best_estimator_'
Run Code Online (Sandbox Code Playgroud) 我有一个小语料库,我想用10倍交叉验证来计算朴素贝叶斯分类器的准确性,怎么做呢.
我想ParamGridBuilder在Spark 1.4.x中找到CrossValidator中最佳模型的参数,
在Spark文档中的Pipeline示例中,它们通过在管道中使用来添加不同的参数(numFeatures,regParam)ParamGridBuilder.然后通过以下代码行创建最佳模型:
val cvModel = crossval.fit(training.toDF)
Run Code Online (Sandbox Code Playgroud)
现在,我想知道从中产生最佳模型的参数(numFeatures,regParam)是什么ParamGridBuilder.
我已经使用了以下命令但没有成功:
cvModel.bestModel.extractParamMap().toString()
cvModel.params.toList.mkString("(", ",", ")")
cvModel.estimatorParamMaps.toString()
cvModel.explainParams()
cvModel.getEstimatorParamMaps.mkString("(", ",", ")")
cvModel.toString()
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
提前致谢,
pipeline scala cross-validation apache-spark apache-spark-mllib
我有一个数据集,以前分为3组:训练,验证和测试.必须使用这些集合以便比较不同算法的性能.
我现在想使用验证集优化我的SVM的参数.但是,我无法找到如何明确输入验证集sklearn.grid_search.GridSearchCV().下面是我之前用于在训练集上进行K折叠交叉验证的一些代码.但是,对于这个问题,我需要使用给定的验证集.我怎样才能做到这一点?
from sklearn import svm, cross_validation
from sklearn.grid_search import GridSearchCV
# (some code left out to simplify things)
skf = cross_validation.StratifiedKFold(y_train, n_folds=5, shuffle = True)
clf = GridSearchCV(svm.SVC(tol=0.005, cache_size=6000,
class_weight=penalty_weights),
param_grid=tuned_parameters,
n_jobs=2,
pre_dispatch="n_jobs",
cv=skf,
scoring=scorer)
clf.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud) 我试图将我的数据集拆分为训练和测试数据集,但我收到此错误:
X_train,X_test,Y_train,Y_test = sklearn.cross_validation.train_test_split(X,df1['ENTRIESn_hourly'])
Run Code Online (Sandbox Code Playgroud)
AttributeError Traceback (most recent call last)
<ipython-input-53-5445dab94861> in <module>()
----> 1 X_train,X_test,Y_train,Y_test = sklearn.cross_validation.train_test_split(X,df1['ENTRIESn_hourly'])
AttributeError: module 'sklearn' has no attribute 'cross_validation'
Run Code Online (Sandbox Code Playgroud)
我怎么处理这个?
我正在使用sklearn进行多分类任务.我需要将alldata拆分为train_set和test_set.我想从每个班级中随机抽取相同的样本编号.实际上,我有趣的是这个功能
X_train, X_test, y_train, y_test = cross_validation.train_test_split(Data, Target, test_size=0.3, random_state=0)
Run Code Online (Sandbox Code Playgroud)
但它给出了不平衡的数据集!任何建议.
cross-validation ×10
scikit-learn ×8
python ×7
apache-spark ×1
definition ×1
difference ×1
grid-search ×1
naivebayes ×1
nltk ×1
pipeline ×1
regression ×1
scala ×1
svm ×1
time-series ×1
validation ×1