自動選擇異常值我有 7000 行,由多個批次組成。我正在按批次進行分佈,並使用離群值箱形圖來查找離群值。但我有 100 多個批次,有沒有辦法讓 JMP 自動選擇哪些行是異常值?
回复:自動選擇異常值這是你需要的嗎?
Names Default To Here( 1 );
// make a sample data table
dt = New Table( "Data",
add rows( 10000 ),
New Column( "it", Numeric, Ordinal, Format( "Best", 8 ), Formula( Row() ) ),
New Column( "Batch", Numeric, Ordinal, Format( "Best", 8 ), formula( Random Integer( 110 ) ) ),
New Column( "y1", Numeric, Continues, Format( "Best", 8 ), formula( Random Lognormal( :Batch / 10, 5 ) ) ),
New Column( "y2", Numeric, Continues, Format( "Best", 8 ), formula( Random Lognormal( :Batch / 10, 5 ) ) ),
New Column( "Out",
Numeric,
Ordinal,
Format( "Best", 8 ),
Set Property( "Value Colors", {0 = -13977687, 1 = -4222943} ),
Color Cell by Value,
formula( 0 )
),
New Column( "Outy1",
Numeric,
Ordinal,
Format( "Best", 8 ),
Set Property( "Value Colors", {0 = -13977687, 1 = -4222943} ),
Color Cell by Value,
formula( 0 )
),
New Column( "Outy2",
Numeric,
Ordinal,
Format( "Best", 8 ),
Set Property( "Value Colors", {0 = -13977687, 1 = -4222943} ),
Color Cell by Value,
formula( 0 )
),
);
dt << run formulas;
Column( dt, "it" ) << delete formula;
Column( dt, "Batch" ) << delete formula;
Column( dt, "y1" ) << delete formula;
Column( dt, "y2" ) << delete formula;
Column( dt, "Out" ) << delete formula;
Column( dt, "Outy1" ) << delete formula;
Column( dt, "Outy2" ) << delete formula;
// now we get to work
// make a list of batches
byvarlist = Associative Array( dt:Batch ) << get keys;
// make a list of columns
cols = dt << get column names( Continuous ); //List all Numeric columns
// loop through the batches
For( i = 1, i <= N Items( byvarlist ), i++,
// select each batch
dt << select where( dt:Batch == byvarlist[i] );
// subset each batch
subdt = dt << Subset( Selected Rows( 1 ) );
// clear selection for smoth workflow
dt << clear select;
// finde outliers in each variable within each batch
For( ii = 1, ii <= N Items( cols ), ii++,
out = Eval(
Parse(
"subdt << get rows where(
subdt:" || Char( cols[ii] ) || " > Col Quantile( subdt:" || Char( cols[ii] ) ||
", 0.75 ) + 1.5 * (Col Quantile( subdt:" || Char( cols[ii] ) || ", 0.75 ) - Col Quantile( subdt:" || Char( cols[ii] ) ||
", 0.25 )) | subdt:" || Char( cols[ii] ) || " <
Col Quantile( subdt:" || Char( cols[ii] ) ||
", 0.25 ) - 1.5 * (Col Quantile( subdt:" || Char( cols[ii] ) || ", 0.75 ) - Col Quantile( subdt:" || Char( cols[ii] ) ||
", 0.25 )));"
)
)`;
Eval( Parse( "column (subdt, \!"Out" || Char( cols[ii] || "\!" )[" || Char( out ) || "] = 1;" ) ) );
// also indicate the global outlier
Column( subdt, "Out" )[out] = 1;
//wait (0.00001);
);
// update original data table with new information for the batch
subdt << delete columns( "Batch" );
subdt << delete columns( cols );
dt << Update( With( subdt ), Match Columns( :it = :it ) );
Close( subdt, No Save );
//Wait( 0.00001 );
);
dt << color by column( :Out );
回复:自動選擇異常值再問一個簡單的問題。 我刪除了大約 90 列,這可以嗎
有 n 列還是總是必須有 3 列?
回复:自動選擇異常值似乎有效。謝謝。
回复:自動選擇異常值現在看看它是否適合你......
您發送的腳本根本不適合您的數據......
回复:自動選擇異常值附件是我嘗試使用它的數據示例。理想情況下,它會對每個 Y 執行此操作。
回复:自動選擇異常值我的公式對批量大小不敏感。此外,即使批處理列是字符(而不是數字),它也將起作用。
你能發布一個樣品嗎,即使只有兩到三個不同的批次?回复:自動選擇異常值當我運行它時,我得到一張表,這是它的快照,這將
工作,因為如果我想選擇所有的,我可以選擇 Out = 1 的行
異常值。
[圖片:image.png]
回复:自動選擇異常值如果你運行整個腳本,你能看到你得到了你想要的東西(只是不在你的數據上)?回复:自動選擇異常值我複制了 // 現在我們開始工作。 當我運行這個時
我自己的表,它只創建一張表,只包含一批。 我必須說
有一件事是每批的點數不一致。 我願意
不知道這是否重要。
回复:自動選擇異常值這對我有用。
最後你應該有 3 張桌子。包含所有行的原始數據,一行僅包含異常值,最後一行沒有異常值。讓我知道它是否有效。
Names Default To Here( 1 );<BR /><BR />// make a sample data table<BR />dt = New Table( "Data",<BR /> add rows( 10000 ),<BR /> New Column( "it", Numeric, Continues, Format( "Best", 8 ), Formula( Row() ) ),<BR /> New Column( "Batch", Numeric, Ordinal, Format( "Best", 8 ), formula( Random Integer( 110 ) ) ),<BR /> New Column( "y", Numeric, Continues, Format( "Best", 8 ), formula( Random Lognormal( :Batch / 10, 5 ) ) ),<BR /> New Column( "Out", Numeric, Ordinal, Format( "Best", 8 ), formula( 0 ) ), <BR /><BR />);<BR /><BR />dt << run formulas;<BR />Column( dt, "it" ) << delete formula;<BR />Column( dt, "Batch" ) << delete formula;<BR />Column( dt, "y" ) << delete formula;<BR />Column( dt, "Out" ) << delete formula;<BR /><BR />// now we get to work<BR />dt = Current Data Table();<BR />byvarlist = Associative Array( dt:Batch ) << get keys;<BR />For( i = 1, i <= N Items( byvarlist ), i++,<BR /> dt << select where( dt:Batch == byvarlist[i] );<BR /> subdt = dt << Subset( Selected Rows( 1 ) );<BR /> dt << clear select;<BR /> subdt:Out << set formula(<BR /> If(<BR /> :y > Col Quantile( :y, 0.75 ) + (Col Quantile( :y, 0.75 ) - Col Quantile( :y, 0.25 )) * 1.5, 1,<BR /> :y < Col Quantile( :y, 0.25 ) - (Col Quantile( :y, 0.75 ) - Col Quantile( :y, 0.25 )) * 1.5, 1,<BR /> 0<BR /> )<BR /> );<BR /> subdt << run formulas;<BR /> Column( subdt, "Out" ) << delete formula;<BR /> keep = {"it", "Out"};<BR /> todelete = subdt << get column names( "string" );<BR /> For( icol = 1, icol <= N Items( keep ), icol++,<BR /> Remove From( todelete, Contains( todelete, Keep[icol] ), 1 )<BR /> );<BR /> subdt << delete columns( todelete );<BR /> dt << Update( With( subdt ), Match Columns( :it = :it ) );<BR /> Close( subdt, No Save );<BR /> Wait( 0.00001 );<BR />);<BR />selected = dt << select where( :Out == 1 );<BR />selected << Markers( 11 );<BR />selected << Marker Size( 8 );<BR />selected << Row Colors( red );<BR />dt << clear select;<BR /><BR />dt << select where( dt:Out == 1 );<BR />Outdt = dt << Subset( Selected Rows( 1 ) );<BR />dt << clear select;<BR /> <BR />Wait( 0.00001 );<BR /> <BR />dt << select where( dt:Out == 0 );<BR />indt = dt << Subset( Selected Rows( 1 ) );<BR />dt << clear select;<BR /><BR />
回复:自動選擇異常值我不確定你是否收到我剛剛發送的最後一條消息,我收到一條奇怪的消息
自動回復電子郵件。 我修好了第二個,它仍然在做
一樣。
回复:自動選擇異常值在 for 循環中它不是回复:自動選擇異常值我的批處理列是大寫的:
[圖片:image.png]
回复:自動選擇異常值列名區分大小寫,使用 :Batch 或 :batch 時保持一致回复:自動選擇異常值當我運行這個時,它僅使用第一批創建了一個子集表。 我
改變這個來做我的開放表:
dt = currentdatatable();
byvarlist = Associative Array( dt:Batch ) << get keys;
For( i = 1, i <= N Items( byvarlist ), i++,
dt << select where( dt:batch == byvarlist[i] );
subdt = dt << Subset( Selected Rows( 1 ) );
dt << clear select;
subdt:Out << set formula(
If(
:y > Col Quantile( :y, 0.75 ) + (Col Quantile( :y, 0.75 )
-Col Quantile( :y, 0.25 )) * 1.5, 1,
:y < Col Quantile( :y, 0.25 ) - (Col Quantile( :y, 0.75 )
-Col Quantile( :y, 0.25 )) * 1.5, 1,
0
)
);
subdt << run formulas;
Column( subdt, "Out" ) << delete formula;
keep = {"it", "Out"};
todelete = subdt << get column names( "string" );
For( icol = 1, icol <= N Items( keep ), icol++,
Remove From( todelete, Contains( todelete, Keep[icol] ), 1 )
);
subdt << delete columns( todelete );
dt << Update( With( subdt ), Match Columns( :it = :it ) );
Close( subdt, No Save );
);
selected = dt << select where( :Out == 1 );
selected << Markers( 11 );
selected << Marker Size( 8 );
selected << Row Colors( red );
dt << clear select;回复:自動選擇異常值讓我再嘗試一次
這不是一個圓滑的解決方案,但步驟清晰且易於修改
Names Default To Here( 1 );
// make a sample data table
dt = New Table( "Data",
add rows( 10000 ),
New Column( "it", Numeric, Continues, Format( "Best", 8 ), Formula( Row() ) ),
New Column( "Batch" ,Numeric, Ordinal, Format( "Best", 8 ), formula( random integer (110) )),
New Column( "y" ,Numeric, Continues, Format( "Best", 8 ), formula( random log normal (:Batch / 10, 5) )),
New Column( "Out" ,Numeric, Ordinal, Format( "Best", 8 ), formula (0)),
);
dt << run formulas;
column (dt, "it") << delete formula;
column (dt, "Batch") << delete formula;
column (dt, "y") << delete formula;
column (dt, "Out") << delete formula;
// now we get to work
// extract the list of the by variable levels
byvarlist = Associative Array( dt:Batch ) << get keys;
// run across each group and locate the outliers
For( i = 1, i <= N Items( byvarlist ), i++,
// produce a subset data table for each group using selection method
dt << select where (dt:batch == byvarlist[i]);
subdt = dt << Subset(
Selected Rows( 1 ),
);
dt << clear select;
// indicate outliers within the group
subdt:Out << set formula(
If(
:y > Col Quantile( :y, 0.75 ) + (Col Quantile( :y, 0.75 ) -
Col Quantile( :y, 0.25 )) * 1.5, 1,
:y < Col Quantile( :y, 0.25 ) - (Col Quantile( :y, 0.75 ) -
Col Quantile( :y, 0.25 )) * 1.5, 1,
0
)
);
subdt << run formulas;
// prepare table for updating original by removing formulas and columns that are not needed
column (subdt, "Out") << delete formula;
keep = {"it", "Out"};
todelete = subdt << get column names( "string" );
For( icol = 1, icol <= N Items( keep ), icol++,
Remove From( todelete, Contains( todelete, Keep[icol] ), 1 )
);
subdt << delete columns( todelete );
// update
dt << Update(
With( subdt ),
Match Columns( :it = :it )
);
Close( subdt, No Save );
);
// now the original data has all the outliers indicated in a column
selected = dt << select where (:Out == 1);
selected << Markers( 11 );
selected << Marker size ( 8 );// not working???
selected << Row Colors( red );// not working???
dt << clear select;
回复:自動選擇異常值嘗試按批次拆分錶並按唯一值分組(這樣您就不會丟失任何行),然後運行我的腳本。
否則你需要一種與我提供的策略不同的策略。
是否有意義?回复:自動選擇異常值我無法讓它與我的數據一起使用,我更改了列的高度和重量,並刪除了打開表格並將其嵌入到我的表格中的兩行,但它說評估已完成,但不會執行任何操作。
我還需要為每個批次單獨使用 by 和 this 的東西。
回复:自動選擇異常值你好,
也許這是一個解決方案:
https://community.jmp.com/t5/Discussions/How-to-extract-month-in-words-from-a-date-value-how-to-change/mp/19362/highlight/true#M17650
羅恩
回复:自動選擇異常值我嘗試了格魯布的腳本。這只是顯示了異常值,並沒有突出顯示行,對嗎?我需要一些可以突出顯示行的東西。
回复:自動選擇異常值如果我需要一個變量,那麼篩選離群值就不起作用。我想做的是我的 Y 位於一列中。另一列標記為批次。我將批次放入並按批次進行分配數量。假設有 100 個發行版。我想要一個腳本來突出顯示所有 100 個分佈中的所有異常值。理想情況下,它只會突出顯示行,這樣我就可以選擇自己的顏色,因為我對不同的東西使用顏色。現在更有意義了嗎?
回复:自動選擇異常值如果您搜索過文件交換的一部分JMP 社區為了 '異常值,'您會發現這兩個實用程序腳本:
當然,每個測試的統計基礎必須適合您的情況和標準。
回复:自動選擇異常值我不確定您到底在尋找什麼。如果要選擇給定分佈的行,則在查看輸出時,只需在離群值箱線圖中顯示的離群值數據點上拖動即可,它將選擇離群值數據點。

但是,如果您想從一列轉到另一列並選擇離群值行,一個簡單的腳本就可以做到這一點,但是請記住,行選擇會跨越所有列,您最終會得到選擇任意列的選定行。 。
您可能真正想要的是一個簡單的腳本,為所有異常值的單個單元格著色。如果遠高於平均值,則可能為紅色;如果低於平均值的異常值,則可能為橙色。
您能準確說明您在尋找什麼嗎?
請參閱 Dan 的回復以獲得更好的答案。
回复:自動選擇異常值您可能需要查看“分析”>“篩選”>“探索離群值”。