Posts

python - IndexError : index out of bounds -

i have implemented multinomialnb message. please me solve it. here code : kf = kfold(len(x), n_folds=2, shuffle=true, random_state=9999) model_train_index = [] model_test_index = [] model = 0 k, (index_train, index_test) in enumerate(kf): x_train, x_test, y_train, y_test = x.ix[index_train,:], x.ix[index_test,:],y[index_train], y[index_test] clf = multinomialnb(alpha=0.1).fit(x_train, y_train) score = clf.score(x_test, y_test) f1score = f1_score(y_test, clf.predict(x_test)) precision = precision_score(y_test, clf.predict(x_test)) recall = recall_score(y_test, clf.predict(x_test)) print('model %d has accuracy %f | f1score: %f | precision: %f | recall : %f'%(k,score, f1score, precision, recall)) model_train_index.append(index_train) model_test_index.append(index_test) model+=1 and result : indexerror traceback (most recent call last) <ipython-input-3-df0b24edb687>...

immutability - RxJS with immutable datastructures? -

i'm working through rxjskoans , i'm seeing recurring pattern of feeding in array of results, subscriber pushes new values onto: var rx = require('rx'), subject = rx.subject var result = []; var s1 = new subject(); s1.subscribe(result.push.bind(result)); s1.onnext('foo'); result; // ['foo'] this impure function; result array mutated subscribe. i've seen small-scale projects on github make stab @ using immutable.js, none actively maintained. im wondering if there's widely-adopted immutable implementation pattern, , if not, why? i wouldn't call pattern, since can pass through stream can pass in immutable data structure: const stream$ = rx.subject.create(); stream$ .map(data => data.set('a', data.get('a') + 1)) .subscribe(data => console.log(data)); stream$.next(immutable.map({ a:1 })); stream$.next(immutable.map({ a:2 })); <script src="https://npmcdn.com/@reactivex/...

javascript - AngularJS + ng file upload + Sails JS -

i need send information each file upload. documentation says can achieve data parameter cant access action in sails controller. frontend: upload.upload({ url: '/file/upload', arraykey: '', data: { file: $scope.files, otherinfo: {user: user, person: 12 }}})..... sails js: req.file('file').upload({ dirname: '../../websrc/uploads' }, function(err, files) { if (err) return res.servererror(err); return res.json({ message: files.length + ' file(s) uploaded successfully!', files: files }); }); if log files, see x objects this: uploadedfilemetadata[0] extra: undefined fd: "/xxxxxxxxxxxxxx/uploads/24fd1f66-36df-40ec-bed3-45e18df77469.jpg" field: "file" filename: "xxxxxxxxxxxxxxxxxxxxxx.jpg" size: 199247 status: "bufferingorwriting" stream: passthrough type: "image/jpeg" how can send information each 1 of files , access server? $scope.uploadf...

ruby on rails - RoR: curl "upload completely sent off" -

rails version: 2.2.4. ruby version: 5.0.0.1 curl version: 7.50.1 hello people, i new ruby on rails programmer , need programm university authentication function ruby on rails through json request , on end can use authentication-function directly on android app. after hours of work made can registrate , login ruby on rails. followed deprecated tutorial ( http://lucatironi.net/tutorial/2012/10/15/ruby_rails_android_app_authentication_devise_tutorial_part_one/ ) , see how authentication function through json request. update: think messed create sessions controller right. created this: controllers/api/v1/sessions_controller.rb data , put text in it: class api::v1::sessionscontroller < devise::sessionscontroller skip_before_filter :verify_authenticity_token, :if => proc.new { |c| c.request.format == 'application/json' } respond_to :json def create warden.authenticate!(:scope => resource_name, :recall => "#{controller_pa...

html - Radio button's appearing one over another -

i have custom radio buttons on application. issue radio buttons display fine individually. when try have 2 of them in 1 line... appear on each other instead of beside each other. can't change html , can mess css. appreciated. thinking due width of each label giving low width had same result. html: <label class="radio"> <input type="radio"> <span class="custom"><span>one</span></span> </label> css: * { box-sizing: border-box; } input[type="radio"] { display: none; cursor: pointer; } label { cursor: pointer; } .radio span.custom > span { margin-left: 22px; } .radio .custom { background-color: #fff; border: 1px solid #ccc; border-radius: 3px; display: inline-block; height: 20px; left: 0; position: absolute; top: 0; width: 20px; } .radio input:checked + .custom:after { background-color: #0574ac; border-radius: 100%; border: 3px solid #fff; conten...

string - shortest repeated substring [PYTHON] -

is there quick method find shortest repeated substring , how many times occurs? if there non need return actual string ( last case ). >>> repeated('ctctctctctctctctctctctct') ('ct', 12) >>> repeated('gatcgatcgatcgatc') ('gatc', 4) >>> repeated('gatcgatcgatcgatcg') ('gatcgatcgatcgatcg', 1) because people think it's 'homework' can show efforts: def repeated(sequentie): string = '' in sequentie: if not in string: string += items = sequentie.count(string) if items * len(string) == len(sequentie): return (string, items) else: return (sequentie, 1) your method unfortunately won't work, since assumes repeating substring have unique characters. may not case: abaabaabaabaabaaba you on right track, though. shortest way can think of try , check on , on if prefix indeed makes entire string: def f...

python - Threads not exiting and program won't exit -

using script below, cannot seem exit threads. script runs smoothly without issues never exits when done. can still see thread alive, have use htop kill them or exit command line. how can script exit , threads die? def async_dns(): s = adns.init() while true: dname = q.get() response = s.synchronous(dname,adns.rr.ns)[0] if response == 0: dot_net.append("y") print(dname + ", y") elif response == 300 or response == 30 or response == 60: dot_net.append("n") print(dname + ", n") elif q.empty() == true: q.task_done() q = queue.queue() threads = [] in range(20): t = threading.thread(target=async_dns) threads.append(t) t.start() name in names: q.put_nowait(name) remove , return item queue. if optional args block true , timeout none (the default), block if necessary until item available. if timeout positive num...