Created
October 4, 2016 14:10
-
-
Save remore/54c41811cb2d73f83b101b118448f605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
skl = VirtualModule.new(:lang=>:python, :pkgs=>["sklearn"=>["datasets", "svm", "grid_search", "cross_validation"]]) | |
include skl | |
iris = datasets.load_iris(:_) | |
clf = grid_search.GridSearchCV(svm.LinearSVC(:_), {'C':[1, 3, 5],'loss':['hinge', 'squared_hinge']}, verbose:0) | |
clf.fit(iris.data, iris.target) | |
p "Best Parameters: #{best_params = clf.best_params_}" #"Best Parameters: {\"loss\"=>\"squared_hinge\", \"C\"=>1}" | |
score = cross_validation.cross_val_score(svm.LinearSVC(loss:'squared_hinge', C:1), iris.data, iris.target, cv:5) | |
p "Scores: #{[:mean,:min,:max,:std].map{|e| e.to_s + '=' + score.send(e, :_).to_s }.join(',')}" # "Scores: mean=0.9666666666666668,min=0.9,max=1.0,std=0.04216370213557838" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment