在尝试使用NodeJS/Express中的Passport对Facebook用户进行身份验证时,已经有两天和一百万次尝试启用CORS.
我在Chrome上遇到的错误是:
XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…%3A8080%2Fauth%2Ffacebook%2Fcallback&scope=email&client_id=598171076960591.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
我使用的路线很简单:
// =====================================
// FACEBOOK ROUTES =====================
// =====================================
// route for facebook authentication and login
app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'email' }));
// handle the callback after facebook has authenticated the user
app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
successRedirect : '/home',
failureRedirect : '/login'
}));
Run Code Online (Sandbox Code Playgroud)
这是在我的angularJS文件上调用路由的方式(我也尝试过设置withCredentials:true):
$http.get('/auth/facebook')
.success(function(response) {
}).error(function(response){
});
Run Code Online (Sandbox Code Playgroud)
我在StackOverflow和其他论坛上尝试了十几个解决方案.
我尝试在routes.js文件的路由之前添加它:
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*'); …Run Code Online (Sandbox Code Playgroud)我在Passport/ExpressJS中使用会话时遇到问题.
当我登录时req.session,我可以看到护照是{}:
{ cookie:
{ path: '/',
_expires: Mon Sep 29 2014 19:37:16 GMT-0300 (BRT),
originalMaxAge: 3594522,
httpOnly: true,
secure: true },
passport: {} }
Run Code Online (Sandbox Code Playgroud)
此外,我正在使用Facebook进行身份验证,并且passport.deserializeUser没有被调用.这是我的代码:
passport.use(new FacebookStrategy({
// pull in our app id and secret from our auth.js file
clientID : configAuth.facebookAuth.clientID,
clientSecret : configAuth.facebookAuth.clientSecret,
callbackURL : configAuth.facebookAuth.callbackURL
},
// facebook will send back the token and profile
function(token, refreshToken, profile, done) {
// asynchronous
process.nextTick(function() {
console.log("profile " + profile.id);
console.log("profile.name "+profile.name.givenName) …Run Code Online (Sandbox Code Playgroud) 我正在使用Spark ML运行一些ML实验,并且在一个20MB的小型数据集(扑克数据集)和一个带参数网格的随机森林中,需要1小时30分钟才能完成。与此类似,使用scikit-learn所需的时间要少得多。
在环境方面,我正在测试2个从属服务器,每个从属服务器15GB内存,24个内核。我认为应该花这么长时间,并且我想知道问题是否出在我的代码中,因为我对Spark非常陌生。
这里是:
df = pd.read_csv(http://archive.ics.uci.edu/ml/machine-learning-databases/poker/poker-hand-testing.data)
dataframe = sqlContext.createDataFrame(df)
train, test = dataframe.randomSplit([0.7, 0.3])
columnTypes = dataframe.dtypes
for ct in columnTypes:
if ct[1] == 'string' and ct[0] != 'label':
categoricalCols += [ct[0]]
elif ct[0] != 'label':
numericCols += [ct[0]]
stages = []
for categoricalCol in categoricalCols:
stringIndexer = StringIndexer(inputCol=categoricalCol, outputCol=categoricalCol+"Index")
stages += [stringIndexer]
assemblerInputs = map(lambda c: c + "Index", categoricalCols) + numericCols
assembler = VectorAssembler(inputCols=assemblerInputs, outputCol="features")
stages += [assembler]
labelIndexer = StringIndexer(inputCol='label', outputCol='indexedLabel', handleInvalid='skip')
stages += …Run Code Online (Sandbox Code Playgroud) 我无法读取和区分输入中的空行.
这是示例输入:
number
string
string
string
...
number
string
string
...
Run Code Online (Sandbox Code Playgroud)
每个数字代表输入的开始,字符串序列表示输入结束后的空白行.字符串可以是短语,而不仅仅是一个单词.
我的代码执行以下操作:
int n;
while(cin >> n) { //number
string s, blank;
getline(cin, blank); //reads the blank line
while (getline(cin, s) && s.length() > 0) { //I've tried !s.empty()
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试直接cin >>空白,但它没有用.
有人可以帮我解决这个问题吗?
谢谢!
这是我的test.py文件:
import unittest, views, json
class FlaskTestCase(unittest.TestCase):
def setUp(self):
self.app = views.app.test_client()
def test_index(self):
rv = self.app.get('/')
assert 'Hamptons Bank' in rv.data
def test_credit(self):
response = self.app.post('/credit', data=json.dumps({
'amount': '20',
'account': '1'
}), content_type='application/json')
print response.data
assert 'Deposit of 20 to account 1' in response.data
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
test_index方法工作正常,但self.app.post保持返回(在print response.data中):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either …Run Code Online (Sandbox Code Playgroud) 因此,基本上我想要并行运行ML Pipelines。我一直在使用scikit-learn,因此决定使用DaskGridSearchCV。
我有一个gridSearchCV = DaskGridSearchCV(pipeline, grid, scoring=evaluator)对象列表,并按顺序运行它们:
for gridSearchCV in list:
gridSearchCV.fit(train_data, train_target)
predicted = gridSearchCV.predict(test_data)
Run Code Online (Sandbox Code Playgroud)
如果我有N个不同的GridSearch对象,我想尽可能多地利用所有可用资源。如果有资源可以同时并行运行2、3、4,...或N,我想这样做。
因此,我开始根据dask的文档尝试一些操作。首先,我尝试了一下dask.threaded,dask.multiprocessing但结果却变慢了,而且我不断:
/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.py:540: UserWarning: Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1
这是代码片段:
def run_pipeline(self, gs, data):
train_data, test_data, train_target, expected = train_test_split(data, target, test_size=0.25, random_state=33)
model = gs.fit(train_data, train_target)
predicted = gs.predict(test_data)
values = [delayed(run_pipeline)(gs, df) for gs in gs_list]
compute(*values, get=dask.threaded.get)
Run Code Online (Sandbox Code Playgroud)
也许我走错路了,您对我有什么建议吗?
我正在一个非常简单的数据集上运行一些测试,该数据集基本上由数值数据组成。可以在这里找到。
我正在使用 pandas、numpy 和 scikit-learn 很好,但是当转移到 Spark 时,我无法以正确的格式设置数据以将其输入到决策树中。
我正在做这行不通的事情:
df = pd.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/poker/poker-hand-training-true.data')
raw_data = sc.parallelize(df)
train_dataset = raw_data.map(lambda line: line.split(","))\
.map(lambda line:LabeledPoint(line[10], np.array([float(x) for x in line[0:10]])))
Run Code Online (Sandbox Code Playgroud)
IndexError: list index out of range尝试line在 map 函数内部进行访问时,我一直在获取。
当我实际下载文件并更改代码时,我才设法让它工作,如下所示:
raw_data = sc.textFile('.../datasets/poker-hand-training.data')
train_dataset = raw_data.map(lambda line: line.split(","))\
.map(lambda line:LabeledPoint(line[10], np.array([float(x) for x in line[0:10]])))
Run Code Online (Sandbox Code Playgroud)
如果我不想下载数据集,是否可以使用read_csv?
所以我现在已经尝试了几天在Spark中的map函数中运行ML算法.我发布了一个更具体的问题,但引用Spark的ML算法给出了以下错误:
AttributeError: Cannot load _jvm from SparkContext. Is SparkContext initialized?
Run Code Online (Sandbox Code Playgroud)
显然我无法SparkContext在apply_classifier函数内部引用.我的代码与我之前提出的问题中的建议类似,但仍未找到我正在寻找的解决方案:
def apply_classifier(clf):
dt = DecisionTreeClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", maxDepth=3)
if clf == 0:
clf = DecisionTreeClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", maxDepth=3)
elif clf == 1:
clf = RandomForestClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", numTrees=5)
classifiers = [0, 1]
sc.parallelize(classifiers).map(lambda x: apply_classifier(x)).collect()
Run Code Online (Sandbox Code Playgroud)
我尝试使用flatMap而不是,map但我得到NoneType object is not iterable.
我还希望将广播的数据集(这是一个DataFrame)作为函数内的参数传递apply_classifier.最后,是否有可能做我想做的事情?有哪些替代方案?
machine-learning apache-spark pyspark apache-spark-ml apache-spark-mllib
我正在使用 Python 的模拟库和 unittest。我正在为一个类编写单元测试,该类在其方法之一中使用外部库的函数。根据情况,此函数返回不同的值。
假设我想测试 A 类:
from external_library import function_foo
class A(object):
...
Run Code Online (Sandbox Code Playgroud)
在我的测试类中,为了使用函数从外部库返回的值,我创建了一个补丁,定义了补丁后才导入类A。但是,我需要在我所有的测试方法中使用这个函数,并且在每个方法中它返回不同的值。
我的测试类如下:
class TestA(TestCase):
@patch('external_library.function_foo', side_effect=[1, 2, 3])
def test_1(self, *patches):
from module import class A
obj = A()
...
@patch('external_library.function_foo', side_effect=[1, 1, 2, 2, 3, 3])
def test_2(self, *patches):
from module import class A
obj = A()
...
...
Run Code Online (Sandbox Code Playgroud)
我有 10 个测试,当我同时运行所有测试时,只有 1 个(第一个)通过,其余的,我得到StopIteration错误。但是,如果我单独运行它们中的每一个,它们都会通过。
我尝试with patch('external_library.function_foo', side_effect=[...])在每种方法中使用,但结果是一样的。我还尝试在setUp方法中只创建一次补丁,启动它,在每个方法中重新分配 side_effect,然后在 中停止tearDown,但没有奏效。
关于在这种情况下可能起作用的任何想法?
谢谢!
我一直在使用bootstrap,我在尝试动态添加下拉菜单时遇到了一个问题.
这是我的JavaScript:
$(document).ready(function() {
$("#clickHere").click(function(){
$("#appendHere").html("<div class=\"dropdown\" style=\"display:inline;\"><a id=\"drop1\" href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\"><b class=\"caret\"></b></a><ul class=\"dropdown-menu pull-left\"><li><button>Analyse Now</button></li><li class=\"divider\"></li><li><button>Analyse Later</button></li></ul></div>");
});
$('#drop1').on('click', function(e){
e.stopPropagation();
$(".dropdown-toggle").dropdown('toggle');
});
});
Run Code Online (Sandbox Code Playgroud)
这是HTML:
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display: block; position: static; margin-bottom: 5px; *width: 180px;">
<li><a tabindex="-1" href="#">Action</a></li>
<li><a tabindex="-1" href="#">Another action</a></li>
<li><a tabindex="-1" href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-submenu pull-left"> <a tabindex="-1" href="#">More options</a>
<ul class="dropdown-menu" id="mainMenu">
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second level link</a></li>
<li><a tabindex="-1" href="#">Second …Run Code Online (Sandbox Code Playgroud) python ×4
apache-spark ×3
pyspark ×3
node.js ×2
passport.js ×2
angularjs ×1
c++ ×1
cors ×1
dask ×1
dask-delayed ×1
express ×1
flask ×1
input ×1
javascript ×1
jquery ×1
mocking ×1
pandas ×1
scikit-learn ×1
session ×1
testing ×1
unit-testing ×1