Exemple #1
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["mFile"] = self.mName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.iFileCheck(params["mFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["oFile"], "出力ファイル名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        iKey = self.iKey_w.getValue()
        mKey = self.mKey_w.getValue()
        field = self.field_w.getValue()
        iOuter = self.iOuter_w.value
        mOuter = self.mOuter_w.value

        if not wlib.blankCheck(field, "結合する項目", self.parent.msg_w):
            return False

        par = []
        par.append("k='%s'" % (iKey))
        if mKey != "":
            par.append("K='%s'" % (mKey))
        par.append("m='%s'" % (params["mFile"]))
        par.append("f='%s'" % (field))
        if iOuter:
            par.append("n=True")
        if mOuter:
            par.append("N=True")
        par.append("i='%s'" % (params["iFile"]))
        par.append("o='%s/%s'" % (params["oPath"], params["oFile"]))

        header = """
#################################
# mjoin_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
""" % (self.version, self.date)

        lib = """
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")
"""
        script = """
f=None
f<<=nm.mjoin(%s)
f.run(msg='on')
print("#### END")
""" % (",".join(par))

        script_w.value = header + lib + script
        return True
Exemple #2
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.fName_w.value
        params["oPath"] = self.oPath_w.value + "/" + self.oDir_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(self.oDir_w.value, "出力dir名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        deepOutput = self.parent.deepOutput_w.value

        params["id_"] = self.id_w.getValue()
        params["y"] = self.y_w.getValue()
        params["nums"] = list(self.num_w.getValue())
        params["cats"] = list(self.cat_w.getValue())
        params["minSamplesLeaf"] = self.minSamplesLeaf_w.value

        if params["y"] in params["nums"] or params["y"] in params["cats"]:
            self.parent.msg_w.value = "##ERROR: 説明変数に目的変数が含まれています:%s" % params[
                "y"]
            return False

        script1 = wlib.readSource("nysol.mining.ctree", "ctree", deepOutput)
        script2 = wlib.readSource("nysol.mining.csv2df")
        script3 = """
print("#### START")
# 出力ディレクトリを作成する
os.makedirs("{oPath}",exist_ok=True)

# pandasデータを作成する
df,ds=csv2df("{iFile}", "{id_}", {nums}, ["{y}"], {cats})

xNames=ds.columns.to_list()
xNames.remove("{y}")
y=pd.DataFrame(ds.loc[:,"{y}"])
x=ds.loc[:,xNames]

config=dict()
config["max_depth"]=10
config["min_samples_leaf"]={minSamplesLeaf}
model=ctree(x,y,config)

model.build()
print("cv_minFunc",model.cv_minFun)
print("cv_minX",model.cv_minX)
print("score",model.score)
model.visualize()
model.save("{oPath}/model")

pred=model.predict(x)
pred.evaluate(y)
pred.save("{oPath}/pred")
print("#### END")
""".format(**params)

        script_w.value = script1 + script2 + script3
        return True
Exemple #3
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value + "/" + self.oDir_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(self.oDir_w.value, "出力dir名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False
        params["minFreq"] = self.minFreq_w.value

        script1 = wlib.readSource("nysol.widget.songs.lib.features")
        script2 = """
import os
print("#### START")

oPath="{oPath}"
os.makedirs(oPath,exist_ok=True)
features("{iFile}",oPath,{minFreq})

print("#### END")
""".format(**params)

        # script tabにセット
        script_w.value = script1 + script2
        return True
Exemple #4
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["oFile"], "出力ファイル名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        script1 = wlib.readSource("nysol.widget.songs.lib.parsing", "parsing")
        script2 = """
import os
print("#### START")

oPath="{oPath}"
os.makedirs(oPath,exist_ok=True)
parsing_count("{iFile}","%s/{oFile}"%(oPath)) 

print("#### END")
""".format(**params)

        # script tabにセット
        script_w.value = script1 + script2
        return True
Exemple #5
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["oFile"], "出力ファイル名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        key = self.key_w.getValue()
        field = self.field_w.getValue()
        stat = self.stat_w.value
        newfld = self.newfld_w.value

        flds = []
        if key != "":
            flds.append(key)
        flds.append(field)
        params1 = "f='%s',i='%s'" % (",".join(flds), params["iFile"])

        params2 = ""
        if key != "":
            params2 += "k='%s'" % (key)
        if newfld == "":
            params2 += ",f='%s'" % (field)
        else:
            params2 += ",f='%s:%s'" % (field, newfld)
        params2 += ",c='%s',o='%s/%s'" % (stat, params["oPath"],
                                          params["oFile"])

        header = """
#################################
# mstats_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
""" % (self.version, self.date)

        lib = """
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")
"""
        script = """
f=None
f<<=nm.mcut(%s)
f<<=nm.mstats(%s)
f.run(msg='on')
print("#### END")
""" % (params1, params2)

        script_w.value = header + lib + script
        return True
Exemple #6
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["oFile"], "出力ファイル名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        params["tid"] = self.tid_w.getValue()
        params["item"] = self.item_w.getValue()
        params["agg"] = self.agg_w.getValue()
        params["klass"] = self.klass_w.getValue()
        params["null"] = self.null_w.value
        params["dummy"] = self.dummy_w.value
        params["stat"] = self.stat_w.value

        script1 = wlib.readSource("nysol.mining.tra2tbl")
        script2 = """
print("#### START")

iFile="{iFile}"
oFile="{oPath}/{oFile}"
tidFld="{tid}"
itemFld="{item}"
null={null}
dummy={dummy}
aggFld="{agg}"
aggStat="{stat}"
klassFld="{klass}"

tra2tbl(iFile,oFile,tidFld,itemFld,null=null,dummy=dummy,aggFld=aggFld,aggStat=aggStat,klassFld=klassFld)
print("#### END")
""".format(**params)

        script_w.value = script1 + script2
        return True
Exemple #7
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        if not wlib.iFileCheck(params["iFile"], self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["oFile"], "出力ファイル名", self.parent.msg_w):
            return False
        if not wlib.oPathCheck(params["oPath"], self.parent.msg_w):
            return False

        _head = self.head_w.value
        _tail = self.tail_w.value
        reverse = self.reverse_w.value
        key = self.key_w.getValue()
        field = self.field_w.getValue()
        value = self.value_w.value

        if value == "":
            self.parent.msg_w.value = "##ERROR: 「値」が入力されていません。"
            return False

        if _head and _tail:
            sub = False
            head = False
            tail = False
        elif _head:
            sub = False
            head = True
            tail = False
        elif _tail:
            sub = False
            head = False
            tail = True
        else:
            sub = True
            head = False
            tail = False

        par = []
        if key != "":
            par.append("k=\"" + key + "\"")
        par.append("f=\"" + field + "\"")
        par.append("v=\"" + value + "\"")
        if reverse:
            par.append("r=True")
        if head:
            par.append("head=True")
        if tail:
            par.append("tail=True")
        if sub:
            par.append("sub=True")
        par.append("i=\"" + params["iFile"] + "\"")
        par.append("o=\"" + params["oPath"] + "/" + params["oFile"] + "\"")

        header = """
#################################
# mselstr_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
""" % (self.version, self.date)

        lib = """
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")
"""
        script = """
f=None
f<<=nm.mselstr(%s)
f.run(msg='on')
print("#### END")
""" % (",".join(par))

        script_w.value = header + lib + script
        return True
Exemple #8
0
	def exe(self,script_w):
		params={}
		params["version"]  = self.version
		params["date"]     = self.date
		params["iFile"]    = self.iName_w.value
		params["oPath"]    = self.oPath_w.value
		params["oDir"]     = self.oDir_w.value

		if not wlib.iFileCheck(params["iFile"],self.parent.msg_w):
			return False
		if not wlib.blankCheck(params["oDir"],"出力dir名",self.parent.msg_w):
			return False
		if not wlib.oPathCheck(params["oPath"],self.parent.msg_w):
			return False

		params["tid"]      = self.traID_w.getValue()
		params["item"]     = self.item_w.getValue()
		params["minSup"]   = self.minSup_w.value
		params["sim"]      = self.edgeType_w.value
		params["nodeSup"]  = self.nodeSup_w.value
		if params["sim"]=="minConf":
			params["th"]  = self.minConf_w.value
			params["simName"]  = "C"
			params["simFld"]  = "confidence"
			params["undirect"]  = False
		else:
			params["th"]  = self.minPMI_w.value
			params["simName"]  = "P"
			params["simFld"]  = "PMI"
			params["undirect"]  = True

		if params["tid"]==params["item"]:
			self.parent.msg_w.value="##ERROR: トランザクションIDとアイテム項目が同じ項目になってます"
			return False

		script="""
import os
import nysol.take as nt
import nysol.mcmd as nm
import nysol.view.mnetpie as nnpie
nm.setMsgFlg(True)
print("#### START")

# 出力ディレクトリを作成する
op="{oPath}"+"/"+"{oDir}"
os.makedirs(op,exist_ok=True)

nt.mtra2gc(i="{iFile}",
				tid="{tid}",
				item="{item}",
				no=op+"/node.csv",
				eo=op+"/edge.csv",
				s={minSup},
				sim="{simName}",
				th={th},
				node_support={nodeSup}
				).run()

nm.mnormalize(f="support:_nv",c="range",i=op+"/node.csv").mcal(c="${{_nv}}*200",a="_nodeSize",o=op+"/node2.csv").run()

nnpie.mnetpie(ei=op+"/edge.csv",
				ni=op+"/node2.csv",
				ef="node1,node2",
				nf="node",
				o=op+"/graph.html",
				nodeSizeFld="_nodeSize",
				undirect={undirect}
				)
print("#### END")
""".format(**params)

		#os.system("fdp)
		"""
mgv(ei=op+"/edge.csv",ef="e1,e2",o=op+"/graph.dot")
"""

		#edgeWidthFld="{simFld}",

		script_w.value = script
		return True
Exemple #9
0
	def exe(self,script_w):
		params={}
		params["version"]=self.version
		params["date"]=self.date
		params["iFile"]= self.iName_w.value
		params["oPath"]= self.oPath_w.value
		params["oDir"] = self.oDir_w.value

		if not wlib.iFileCheck(params["iFile"],self.parent.msg_w):
			return False
		if not wlib.blankCheck(params["oDir"],"出力dir名",self.parent.msg_w):
			return False
		if not wlib.oPathCheck(params["oPath"],self.parent.msg_w):
			return False

		params["tid"]   =self.traID_w.getValue()
		params["item"]  =self.item_w.getValue()
		params["klass"] =self.class_w.getValue()
		params["pType"] =self.type_w.value[0] # 0は先頭文字の(F,C,M)
		params["minSup"]=self.minSup_w.value
		params["maxSup"]=self.maxSup_w.value
		params["minLen"]=self.minLen_w.value
		params["maxLen"]=self.maxLen_w.value
		params["minGR"] =self.minGR_w.value
		params["top"]   =self.top_w.value

		if params["item"]==params["tid"]:
			self.parent.msg_w.value="##ERROR: トランザクションIDとアイテム項目が同じ項目になってます"
			return False

		if self.usetop_w.value==True:
			script="""
#################################
# mitemset_w.pyの自動生成スクリプト
# version: {version}
# 実行日時: {date}
#################################
import os
import nysol.take as nt
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")

########### parameter設定
traFile="{iFile}" # トランザクションファイル名
oPath="{oPath}/{oDir}" # 出力ディレクトリ名
tid="{tid}" # トランザクションID項目
item="{item}" # アイテム項目
klass="{klass}" # クラス項目
pType="{pType}" # パターンタイプ(F:頻出集合,C:飽和集合,M:極大集合)
minSup={minSup} # minimum support
maxSup={maxSup} # maximum support
minLen={minLen} # minimum length of items
maxLen={maxLen} # maximum length of items
minGR={minGR} # minimum post-probability (klass指定時のみ有効)
top={top} # 抽出上位件数(supportの大きい順)

os.makedirs(oPath,exist_ok=True)

nt.mitemset(i=traFile,
				cls=klass,
				tid=tid,
				item=item,
				O=oPath,
				type=pType,
				s=minSup,
				sx=maxSup,
				l=minLen,
				u=maxLen,
				p=minGR,
				top=top).run()
print("#### END")
""".format(**params)

		else:
			script="""
#################################
# mitemset_w.pyの自動生成スクリプト
# version: {version}
# 実行日時: {date}
#################################
import os
import nysol.take as nt
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")

########### parameter設定
traFile="{iFile}" # トランザクションファイル名
oPath="{oPath}/{oDir}" # 出力ディレクトリ名
tid="{tid}" # トランザクションID項目
item="{item}" # アイテム項目
klass="{klass}" # クラス項目
pType="{pType}" # パターンタイプ(F:頻出集合,C:飽和集合,M:極大集合)
minSup={minSup} # minimum support
maxSup={maxSup} # maximum support
minLen={minLen} # minimum length of items
maxLen={maxLen} # maximum length of items
minGR={minGR} # minimum post-probability (klass指定時のみ有効)

os.makedirs(oPath,exist_ok=True)

nt.mitemset(i=traFile,
				cls=klass,
				tid=tid,
				item=item,
				O=oPath,
				type=pType,
				s=minSup,
				sx=maxSup,
				l=minLen,
				u=maxLen,
				p=minGR).run()
print("#### END")
""".format(**params)

		# script tabにセット
		script_w.value = script
		return True
Exemple #10
0
	def exe(self,script_w):
		params={}
		params["iFile"]= self.iName_w.value
		params["oPath"]= self.oPath_w.value
		params["oFile"]= self.oFile_w.value

		if not wlib.iFileCheck(params["iFile"],self.parent.msg_w):
			return False
		if not wlib.blankCheck(params["oFile"],"出力ファイル名",self.parent.msg_w):
			return False
		if not wlib.oPathCheck(params["oPath"],self.parent.msg_w):
			return False

		key=self.key_w.getValue()
		field=self.field_w.getValue()
		vFr=self.vFr_w.value
		vFrEq=self.vFrEq_w.value
		vTo=self.vTo_w.value
		vToEq=self.vToEq_w.value
		reverse=self.reverse_w.value

		rFr="("
		rTo=")"
		if vFrEq:
			rFr="["
		if vToEq:
			rTo="]"
		range_="%s%s,%s%s"%(rFr,vFr,vTo,rTo)

		par=[]
		if key!="":
			par.append("k=\""+key+"\"")
		par.append("f=\""+field+"\"")
		par.append("c=\""+range_+"\"")
		if reverse:
			par.append("r=True")
		par.append("i=\""+params["iFile"]+"\"")
		par.append("o=\""+params["oPath"]+"/"+params["oFile"]+"\"")

		header="""
#################################
# mselnum_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
"""%(self.version,self.date)

		lib="""
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")
"""
		script="""
f=None
f<<=nm.mselnum(%s)
f.run(msg='on')
print("#### END")
"""%(",".join(par))

		script_w.value = header+lib+script
		return True
Exemple #11
0
    def exe(self, script_w):
        params = {}
        params["iFile"] = self.iName_w.value
        params["oPath"] = self.oPath_w.value
        params["oFile"] = self.oFile_w.value

        params["key"] = self.key_w.getValue()
        params["fld"] = self.field_w.getValue()
        params["val"] = self.value_w.value
        params["newName"] = self.newfld_w.value

        params["reverse"] = self.reverse_w.value
        params["reverse_r"] = not params["reverse"]

        if not wlib.blankCheck(params["val"], "「値」", self.parent.msg_w):
            return False
        if not wlib.blankCheck(params["newName"], "「目的変数名」",
                               self.parent.msg_w):
            return False

        _head = self.head_w.value
        _tail = self.tail_w.value
        if _head and _tail:
            sub = False
            head = False
            tail = False
        elif _head:
            sub = False
            head = True
            tail = False
        elif _tail:
            sub = False
            head = False
            tail = True
        else:
            sub = True
            head = False
            tail = False
        params["sub"] = sub
        params["head"] = head
        params["tail"] = tail

        script = """
klass=None
klass<<=nm.mselstr(k='{key}',f='{fld}',v='{val}',r={reverse},head={head},tail={tail},sub={sub},i='{iFile}')
klass<<=nm.msetstr(v='1',a='{newName}')
klass<<=nm.mcut(f='{key},{newName}')
klass<<=nm.muniq(k='{key},{newName}')

f=None
f<<=nm.mjoin(k='{key}',m=klass,f='{newName}',n=True,i='{iFile}')
f<<=nm.mselstr(f='{fld}',v='{val}',r={reverse_r},head={head},tail={tail},sub={sub})
f<<=nm.mnullto(f='{newName}',v='0',o='{oPath}/{oFile}')
f.run()
print("#### END")
""".format(**params)

        header = """
#################################
# mselstr_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
""" % (self.version, self.date)

        lib = """
import nysol.mcmd as nm
nm.setMsgFlg(True)
print("#### START")
"""
        output = """
# ファイル出力された結果
oFile="%s"
""" % (params["oFile"])

        script_w.value = header + lib + script
        return True
Exemple #12
0
	def exe(self,script_w):
		params={}
		params["iFile"]= self.iName_w.value
		params["oPath"]= self.oPath_w.value
		params["oDir"] = self.oDir_w.value

		if not wlib.iFileCheck(params["iFile"],self.parent.msg_w):
			return False
		if not wlib.blankCheck(params["oDir"],"出力dir名",self.parent.msg_w):
			return False
		if not wlib.oPathCheck(params["oPath"],self.parent.msg_w):
			return False

		#params["_id"]  =self.id_w.getValue()
		params["x"]    =list(self.x_w.getValue())
		params["algo"] =self.algo_w.value
		params["k"]    =self.k_w.value

		#if params["_id"] in params["x"]:
		#	self.parent.msg_w.value="##ERROR: idと入力変数が重複指定されています"
		#	return False
		if not wlib.blankCheck(params["k"],"クラスタ数",self.parent.msg_w):
			return False

		header="""
#################################
# mitemset_w.pyの自動生成スクリプト
# version: %s
# 実行日時: %s
#################################
"""%(self.version,self.date)

		script="""
import os
import csv
import numpy as np
import pandas as pd
from sklearn.cluster import KMeans
from yellowbrick.cluster import InterclusterDistance
print("#### START")

########### parameter設定
iFile="{iFile}" # 入力CSVファイル名
x={x} # 入力変数
oPath="{oPath}" # 出力パス
oDir="{oDir}" # 出力ディレクトリ名
algo="{algo}" # クラスタリングアルゴリズム
k={k} # クラスタ数

print("## データセット作成中...")
# 出力ディレクトリを作成する
os.makedirs(oPath+"/"+oDir,exist_ok=True)

# CSVデータをpandas DataFrameに読み込む
df=pd.read_csv(iFile,dtype=str) # とりあえずは全項目str型として読み込む
ds=df.loc[:,x] # 入力変数のみ選択する
ds=ds.astype(float) # 全変数をfloat型に設定する

print("## クラスタリング{algo} 実行中...")
# kmeansモデルの設定と実行
model=KMeans(n_clusters=k)
pred=model.fit_predict(ds.values)

print("## 結果出力")
cluster=pd.DataFrame(pred) # 予測結果をDataFrameに
cluster.columns=["cluster"] # 項目名を設定
out=df.join(cluster) # 元のDataframeに結合する

visualizer = InterclusterDistance(model)
visualizer.fit(ds.values)
visualizer.show(outpath="{oPath}/{oDir}/interclusterDistance.png")
visualizer.show()

# CSVに出力
out.to_csv("{oPath}/{oDir}/predict.csv",index_label=None,encoding="utf-8")

print("#### END")
""".format(**params)

		script_w.value = script
		return True