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
import json | |
#make a test data. | |
testHash={"A":10,"B":20.0,"C":[30.0,40]} | |
#dump the variable as a file | |
with open("E:/test.json","w") as f: | |
json.dump(testHash,f) | |
#load from a json file |
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
>>> import json | |
>>> testHash={"A":10,"B":20,"C":30.0} | |
with open("E:/test.json","w") as f: | |
json.dump(testHash,f) | |
>>> testHash | |
{'A': 10, 'C': 30.0, 'B': 20} |
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
#delete the next # if rjson package is not installed in the system | |
#install.packages("rjson") | |
library("rjson") | |
#load from a json file | |
data=fromJSON(file="E:/test.json") | |
#check the data | |
print(data) |
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
# -*- coding: utf-8 -*- | |
# This code is distributed under the 3-Clause BSD license (New BSD license). | |
# 基本的に作者の名前を書いていただければ、商用利用も可能です。なお、保証はしません。 | |
# 参考URL: http://osdn.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license | |
from sklearn import linear_model | |
import Image | |
import numpy as np | |
from sklearn.cross_validation import ShuffleSplit | |
class MinibatchSGDRegressor(linear_model.SGDRegressor): |
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
# -*- coding: utf-8 -*- | |
# This code is distributed under the 3-Clause BSD license (New BSD license). | |
# 基本的に作者の名前を書いていただければ、商用利用も可能です。なお、保証はしません。 | |
# 参考URL: http://osdn.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license | |
from sklearn import linear_model | |
import Image | |
import numpy as np | |
from sklearn.cross_validation import ShuffleSplit | |
from sklearn.metrics import r2_score |
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
# -*- coding: utf-8 -*- | |
# This code is distributed under the 3-Clause BSD license (New BSD license). | |
# 日本の方へ | |
# 基本的に作者の名前を書いていただければ、商用利用も可能です。なお、保証はいたしかねます。 | |
# 参考URL: http://osdn.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license | |
# References: https://docs.python.org/3/library/gzip.html | |
# http://henrysmac.org/blog/2010/3/15/python-pickle-example-including-gzip-for-compression.html |
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
library(randomForest) | |
#「フィッシャーのあやめ」データセットを読み出す | |
data(iris) | |
#データセットを特徴量とラベルに分割 | |
features<-iris[1:4] | |
labels<-iris[5] | |
#ラベルを因子化 |
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
setosa versicolor virginica MeanDecreaseAccuracy MeanDecreaseGini | |
Sepal.Length 7.277437 7.0994514 8.087167 10.842432 9.553025 | |
Sepal.Width 5.029336 -0.4402422 2.381594 3.438372 2.528796 | |
Petal.Length 22.909121 32.9889332 30.209000 35.201262 43.785432 | |
Petal.Width 21.741775 30.5797963 31.309059 32.724397 43.400080 |
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
#see also: http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html | |
import numpy as np | |
from sklearn import mixture,preprocessing | |
class BagOfFeaturesGMM: | |
"""This is a class of Bag-of-Features by GMM """ | |
codebookSize=0 | |
classifier=None | |
def __init__(self, codebookSize): |
OlderNewer