TransformAnomalies[data,tspec]
データ中の異常値を変換 tspec を使って変換する.
TransformAnomalies[data,dspectspec]
指定 dspec を使って異常値を検出する.
TransformAnomalies[tab,{col1spec1,…}]
列 coliに指定 speciを使って表形式データ tab を変換する.
TransformAnomalies
TransformAnomalies[data,tspec]
データ中の異常値を変換 tspec を使って変換する.
TransformAnomalies[data,dspectspec]
指定 dspec を使って異常値を検出する.
TransformAnomalies[tab,{col1spec1,…}]
列 coliに指定 speciを使って表形式データ tab を変換する.
詳細
- TransformAnomaliesは,異常検出あるい外れ値処理としても知られている.
- TransformAnomaliesは,事実上異常値を特定しこれを管理することで,信頼性の高い分析を保証し,データ品質を保持することに役に立つ.
- 次は,data の使用可能な形式である.
-
{el1,el2,…} 個々の要素のリスト tab 表形式データ - 次は,使用可能な表形式データ tab の形式である.
-
Tabular 表形式オブジェクト Dataset データ集合オブジェクト TimeSeries[…] 時系列オブジェクト EventSeries[…] 事象系列オブジェクト {assoc1,assoc2,…} 連想のリスト matrix 行列 - 次は,異常値を管理するために使用可能な変換方法 tspec である.
-
"Clip" 極値を異常ではない範囲に制限する "Replace" 異常値を計算された値で置換する {"Replace",method} method を使って異常値を置換する "Trim" 異常要素を除去する "Flag" 異常値をMissing["Anomalous"]で置換する tfun 関数 tfun を使って異常値を変換する - 使用可能な"Replace"法はTransformMissingにおけるものに等しい.
-
" Mean" 平均値 "Median" 中央値 "Mode" 最頻値 {"Constant", val} 一定の値 val "RandomElement" ランダムに選択された値 {"RandomVariate",dist} dist からサンプルとして取られた値 "NearestElement" 欠落していない最近の要素を使う "NextElement" 欠落していない次の要素を使う "PreviousElement" 欠落していない前の要素を使う "Interpolation" 補間を使う {"Interpolation",InterpolationOrderdegree} 補間次数 degree を指定する - 異常値を除外することは分析に対する異常値の影響を最小にする.異常値の切取りや置換は異常値の影響を最小にしつつデータ集合の構造は保持する.フラッグを立てると将来的な分析のためにすべてのデータ点を保持しつつ検討項目として異常値に印を付けることができる.
- 以下は,異常値検出に使えるメソッド dspec である.
-
"IQR" 四分位範囲閾値 "ZScore" 平均からの標準偏差 "ModifiedZScore" 中央値とMADを使った強力なバージョン {spec,t} 異常検出に閾値 t を指定する {spec,{t1,t2}} 上下の閾値を指定する - さらに,次の指定もサポートされている.
-
Scaled[f] 最小要素および最大要素の割合 f Scaled[{f1,f2}] 最小要素と最大要素に別々の閾値 dfun カスタム関数 fun - カスタムの異常値検出器 dfun は,各要素に別々に適用されてブール値を返さなければならない.
- 希望の列を指定するとき,coliは以下の形式を取ることができる.
-
n n 番目の列 "name" 列"name" TypeSpecifier[…] 指定の型にマッチする列 All すべての列 Automatic spec に基づいて自動的に列を求める(デフォルト)
例題
すべて開く すべて閉じる例 (2)
TransformAnomalies[{-10, 1, 2, 3, 10}, "Trim"]SeedRandom[1];
data = RandomVariate[GammaDistribution[1, 10], 100];Histogram[{data, TransformAnomalies[data, Scaled[{0, .05}] -> "Clip"]}, ChartLayout -> "Row"]スコープ (16)
データ型 (5)
TransformAnomalies[{-2, 1, 2, 3, 10}, "Flag"]TabularColumn中の異常値を検出する:
tcol = TabularColumn[Association["Data" -> {{-2, 1, 2, 3, 10}, {}, None}, "ElementType" -> "Integer64"]];tcol//NormalTransformAnomalies[TabularColumn[Association["Data" -> {{-2, 1, 2, 3, 10}, {}, None}, "ElementType" -> "Integer64"]], "Flag"]Normal[%]TransformAnomalies[{{1, 2}, {2, 3}, {4, 12}}, "Flag"]Tabularオブジェクト中の異常値を検出する:
tab = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Species" -> Association["ElementType" -> "String"],
"SepalLength" -> Association["ElementType" -> TypeSpecifier["Quantity"]["Real64",
"Centimeters"]], "SepalWidth" -> Association["ElementType" -> TypeSpecifier["Quantity"][
"Real64", "Centimeters"]], "PetalLength" -> Association["ElementType" ->
TypeSpecifier["Quantity"]["Real64", "Centimeters"]],
"PetalWidth" -> Association["ElementType" -> TypeSpecifier["Quantity"]["Real64",
"Centimeters"]]], "KeyColumns" -> None, "Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 6, 12, 18, 24, 30, 36},
"setosasetosasetosasetosasetosasetosa"}, {}, None}, "ElementType" -> "String"]],
TabularColumn[Association["Data" -> {6, {{{4.7, 4.6, 5.1, 5.7, 5., 4.9}, {}, None}}, None},
"ElementType" -> TypeSpecifier["Quantity"]["Real64", "Centimeters"],
"CachedOriginalExpression" -> {Quantity[4.7, "Centimeters"], Quantity[4.6,
"Centimeters"], Quantity[5.1, "Centimeters"], Quantity[5.7, "Centimeters"],
Quantity[5., "Centimeters"], Quantity[4.9, "Centimeters"]}]],
TabularColumn[Association["Data" -> {6, {{{3.2, 3.1, 3.5, 4.4, 3.6, 3.}, {}, None}}, None},
"ElementType" -> TypeSpecifier["Quantity"]["Real64", "Centimeters"],
"CachedOriginalExpression" -> {Quantity[3.2, "Centimeters"], Quantity[3.1,
"Centimeters"], Quantity[3.5, "Centimeters"], Quantity[4.4, "Centimeters"],
Quantity[3.6, "Centimeters"], Quantity[3., "Centimeters"]}]],
TabularColumn[Association["Data" -> {6, {{{1.3, 1.5, 1.4, 1.5, 1.4, 1.4}, {}, None}},
None}, "ElementType" -> TypeSpecifier["Quantity"]["Real64", "Centimeters"],
"CachedOriginalExpression" -> {Quantity[1.3, "Centimeters"], Quantity[1.5,
"Centimeters"], Quantity[1.4, "Centimeters"], Quantity[1.5, "Centimeters"],
Quantity[1.4, "Centimeters"], Quantity[1.4, "Centimeters"]}]],
TabularColumn[Association["Data" -> {6, {{{0.2, 0.2, 0.2, 0.4, 0.2, 0.2}, {}, None}},
None}, "ElementType" -> TypeSpecifier["Quantity"]["Real64", "Centimeters"],
"CachedOriginalExpression" -> {Quantity[0.2, "Centimeters"], Quantity[0.2,
"Centimeters"], Quantity[0.2, "Centimeters"], Quantity[0.4, "Centimeters"],
Quantity[0.2, "Centimeters"], Quantity[0.2, "Centimeters"]}]]}}]]]];TransformAnomalies[tab, "Flag"]TransformAnomalies[{
<|"A" -> Quantity[0.2, "Centimeters"], "B" -> Quantity[1.3, "Centimeters"]|>, <|"A" -> Quantity[0.2, "Centimeters"], "B" -> Quantity[1.5, "Centimeters"]|>, <|"A" -> Quantity[0.2, "Centimeters"], "B" -> Quantity[1.4, "Centimeters"]|>, <|"A" -> Quantity[0.4, "Centimeters"], "B" -> Quantity[1.5, "Centimeters"]|>, <|"A" -> Quantity[0.2, "Centimeters"], "B" -> Quantity[1.4, "Centimeters"]|>, <|"A" -> Quantity[0.2, "Centimeters"], "B" -> Quantity[1.4, "Centimeters"]|>}, "Flag"]検出法 (6)
TransformAnomalies[{-2, 1, 2, 3, 10}, "IQR"]TransformAnomalies[{-2, 1, 2, 3, 10}, "ZScore"]TransformAnomalies[{-2, 1, 2, 3, 10}, "ModifiedZScore"]TransformAnomalies[{-2, 1, 2, 3, 10}, {"ZScore", 1}]TransformAnomalies[{-2, 1, 2, 3, 10}, {"ZScore", {2, 1}}]TransformAnomalies[{-2, 1, 2, 3, 10}, Scaled[.2]]TransformAnomalies[{-2, 1, 2, 3, 10}, Scaled[{.2, 0}]]TransformAnomalies[{-2, 1, 2, 3, 10}, Negative -> "Flag"]変換法 (5)
TransformAnomalies[{-2, 1, 2, 3, 10}, "Trim"]TransformAnomalies[{-2, 1, 2, 3, 10}, "Clip"]TransformAnomalies[{-2, 1, 2, 3, 10}, "Flag"]任意のTransformMissing指定を適用する:
TransformAnomalies[{-2, 1, 2, 3, 10}, {"Replace", "Mean"}]TransformAnomalies[{-2, 1, 2, 3, 10}, f]アプリケーション (2)
売上データのTabularオブジェクトを取得する:
data = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Date" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer32", "Day",
"Gregorian", 0]], "City" -> Association["ElementType" -> "String"],
"Sales" -> Association["ElementType" -> "Integer64"]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {52, {{NumericArray[{16071, 16071, 16071, 16071, 16071,
16071, 16072, 16072, 16072, 16072, 16072, 16072, 16073, 16073, 16073, 16073, 16073,
16073, 16074, 16074, 16074, 16074, 16074, 16074, 16075, 16075, 16075, 16075, 16075,
16075, 16076, 16076, 16076, 16076, 16076, 16076, 16077, 16077, 16077, 16077, 16077,
16077, 16078, 16078, 16078, 16078, 16078, 16078, 16079, 16079, 16079, 16079},
"Integer32"], {}, None}}, None}, "ElementType" -> "Date"["Integer32", "Day",
"Gregorian", 0]]], TabularColumn[Association["Data" ->
{{3, {0, 6, 14, 19, 25, 33, 38, 44, 52, 57, 63, 71, 76, 82, 90, 95, 101, 109, 114, 120,
128, 133, 139, 147, 152, 158, 166, 171, 177, 185, 190, 196, 204, 209, 215, 223, 228,
234, 242, 247, 253, 261, 266, 272, 280, 285, 291, 299, 304, 310, 318, 323, 329}, "Bos\
tonNew YorkParisLondonShanghaiTokioBostonNew YorkParisLondonShanghaiTokioBostonNew \
YorkParisLondonShanghaiTokioBostonNew YorkParisLondonShanghaiTokioBostonNew \
YorkParisLondonShanghaiTokioBostonNew YorkParisLondonShanghaiTokioBostonNew \
YorkParisLondonShanghaiTokioBostonNew YorkParisLondonShanghaiTokioBostonNew YorkParisLondon"}, {},
None}, "ElementType" -> "String"]], TabularColumn[
Association["Data" -> {{198, 0, 215, 225, 241, 218, 189, 0, 211, 228, 242, 229, 196, 235,
221, 229, 238, 236, 194, 237, 213, 226, 231, 228, 193, 0, 219, 247, 242, 225, 184,
228, 214, 225, 244, 219, 190, 227, 218, 232, 235, 224, 196, 0, 214, 236, 229, 233,
189, 227, 211, 226}, {}, None}, "ElementType" -> "Integer64"]]}}]]]];"Sales"列には外れ値の0があるが,これは欠落値の代りである:
Histogram[data -> "Sales"]もとのデータから関連する行を削除することで0という異常値を変換する:
data1 = TransformAnomalies[data, "Trim"]Missingオブジェクトに変えることで0という異常値を変換する:
data2 = TransformAnomalies[data, "Flag"]Histogram[# -> "Sales"]& /@ {data1, data2}気象観測のTabularオブジェクトを取得する:
data = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Time" -> Association["ElementType" -> TypeSpecifier["Date"]["Integer64",
"Instant", "Gregorian", -6.]], "Temperature" ->
Association["ElementType" -> TypeSpecifier["Quantity"]["NumberExpression",
"DegreesCelsius"]], "Pressure" -> Association["ElementType" ->
TypeSpecifier["Quantity"]["NumberExpression", "Millibars"]]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {23, {{{1701427980000, 1701429480000, 1701431580000,
1701431940000, 1701433080000, 1701435180000, 1701436260000, 1701438780000,
1701442380000, 1701518340000, 1701520680000, 1701521580000, 1701524100000,
1701525180000, 1701604740000, 1701605340000, 1701607980000, 1701611100000,
1701611580000, 1701611700000, 1701612120000, 1701613020000, 1701615180000}, {},
None}}, None}, "ElementType" -> "Date"["Integer64", "Instant", "Gregorian", -6.],
"CachedOriginalExpression" -> {DateObject[{2023, 12, 1, 4, 53, 0}, "Instant",
"Gregorian", -6.], DateObject[{2023, 12, 1, 5, 18, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 5, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 5, 59, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 6, 18, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 6, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 7, 11, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 7, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 1, 8, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 2, 5, 59, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 2, 6, 38, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 2, 6, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 2, 7, 35, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 2, 7, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 5, 59, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 6, 9, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 6, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 7, 45, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 7, 53, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 7, 55, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 8, 2, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 8, 17, 0}, "Instant", "Gregorian", -6.],
DateObject[{2023, 12, 3, 8, 53, 0}, "Instant", "Gregorian", -6.]}]],
TabularColumn[Association["Data" -> {23, {{{8.9, 8.3, 7.8, 45.68, 7.2, 7.2, 7.2, 7.2, 6.7,
43.52, 6.1, 6.1, 5.6, 5.6, 41.54, 5, 5, 5, 5, 5, 5, 5, 5}, {}, None}}, None},
"ElementType" -> TypeSpecifier["Quantity"]["NumberExpression", "DegreesCelsius"],
"CachedOriginalExpression" -> {Quantity[8.9, "DegreesCelsius"],
Quantity[8.3, "DegreesCelsius"], Quantity[7.8, "DegreesCelsius"],
Quantity[45.68, "DegreesCelsius"], Quantity[7.2, "DegreesCelsius"],
Quantity[7.2, "DegreesCelsius"], Quantity[7.2, "DegreesCelsius"],
Quantity[7.2, "DegreesCelsius"], Quantity[6.7, "DegreesCelsius"],
Quantity[43.52, "DegreesCelsius"], Quantity[6.1, "DegreesCelsius"],
Quantity[6.1, "DegreesCelsius"], Quantity[5.6, "DegreesCelsius"],
Quantity[5.6, "DegreesCelsius"], Quantity[41.54, "DegreesCelsius"],
Quantity[5, "DegreesCelsius"], Quantity[5, "DegreesCelsius"],
Quantity[5, "DegreesCelsius"], Quantity[5, "DegreesCelsius"],
Quantity[5, "DegreesCelsius"], Quantity[5, "DegreesCelsius"],
Quantity[5, "DegreesCelsius"], Quantity[5, "DegreesCelsius"]}]],
TabularColumn[Association["Data" -> {23, {{{1011.9, 1012.1, 1012.3, 99, 1012.2, 1012.1,
1012.2, 1012.2, 1011.3, 99, 1011.7, 1012., 99, 1013.4, 99, 1011.5, 1009.9, 1009.4,
1009.1, 1008.8, 1008.7, 1008.4, 1008.3}, {}, None}}, None},
"ElementType" -> TypeSpecifier["Quantity"]["NumberExpression", "Millibars"],
"CachedOriginalExpression" -> {Quantity[1011.9, "Millibars"], Quantity[1012.1,
"Millibars"], Quantity[1012.3, "Millibars"], Quantity[99, "Millibars"],
Quantity[1012.2, "Millibars"], Quantity[1012.1, "Millibars"], Quantity[1012.2,
"Millibars"], Quantity[1012.2, "Millibars"], Quantity[1011.3, "Millibars"],
Quantity[99, "Millibars"], Quantity[1011.7, "Millibars"], Quantity[1012., "Millibars"],
Quantity[99, "Millibars"], Quantity[1013.4, "Millibars"], Quantity[99, "Millibars"],
Quantity[1011.5, "Millibars"], Quantity[1009.9, "Millibars"], Quantity[1009.4,
"Millibars"], Quantity[1009.1, "Millibars"], Quantity[1008.8, "Millibars"],
Quantity[1008.7, "Millibars"], Quantity[1008.4, "Millibars"], Quantity[1008.3,
"Millibars"]}]]}}]]]];DateListPlot[data -> {"Time", "Temperature"}, PlotRange -> All]気温データには,多分不正な単位でデータを入力したことによる,外れ値が含まれているようである.同様に,"Pressure"列にも外れ値が含まれている.これは,しばしば欠落値に使われる99という数である.気温単位の変換関数を指定する:
tempF = (UnitConvert[Quantity[QuantityMagnitude[#], "DegreesFahrenheit"], "DegreesCelsius"]&);上記関数を使って"Temperature"列の外れ値を変換し,"Pressure"列の外れ値は直近の有効な値で置換する:
new = TransformAnomalies[data, {"Temperature" -> tempF, "Pressure" -> {"Replace", "NearestElement"}}]GraphicsRow[DateListPlot[new -> {"Time", #}, FrameLabel -> Automatic, PlotLabel -> #]& /@ {"Temperature", "Pressure"}, ImageSize -> Medium]テキスト
Wolfram Research (2025), TransformAnomalies, Wolfram言語関数, https://reference.wolfram.com/language/ref/TransformAnomalies.html.
CMS
Wolfram Language. 2025. "TransformAnomalies." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TransformAnomalies.html.
APA
Wolfram Language. (2025). TransformAnomalies. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TransformAnomalies.html
BibTeX
@misc{reference.wolfram_2026_transformanomalies, author="Wolfram Research", title="{TransformAnomalies}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TransformAnomalies.html}", note=[Accessed: 08-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_transformanomalies, organization={Wolfram Research}, title={TransformAnomalies}, year={2025}, url={https://reference.wolfram.com/language/ref/TransformAnomalies.html}, note=[Accessed: 08-November-2026]}