尝试使用sklearn和panads创建具有交叉验证的决策树.
我的问题是在下面的代码中,交叉验证分割数据,然后我将其用于训练和测试.我将尝试通过在不同的最大深度设置下重新创建n次来找到树的最佳深度.在使用交叉验证时,我应该使用k folds CV,如果是这样,我将如何在我的代码中使用它?
import numpy as np
import pandas as pd
from sklearn import tree
from sklearn import cross_validation
features = ["fLength", "fWidth", "fSize", "fConc", "fConc1", "fAsym", "fM3Long", "fM3Trans", "fAlpha", "fDist", "class"]
df = pd.read_csv('magic04.data',header=None,names=features)
df['class'] = df['class'].map({'g':0,'h':1})
x = df[features[:-1]]
y = df['class']
x_train,x_test,y_train,y_test = cross_validation.train_test_split(x,y,test_size=0.4,random_state=0)
depth = []
for i in range(3,20):
clf = tree.DecisionTreeClassifier(max_depth=i)
clf = clf.fit(x_train,y_train)
depth.append((i,clf.score(x_test,y_test)))
print depth
Run Code Online (Sandbox Code Playgroud)
这里是我正在使用的数据的链接,以防任何人. https://archive.ics.uci.edu/ml/datasets/MAGIC+Gamma+Telescope
尝试编写一个非常简单的chrome 扩展,作为测试,我想添加控制台日志以进行调试。但是,我不断收到此错误
运行时未检查runtime.lastError
webRequestInternal.addEventListener:您需要在清单文件中请求主机权限,以便收到来自 webRequest API 的请求的通知。
我已经尝试添加我能找到的所有权限,但没有任何运气。有人可以帮我吗!
{
"manifest_version": 2,
"name": "test",
"description": "testing app",
"version": "1.0",
"background": {
"scripts": ["small.js"],
"persistent": true
},
"permissions": ["webRequest", "webRequestBlocking", "tabs", "background", "storage"],
"optional_permissions": ["http://*/*", "https://*/*", "<all_urls>"]
}
Run Code Online (Sandbox Code Playgroud)
chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (details.method === "POST") {
alert('here');
console.log('logging here');
} else if (details.method === "GET") {
alert('there');
console.log('logging there');
}
}, {
urls: ["<all_urls>"]
}, ["blocking", "requestBody"]);
Run Code Online (Sandbox Code Playgroud) javascript ×1