我一直在努力优化Scikit-Learn中的SVR模型,但一直无法理解如何利用GridSearchCV.
考虑文档中提供的示例代码的略微修改的情况:
from sklearn import svm, grid_search, datasets
iris = datasets.load_iris()
parameters = {'kernel': ('linear', 'rbf'), 'C':[1.5, 10]}
svr = svm.SVC()
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(iris.data, iris.target)
clf.get_params()
Run Code Online (Sandbox Code Playgroud)
由于我指定最佳C值的搜索仅包含1.5和10,我希望模型返回使用这两个值中的一个.但是,当我查看输出时,情况似乎并非如此:
{'cv': None,
'estimator': SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
kernel='rbf', max_iter=-1, probability=False, random_state=None,
shrinking=True, tol=0.001, verbose=False),
'estimator__C': 1.0,
'estimator__cache_size': 200,
'estimator__class_weight': None,
'estimator__coef0': 0.0,
'estimator__degree': 3,
'estimator__gamma': 0.0,
'estimator__kernel': 'rbf',
'estimator__max_iter': -1,
'estimator__probability': False,
'estimator__random_state': None,
'estimator__shrinking': True,
'estimator__tol': 0.001,
'estimator__verbose': False,
'fit_params': {},
'iid': True,
'loss_func': None,
'n_jobs': …Run Code Online (Sandbox Code Playgroud) 的背景
我有一个问题,其中有许多解决方案可能,但我相信有一个尚未发现的优雅解决方案利用purrr.
示例代码
我有一个如下的大数据框,我在其中包含了一个例子:
library(tibble)
library(ggmap)
library(purrr)
library(dplyr)
# Define Example Data
df <- frame_data(
~Street, ~City, ~State, ~Zip, ~lon, ~lat,
"226 W 46th St", "New York", "New York", 10036, -73.9867, 40.75902,
"5th Ave", "New York", "New York", 10022, NA, NA,
"75 Broadway", "New York", "New York", 10006, -74.01205, 40.70814,
"350 5th Ave", "New York", "New York", 10118, -73.98566, 40.74871,
"20 Sagamore Hill Rd", "Oyster Bay", "New York", 11771, NA, NA,
"45 Rockefeller Plaza", "New York", "New York", 10111, -73.97771, …Run Code Online (Sandbox Code Playgroud) RStudio网站有一个非常有趣的可视化,如下所示:
https://gallery.shinyapps.io/TSupplyDemand/
不幸的是,我似乎无法确定源代码,包,甚至更简单地说明这个可视化的名称.
如果有人能够将我的研究指向正确的方向,我将不胜感激.我怀疑知道可视化的名称将帮助我很快解决剩下的问题.
我在一个简单的数据转换中被困了一段时间,我希望蜂巢的头脑可以提供帮助.
假设我有一个用于机器学习的Python Pandas数据框,如下所示:
>> trainingDF.ix[0:3,'temp']
Index temp
2011-01-01 00:00:00 9.84
2011-01-01 01:00:00 9.02
2011-01-01 02:00:00 9.02
Run Code Online (Sandbox Code Playgroud)
我们看到索引是一个pandas数据时间序列,而奇异数据列是温度.
我想在此数据框中添加12个特征列,每个特征列指示样本(例如行)是否为给定月份.换句话说,它应该如下所示:
Index temp isJan isFeb isMar isApr isMay etc.
2011-01-01 00:00:00 9.84 1 0 0 0 0 etc.
2011-01-01 01:00:00 9.02 1 0 0 0 0 etc.
2011-01-01 02:00:00 9.02 1 0 0 0 0 etc.
Run Code Online (Sandbox Code Playgroud)
不幸的是,尽管有许多不同的尝试,我似乎无法确定一个优雅的方法来实现这一目标.
任何指针都将非常感激.