@@ -5,6 +5,7 @@ using Statistics
55using Serialization
66import PythonCall
77const PYC = PythonCall
8+ using CSV
89
910using DataFrames: DataFrame
1011using Random
@@ -99,21 +100,21 @@ function plottroutput(mlfad::AutoMLFlowAnomalyDetection, Y::Union{Vector,DataFra
99100 strndx = string (ndx)
100101 coldata = data[:, strndx]
101102 ndx = findall (x -> x == true , coldata)
102- Plots. plot (data. x1 , label= " tsdata" , title= " Anomaly voting cutoff=$strndx " )
103+ Plots. plot (data[:, 1 ] , label= " tsdata" , title= " Anomaly voting cutoff=$strndx " )
103104 xlabel! (" X" )
104105 ylabel! (" Y" )
105- plp = scatter! (ndx, data. x1 [ndx], label= " anomalous" )
106+ plp = scatter! (ndx, data[:, 1 ] [ndx], label= " anomalous" )
106107 savefig (plp, artifact_plot)
107108 append_pdf! (artifact_allplots, artifact_plot, cleanup= true )
108109 end
109110 else
110111 strndx = string (votepercent)
111112 coldata = data[:, strndx]
112113 ndx = findall (x -> x == true , coldata)
113- Plots. plot (data. x1 , label= " tsdata" , title= " Anomaly voting cutoff=$strndx " )
114+ Plots. plot (data[:, 1 ] , label= " tsdata" , title= " Anomaly voting cutoff=$strndx " )
114115 xlabel! (" X" )
115116 ylabel! (" Y" )
116- scatter! (ndx, data. x1 [ndx], label= " anomalous" )
117+ scatter! (ndx, data[:, 1 ] [ndx], label= " anomalous" )
117118 savefig (artifact_allplots)
118119 end
119120 MLF. log_artifact (artifact_allplots)
@@ -141,54 +142,56 @@ function transform(mlfad::AutoMLFlowAnomalyDetection, X::DataFrame)
141142end
142143
143144function mlfaddriver ()
145+ url = " http://localhost:8081"
144146 url = " http://mlflow.home"
145- url = " http://localhost:8080"
146147 url = " http://mlflow.isiath.duckdns.org:8082"
147148
148- X = vcat (5 * cos .(- 10 : 10 ), sin .(- 30 : 30 ), 3 * cos .(- 10 : 10 ), 2 * tan .(- 10 : 10 ), sin .(- 30 : 30 )) |> x -> DataFrame ([x], :auto )
149-
150- # test all voting percent
151- mlfad = AutoMLFlowAnomalyDetection (Dict (:url => url))
152- Yc = fit_transform! (mlfad, X)
153- println (Yc |> x -> first (x, 5 ))
154-
155- # test specific votepercent
156- mlvad = AutoMLFlowAnomalyDetection (Dict (:url => url, :impl_args => Dict (:votepercent => 0.3 )))
157- Yc = fit_transform! (mlvad, X)
158- println (Yc |> x -> first (x, 5 ))
159-
160- # override default votepercent
161- mlfad = AutoMLFlowAnomalyDetection (Dict (:url => url))
162- mlfad. model[:automodel ](; votepercent= 0.5 )
163- Yc = fit_transform! (mlfad, X)
164- println (Yc |> x -> first (x, 5 ))
149+ X = CSV. read (" ./data/node_cpu_ratio_rate_5m_1d_1m.csv" ,DataFrame;header= false )
165150
151+ # X = vcat(5 * cos.(-10:10), sin.(-30:30), 3 * cos.(-10:10), 2 * tan.(-10:10), sin.(-30:30)) |> x -> DataFrame([x], :auto)
166152
153+ # test all voting percent
167154 mlfad = AutoMLFlowAnomalyDetection (Dict (:url => url))
168- mlfad. model[:automodel ](; votepercent= 0.0 )
169155 Yc = fit_transform! (mlfad, X)
170156 println (Yc |> x -> first (x, 5 ))
171157
172- # # test prediction using exisiting trained model from artifacts
173- # ### alternative 1 to use trained model for transform
174- mlvad = AutoMLFlowAnomalyDetection (Dict (:url => url))
175- Yc = fit_transform! (mlvad, X)
176- run_id = mlvad. model[:run_id ]
177- newmlad = AutoMLFlowAnomalyDetection (Dict (:run_id => run_id, :url => url, :impl_args => Dict (:votepercent => 0.5 )))
178- newmlad. model[:automodel ](; votepercent= 0.2 )
179- Yn = transform! (newmlad, X)
180- println (Yn |> x -> first (x, 5 ))
181-
182- # # alternative 2 to use trained model for transform
183- mlvad = AutoMLFlowAnomalyDetection (Dict (:url => url))
184- Yc = fit_transform! (mlvad, X)
185- run_id = mlvad. model[:run_id ]
186- votepercent = 0.3
187- newmlad = AutoMLFlowAnomalyDetection (Dict (:url => url))
188- newmlad (; run_id)
189- newmlad. model[:automodel ](; votepercent)
190- Yn = transform! (newmlad, X)
191- println (Yn |> x -> first (x, 5 ))
158+ # # test specific votepercent
159+ # mlvad = AutoMLFlowAnomalyDetection(Dict(:url => url, :impl_args => Dict(:votepercent => 0.3)))
160+ # Yc = fit_transform!(mlvad, X)
161+ # println(Yc |> x -> first(x, 5))
162+ #
163+ # # override default votepercent
164+ # mlfad = AutoMLFlowAnomalyDetection(Dict(:url => url))
165+ # mlfad.model[:automodel](; votepercent=0.5)
166+ # Yc = fit_transform!(mlfad, X)
167+ # println(Yc |> x -> first(x, 5))
168+ #
169+ #
170+ # mlfad = AutoMLFlowAnomalyDetection(Dict(:url => url))
171+ # mlfad.model[:automodel](; votepercent=0.0)
172+ # Yc = fit_transform!(mlfad, X)
173+ # println(Yc |> x -> first(x, 5))
174+ #
175+ # ## test prediction using exisiting trained model from artifacts
176+ # #### alternative 1 to use trained model for transform
177+ # mlvad = AutoMLFlowAnomalyDetection(Dict(:url => url))
178+ # Yc = fit_transform!(mlvad, X)
179+ # run_id = mlvad.model[:run_id]
180+ # newmlad = AutoMLFlowAnomalyDetection(Dict(:run_id => run_id, :url => url, :impl_args => Dict(:votepercent => 0.5)))
181+ # newmlad.model[:automodel](; votepercent=0.2)
182+ # Yn = transform!(newmlad, X)
183+ # println(Yn |> x -> first(x, 5))
184+ #
185+ # ## alternative 2 to use trained model for transform
186+ # mlvad = AutoMLFlowAnomalyDetection(Dict(:url => url))
187+ # Yc = fit_transform!(mlvad, X)
188+ # run_id = mlvad.model[:run_id]
189+ # votepercent = 0.3
190+ # newmlad = AutoMLFlowAnomalyDetection(Dict(:url => url))
191+ # newmlad(; run_id)
192+ # newmlad.model[:automodel](; votepercent)
193+ # Yn = transform!(newmlad, X)
194+ # println(Yn |> x -> first(x, 5))
192195
193196 return nothing
194197end
0 commit comments